r18535 - gnucash/trunk/src - Re-indentation of source code, next batch.

Christian Stimming cstim at code.gnucash.org
Tue Dec 29 15:12:51 EST 2009


Author: cstim
Date: 2009-12-29 15:12:48 -0500 (Tue, 29 Dec 2009)
New Revision: 18535
Trac: http://svn.gnucash.org/trac/changeset/18535

Modified:
   gnucash/trunk/src/app-utils/file-utils.c
   gnucash/trunk/src/app-utils/file-utils.h
   gnucash/trunk/src/app-utils/gfec.c
   gnucash/trunk/src/app-utils/gnc-account-merge.c
   gnucash/trunk/src/app-utils/gnc-account-merge.h
   gnucash/trunk/src/app-utils/gnc-accounting-period.c
   gnucash/trunk/src/app-utils/gnc-accounting-period.h
   gnucash/trunk/src/app-utils/gnc-component-manager.c
   gnucash/trunk/src/app-utils/gnc-component-manager.h
   gnucash/trunk/src/app-utils/gnc-druid-cb.c
   gnucash/trunk/src/app-utils/gnc-druid-cb.h
   gnucash/trunk/src/app-utils/gnc-druid-provider-desc-edge.c
   gnucash/trunk/src/app-utils/gnc-druid-provider-desc-edge.h
   gnucash/trunk/src/app-utils/gnc-druid-provider-desc-file.c
   gnucash/trunk/src/app-utils/gnc-druid-provider-desc-file.h
   gnucash/trunk/src/app-utils/gnc-druid-provider-desc-multifile.c
   gnucash/trunk/src/app-utils/gnc-druid-provider-desc-multifile.h
   gnucash/trunk/src/app-utils/gnc-druid-provider-desc.c
   gnucash/trunk/src/app-utils/gnc-druid-provider-desc.h
   gnucash/trunk/src/app-utils/gnc-druid-provider-file-cb.c
   gnucash/trunk/src/app-utils/gnc-druid-provider-file-cb.h
   gnucash/trunk/src/app-utils/gnc-druid-provider.c
   gnucash/trunk/src/app-utils/gnc-druid-provider.h
   gnucash/trunk/src/app-utils/gnc-druid.c
   gnucash/trunk/src/app-utils/gnc-druid.h
   gnucash/trunk/src/app-utils/gnc-euro.c
   gnucash/trunk/src/app-utils/gnc-exp-parser.c
   gnucash/trunk/src/app-utils/gnc-exp-parser.h
   gnucash/trunk/src/app-utils/gnc-gettext-util.c
   gnucash/trunk/src/app-utils/gnc-gettext-util.h
   gnucash/trunk/src/app-utils/gnc-help-utils.c
   gnucash/trunk/src/app-utils/gnc-help-utils.h
   gnucash/trunk/src/app-utils/gnc-helpers.c
   gnucash/trunk/src/app-utils/gnc-sx-instance-model.c
   gnucash/trunk/src/app-utils/gnc-sx-instance-model.h
   gnucash/trunk/src/app-utils/gnc-ui-common.h
   gnucash/trunk/src/app-utils/gnc-ui-util.c
   gnucash/trunk/src/app-utils/gnc-ui-util.h
   gnucash/trunk/src/app-utils/gncmod-app-utils.c
   gnucash/trunk/src/app-utils/guile-util.c
   gnucash/trunk/src/app-utils/guile-util.h
   gnucash/trunk/src/app-utils/option-util.c
   gnucash/trunk/src/app-utils/option-util.h
   gnucash/trunk/src/app-utils/test/test-exp-parser.c
   gnucash/trunk/src/app-utils/test/test-link-module.c
   gnucash/trunk/src/app-utils/test/test-print-parse-amount.c
   gnucash/trunk/src/app-utils/test/test-print-queries.c
   gnucash/trunk/src/app-utils/test/test-scm-query-string.c
   gnucash/trunk/src/app-utils/test/test-sx.c
   gnucash/trunk/src/backend/postgres/PostgresBackend.c
   gnucash/trunk/src/backend/postgres/PostgresBackend.h
   gnucash/trunk/src/backend/postgres/account.c
   gnucash/trunk/src/backend/postgres/account.h
   gnucash/trunk/src/backend/postgres/book.c
   gnucash/trunk/src/backend/postgres/builder.c
   gnucash/trunk/src/backend/postgres/builder.h
   gnucash/trunk/src/backend/postgres/checkpoint.c
   gnucash/trunk/src/backend/postgres/checkpoint.h
   gnucash/trunk/src/backend/postgres/demo.c
   gnucash/trunk/src/backend/postgres/escape.c
   gnucash/trunk/src/backend/postgres/events.c
   gnucash/trunk/src/backend/postgres/events.h
   gnucash/trunk/src/backend/postgres/gncquery.c
   gnucash/trunk/src/backend/postgres/gncquery.h
   gnucash/trunk/src/backend/postgres/kvp-sql.c
   gnucash/trunk/src/backend/postgres/kvp-sql.h
   gnucash/trunk/src/backend/postgres/newtables.h
   gnucash/trunk/src/backend/postgres/price.c
   gnucash/trunk/src/backend/postgres/putil.c
   gnucash/trunk/src/backend/postgres/putil.h
   gnucash/trunk/src/backend/postgres/test/test-db.c
   gnucash/trunk/src/backend/postgres/test/test-escape.c
   gnucash/trunk/src/backend/postgres/test/test-load-backend.c
   gnucash/trunk/src/backend/postgres/test/test-period.c
   gnucash/trunk/src/backend/postgres/txn.c
   gnucash/trunk/src/backend/postgres/txn.h
   gnucash/trunk/src/backend/postgres/txnmass.c
   gnucash/trunk/src/backend/postgres/upgrade.c
   gnucash/trunk/src/backend/postgres/upgrade.h
   gnucash/trunk/src/backend/xml/gnc-account-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-backend-xml.c
   gnucash/trunk/src/backend/xml/gnc-backend-xml.h
   gnucash/trunk/src/backend/xml/gnc-book-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-budget-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-commodity-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-freqspec-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-lot-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-pricedb-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-recurrence-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-transaction-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-xml.h
   gnucash/trunk/src/backend/xml/gncmod-backend-xml.c
   gnucash/trunk/src/backend/xml/io-example-account.c
   gnucash/trunk/src/backend/xml/io-gncxml-gen.c
   gnucash/trunk/src/backend/xml/io-gncxml-v1.c
   gnucash/trunk/src/backend/xml/io-gncxml-v2.c
   gnucash/trunk/src/backend/xml/io-gncxml-v2.h
   gnucash/trunk/src/backend/xml/io-gncxml.h
   gnucash/trunk/src/backend/xml/io-utils.c
   gnucash/trunk/src/backend/xml/io-utils.h
   gnucash/trunk/src/backend/xml/sixtp-dom-generators.c
   gnucash/trunk/src/backend/xml/sixtp-dom-parsers.c
   gnucash/trunk/src/backend/xml/sixtp-parsers.h
   gnucash/trunk/src/backend/xml/sixtp-stack.c
   gnucash/trunk/src/backend/xml/sixtp-stack.h
   gnucash/trunk/src/backend/xml/sixtp-to-dom-parser.c
   gnucash/trunk/src/backend/xml/sixtp-utils.c
   gnucash/trunk/src/backend/xml/sixtp-utils.h
   gnucash/trunk/src/backend/xml/sixtp.c
   gnucash/trunk/src/backend/xml/sixtp.h
   gnucash/trunk/src/backend/xml/test/test-date-converting.c
   gnucash/trunk/src/backend/xml/test/test-dom-converters1.c
   gnucash/trunk/src/backend/xml/test/test-dom-parser1.c
   gnucash/trunk/src/backend/xml/test/test-file-stuff.c
   gnucash/trunk/src/backend/xml/test/test-kvp-frames.c
   gnucash/trunk/src/backend/xml/test/test-load-backend.c
   gnucash/trunk/src/backend/xml/test/test-load-example-account.c
   gnucash/trunk/src/backend/xml/test/test-load-xml2.c
   gnucash/trunk/src/backend/xml/test/test-save-in-lang.c
   gnucash/trunk/src/backend/xml/test/test-string-converters.c
   gnucash/trunk/src/backend/xml/test/test-xml-account.c
   gnucash/trunk/src/backend/xml/test/test-xml-commodity.c
   gnucash/trunk/src/backend/xml/test/test-xml-pricedb.c
   gnucash/trunk/src/backend/xml/test/test-xml-transaction.c
   gnucash/trunk/src/calculation/amort_opt.c
   gnucash/trunk/src/calculation/amort_prt.c
   gnucash/trunk/src/calculation/expression_parser.c
   gnucash/trunk/src/calculation/fin-interactive.c
   gnucash/trunk/src/calculation/fin-main.c
   gnucash/trunk/src/calculation/fin.c
   gnucash/trunk/src/calculation/fin_spl_protos.h
   gnucash/trunk/src/calculation/fin_static_proto.h
   gnucash/trunk/src/calculation/finproto.h
   gnucash/trunk/src/calculation/finvar.h
   gnucash/trunk/src/calculation/gncmod-calculation.c
   gnucash/trunk/src/calculation/numeric_ops.c
   gnucash/trunk/src/calculation/test/test-link.c
   gnucash/trunk/src/core-utils/gnc-gconf-utils.c
   gnucash/trunk/src/core-utils/gnc-gconf-utils.h
   gnucash/trunk/src/core-utils/gnc-gdate-utils.c
   gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c
   gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h
   gnucash/trunk/src/core-utils/gnc-glib-utils.c
   gnucash/trunk/src/core-utils/gnc-glib-utils.h
   gnucash/trunk/src/core-utils/gnc-gobject-utils.c
   gnucash/trunk/src/core-utils/gnc-gobject-utils.h
   gnucash/trunk/src/core-utils/gnc-gtk-utils.c
   gnucash/trunk/src/core-utils/gnc-gtk-utils.h
   gnucash/trunk/src/core-utils/gnc-main.c
   gnucash/trunk/src/doc/doxygen_main_page.c
   gnucash/trunk/src/gnc-module/gnc-module.c
   gnucash/trunk/src/gnc-module/gnc-module.h
   gnucash/trunk/src/gnc-module/test/misc-mods/agedver.c
   gnucash/trunk/src/gnc-module/test/misc-mods/futuremodsys.c
   gnucash/trunk/src/gnc-module/test/misc-mods/incompatdep.c
   gnucash/trunk/src/gnc-module/test/mod-bar/bar.c
   gnucash/trunk/src/gnc-module/test/mod-bar/gnc-mod-bar.c
   gnucash/trunk/src/gnc-module/test/mod-baz/baz.c
   gnucash/trunk/src/gnc-module/test/mod-baz/gnc-mod-baz.c
   gnucash/trunk/src/gnc-module/test/mod-foo/foo.c
   gnucash/trunk/src/gnc-module/test/mod-foo/gnc-mod-foo.c
   gnucash/trunk/src/gnc-module/test/test-agedver.c
   gnucash/trunk/src/gnc-module/test/test-dynload.c
   gnucash/trunk/src/gnc-module/test/test-incompatdep.c
   gnucash/trunk/src/gnc-module/test/test-load-c.c
   gnucash/trunk/src/gnc-module/test/test-modsysver.c
   gnucash/trunk/src/libqof/backend/file/qof-backend-qsf.h
   gnucash/trunk/src/libqof/backend/file/qsf-backend.c
   gnucash/trunk/src/libqof/backend/file/qsf-xml-map.c
   gnucash/trunk/src/libqof/backend/file/qsf-xml.c
   gnucash/trunk/src/libqof/backend/file/qsf-xml.h
   gnucash/trunk/src/libqof/qof/gnc-date.c
   gnucash/trunk/src/libqof/qof/qofbackend.c
   gnucash/trunk/src/libqof/qof/qofbook.c
   gnucash/trunk/src/libqof/qof/qofbookslots.h
   gnucash/trunk/src/libqof/qof/qofutil.c
   gnucash/trunk/src/tax/us/gncmod-tax-us.c
   gnucash/trunk/src/tax/us/test/test-link-module.c
   gnucash/trunk/src/test-core/gncmod-test.c
   gnucash/trunk/src/test-core/test-stuff.c
   gnucash/trunk/src/test-core/test-stuff.h
Log:
Re-indentation of source code, next batch.

This also strips trailing whitespaces from lines where they existed.
This re-indentation was done using astyle-1.23 using the following options:

astyle --indent=spaces=4 --brackets=break --pad-oper

Discussed at http://lists.gnucash.org/pipermail/gnucash-devel/2009-August/026121.html

Modified: gnucash/trunk/src/app-utils/file-utils.c
===================================================================
--- gnucash/trunk/src/app-utils/file-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/file-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -38,7 +38,7 @@
 #include "gnc-engine.h"
 #include "gnc-filepath-utils.h"
 #include "gnc-gkeyfile-utils.h"
- 
+
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_GUILE;
 
@@ -46,24 +46,24 @@
 \********************************************************************/
 
 char *
-gncFindFile (const char * filename) 
+gncFindFile (const char * filename)
 {
-  const gchar *full_filename = NULL;
-  SCM find_doc_file;
-  SCM scm_filename;
-  SCM scm_result;
+    const gchar *full_filename = NULL;
+    SCM find_doc_file;
+    SCM scm_filename;
+    SCM scm_result;
 
-  if (!filename || *filename == '\0')
-    return NULL;
+    if (!filename || *filename == '\0')
+        return NULL;
 
-  find_doc_file = scm_c_eval_string("gnc:find-doc-file");
-  scm_filename = scm_makfrom0str ((char *) filename);
-  scm_result = scm_call_1(find_doc_file, scm_filename);
+    find_doc_file = scm_c_eval_string("gnc:find-doc-file");
+    scm_filename = scm_makfrom0str ((char *) filename);
+    scm_result = scm_call_1(find_doc_file, scm_filename);
 
-  if (SCM_STRINGP(scm_result))
-    full_filename = SCM_STRING_CHARS(scm_result);
+    if (SCM_STRINGP(scm_result))
+        full_filename = SCM_STRING_CHARS(scm_result);
 
-  return g_strdup (full_filename);
+    return g_strdup (full_filename);
 }
 
 /********************************************************************\
@@ -74,59 +74,60 @@
  * Return: size of data read                                        *
  * Global: helpPath - the path to the help files                    *
 \********************************************************************/
-int 
+int
 gncReadFile (const char * file, char ** data)
 {
-  char *buf=NULL;
-  char  *filename;
-  int   size=0;
-  int   fd;
+    char *buf = NULL;
+    char  *filename;
+    int   size = 0;
+    int   fd;
 
-  /* construct absolute path -- twiddle the relative path we received */
-  if (!file || file[0] == '\0') return 0;
+    /* construct absolute path -- twiddle the relative path we received */
+    if (!file || file[0] == '\0') return 0;
 
-  /* take absolute paths without searching */
-  if (!g_path_is_absolute (file))
-    filename = gncFindFile (file);
-  else
-    filename = g_strdup (file);
+    /* take absolute paths without searching */
+    if (!g_path_is_absolute (file))
+        filename = gncFindFile (file);
+    else
+        filename = g_strdup (file);
 
-  if (!filename) return 0;
+    if (!filename) return 0;
 
-  /* Open file: */
-  fd = g_open( filename, O_RDONLY, 0 );
+    /* Open file: */
+    fd = g_open( filename, O_RDONLY, 0 );
 
-  g_free(filename); filename = NULL;
+    g_free(filename);
+    filename = NULL;
 
-  if( fd == -1 )
-  {
-    int norr = errno;
-    PERR ("file %s: (%d) %s \n", file, norr, strerror(norr));
-    return 0;
-  }
+    if ( fd == -1 )
+    {
+        int norr = errno;
+        PERR ("file %s: (%d) %s \n", file, norr, strerror(norr));
+        return 0;
+    }
 
-  /* Find size: */
-  size = lseek( fd, 0, SEEK_END );
-  lseek( fd, 0, SEEK_SET );
+    /* Find size: */
+    size = lseek( fd, 0, SEEK_END );
+    lseek( fd, 0, SEEK_SET );
 
-  /* Allocate memory */
-  buf = g_new(char, size + 1);
+    /* Allocate memory */
+    buf = g_new(char, size + 1);
 
-  /* read in file */
-  if( read(fd,buf,size) == -1 )
-  {
-    g_free(buf);
-    buf=NULL;
-  }
-  else
-  {
-    buf[size] = '\0';
-  }
+    /* read in file */
+    if ( read(fd, buf, size) == -1 )
+    {
+        g_free(buf);
+        buf = NULL;
+    }
+    else
+    {
+        buf[size] = '\0';
+    }
 
-  close(fd);
-  *data = buf;
+    close(fd);
+    *data = buf;
 
-  return size;
+    return size;
 }
 
 /**
@@ -145,28 +146,29 @@
 gint64
 gnc_getline (gchar **line, FILE *file)
 {
-  char str[BUFSIZ];
-  gint64 len;
-  GString *gs;
+    char str[BUFSIZ];
+    gint64 len;
+    GString *gs;
 
-  g_return_val_if_fail(line, -1);
-  *line = NULL;
-  g_return_val_if_fail(file, -1);
+    g_return_val_if_fail(line, -1);
+    *line = NULL;
+    g_return_val_if_fail(file, -1);
 
-  gs = g_string_new("");
+    gs = g_string_new("");
 
-  while (fgets(str, sizeof(str), file) != NULL) {
-    g_string_append(gs, str);
+    while (fgets(str, sizeof(str), file) != NULL)
+    {
+        g_string_append(gs, str);
 
-    len = strlen(str);
-    if (str[len-1] == '\n')
-      break;
-  }
+        len = strlen(str);
+        if (str[len-1] == '\n')
+            break;
+    }
 
-  len = gs->len;
-  *line = gs->str;
-  g_string_free(gs, FALSE);
-  return len;
+    len = gs->len;
+    *line = gs->str;
+    g_string_free(gs, FALSE);
+    return len;
 }
 
 
@@ -182,48 +184,54 @@
 static gboolean
 gnc_update_state_file_keys(const gchar *filename)
 {
-  gchar *contents, **lines, *line, **kv, **parts, *part, *newkey;
-  GError *error = NULL;
-  int i, j;
+    gchar *contents, **lines, *line, **kv, **parts, *part, *newkey;
+    GError *error = NULL;
+    int i, j;
 
-  if (!g_file_get_contents(filename, &contents, NULL, &error)) {
-    DEBUG("Error reading state file: %s", error->message);
-    g_error_free(error);
-    return FALSE;
-  }
+    if (!g_file_get_contents(filename, &contents, NULL, &error))
+    {
+        DEBUG("Error reading state file: %s", error->message);
+        g_error_free(error);
+        return FALSE;
+    }
 
-  lines = g_strsplit_set(contents, "\r\n", -1);
-  g_free(contents);
+    lines = g_strsplit_set(contents, "\r\n", -1);
+    g_free(contents);
 
-  /* Strip spaces from non-comment lines, and rewrite the new text
-   * over top of the old text.  The new line is guaranteed to be at
-   * most the same number of characters as the old. */
-  for (i = 0, line = lines[i++]; line; line = lines[i++]) {
-    if ((*line == '\0') || (*line == '#') || (*line == '[')) {
-      continue;
-    } else {
-      kv = g_strsplit(line, "=", 2);
-      parts = g_strsplit(kv[0], " ", -1);
-      for (j = 0, part = parts[j++]; part; part = parts[j++])
-	part[0] = g_ascii_toupper(part[0]);
-      newkey = g_strjoinv("", parts);
-      g_sprintf(line, "%s=%s", newkey, kv[1] ? kv[1] : "");
-      g_free(newkey);
-      g_strfreev(parts);
-      g_strfreev(kv);
+    /* Strip spaces from non-comment lines, and rewrite the new text
+     * over top of the old text.  The new line is guaranteed to be at
+     * most the same number of characters as the old. */
+    for (i = 0, line = lines[i++]; line; line = lines[i++])
+    {
+        if ((*line == '\0') || (*line == '#') || (*line == '['))
+        {
+            continue;
+        }
+        else
+        {
+            kv = g_strsplit(line, "=", 2);
+            parts = g_strsplit(kv[0], " ", -1);
+            for (j = 0, part = parts[j++]; part; part = parts[j++])
+                part[0] = g_ascii_toupper(part[0]);
+            newkey = g_strjoinv("", parts);
+            g_sprintf(line, "%s=%s", newkey, kv[1] ? kv[1] : "");
+            g_free(newkey);
+            g_strfreev(parts);
+            g_strfreev(kv);
+        }
     }
-  }
 
-  contents = g_strjoinv("\n", lines);
-  if (!g_file_set_contents(filename, contents, -1, &error)) {
-    DEBUG("Error writing state file: %s", error->message);
-    g_error_free(error);
+    contents = g_strjoinv("\n", lines);
+    if (!g_file_set_contents(filename, contents, -1, &error))
+    {
+        DEBUG("Error writing state file: %s", error->message);
+        g_error_free(error);
+        g_free(contents);
+        return FALSE;
+    }
+
     g_free(contents);
-    return FALSE;
-  }
-
-  g_free(contents);
-  return TRUE;
+    return TRUE;
 }
 
 /*  Find the state file that corresponds to this URL and guid.  The
@@ -232,98 +240,107 @@
  *  user has multiple data files with the same name. */
 GKeyFile *
 gnc_find_state_file (const gchar *url,
-		     const gchar *guid,
-		     gchar **filename_p)
+                     const gchar *guid,
+                     gchar **filename_p)
 {
-  gchar *basename, *original = NULL, *filename, *tmp, *file_guid;
-  GKeyFile *key_file = NULL;
-  GError *error = NULL;
-  gboolean do_increment;
-  gint i;
+    gchar *basename, *original = NULL, *filename, *tmp, *file_guid;
+    GKeyFile *key_file = NULL;
+    GError *error = NULL;
+    gboolean do_increment;
+    gint i;
 
-  ENTER("url %s, guid %s", url, guid);
-  tmp = strchr(url, ':');
-  if (tmp)
-    url = tmp + 1;
+    ENTER("url %s, guid %s", url, guid);
+    tmp = strchr(url, ':');
+    if (tmp)
+        url = tmp + 1;
 
-  basename = g_path_get_basename(url);
-  DEBUG("Basename %s", basename);
-  original = gnc_build_book_path(basename);
-  g_free(basename);
-  DEBUG("Original %s", original);
+    basename = g_path_get_basename(url);
+    DEBUG("Basename %s", basename);
+    original = gnc_build_book_path(basename);
+    g_free(basename);
+    DEBUG("Original %s", original);
 
-  i = 1;
-  while (1) {
-    if (i == 1)
-      filename = g_strdup(original);
-    else
-      filename = g_strdup_printf("%s_%d", original, i);
-    DEBUG("Trying %s", filename);
-    key_file = gnc_key_file_load_from_file(filename, FALSE, FALSE, &error);
-    DEBUG("Result %p", key_file);
+    i = 1;
+    while (1)
+    {
+        if (i == 1)
+            filename = g_strdup(original);
+        else
+            filename = g_strdup_printf("%s_%d", original, i);
+        DEBUG("Trying %s", filename);
+        key_file = gnc_key_file_load_from_file(filename, FALSE, FALSE, &error);
+        DEBUG("Result %p", key_file);
 
-    if (error &&
-	(error->domain == G_KEY_FILE_ERROR) && 
-	(error->code == G_KEY_FILE_ERROR_PARSE)) {
-      /* Handle the case where glib was updated first, and is refusing
-       * to read old state files. */
-      if (gnc_update_state_file_keys(filename)) {
-	DEBUG("Trying %s again", filename);
-	key_file = gnc_key_file_load_from_file(filename, FALSE, FALSE, NULL);
-	DEBUG("Result %p", key_file);
-      }
-    }
-    if (error) {
-      g_error_free(error);
-      error = NULL;
-    }
-    if (!key_file) {
-      DEBUG("No key file by that name");
-      break;
-    }
+        if (error &&
+                (error->domain == G_KEY_FILE_ERROR) &&
+                (error->code == G_KEY_FILE_ERROR_PARSE))
+        {
+            /* Handle the case where glib was updated first, and is refusing
+             * to read old state files. */
+            if (gnc_update_state_file_keys(filename))
+            {
+                DEBUG("Trying %s again", filename);
+                key_file = gnc_key_file_load_from_file(filename, FALSE, FALSE, NULL);
+                DEBUG("Result %p", key_file);
+            }
+        }
+        if (error)
+        {
+            g_error_free(error);
+            error = NULL;
+        }
+        if (!key_file)
+        {
+            DEBUG("No key file by that name");
+            break;
+        }
 
-    file_guid = g_key_file_get_string(key_file,
-				      STATE_FILE_TOP, STATE_FILE_BOOK_GUID,
-				      NULL);
-    DEBUG("File GUID is %s", file_guid ? file_guid : "<not found>");
-    if (safe_strcmp(guid, file_guid) == 0) {
-      DEBUG("Matched !!!");
-      g_free(file_guid);
-      break;
-    }
-	g_free(file_guid);
+        file_guid = g_key_file_get_string(key_file,
+                                          STATE_FILE_TOP, STATE_FILE_BOOK_GUID,
+                                          NULL);
+        DEBUG("File GUID is %s", file_guid ? file_guid : "<not found>");
+        if (safe_strcmp(guid, file_guid) == 0)
+        {
+            DEBUG("Matched !!!");
+            g_free(file_guid);
+            break;
+        }
+        g_free(file_guid);
 
-    /* Handle the case where gnucash was updated first, and is trying
-     * to find new key names in an old state files. */
-    file_guid = g_key_file_get_string(key_file,
-				      STATE_FILE_TOP, STATE_FILE_BOOK_GUID_OLD,
-				      NULL);
-    DEBUG("%s is %s", STATE_FILE_BOOK_GUID,
-	  file_guid ? file_guid : "<not found>");
-    if (safe_strcmp(guid, file_guid) == 0) {
-      DEBUG("Matched !!!");
-      do_increment = !gnc_update_state_file_keys(filename);
-    } else {
-      do_increment = TRUE;
+        /* Handle the case where gnucash was updated first, and is trying
+         * to find new key names in an old state files. */
+        file_guid = g_key_file_get_string(key_file,
+                                          STATE_FILE_TOP, STATE_FILE_BOOK_GUID_OLD,
+                                          NULL);
+        DEBUG("%s is %s", STATE_FILE_BOOK_GUID,
+              file_guid ? file_guid : "<not found>");
+        if (safe_strcmp(guid, file_guid) == 0)
+        {
+            DEBUG("Matched !!!");
+            do_increment = !gnc_update_state_file_keys(filename);
+        }
+        else
+        {
+            do_increment = TRUE;
+        }
+
+        DEBUG("Clean up this pass");
+        g_free(file_guid);
+        g_key_file_free(key_file);
+        g_free(filename);
+        if (do_increment)
+            i++;
     }
 
-    DEBUG("Clean up this pass");
-    g_free(file_guid);
-    g_key_file_free(key_file);
-    g_free(filename);
-    if (do_increment)
-      i++;
-  }
-
-  DEBUG("Clean up");
-  g_free(original);
-  if (filename_p)
-    *filename_p = filename;
-  else
-    g_free(filename);
-  LEAVE("key_file %p, filename %s", key_file,
-	filename_p ? *filename_p : "(none)");
-  return key_file;
+    DEBUG("Clean up");
+    g_free(original);
+    if (filename_p)
+        *filename_p = filename;
+    else
+        g_free(filename);
+    LEAVE("key_file %p, filename %s", key_file,
+          filename_p ? *filename_p : "(none)");
+    return key_file;
 }
 
 /* ----------------------- END OF FILE ---------------------  */

Modified: gnucash/trunk/src/app-utils/file-utils.h
===================================================================
--- gnucash/trunk/src/app-utils/file-utils.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/file-utils.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -34,12 +34,12 @@
 char * gncFindFile (const char * filename);
 
 /********************************************************************\
- * gncReadFile                                                      * 
- *                                                                  * 
+ * gncReadFile                                                      *
+ *                                                                  *
  * Args:   file - the name of the html file to read                 *
- *         data - pointer to data pointer                           * 
- * Return: file size                                                * 
- * Global: xxxPath - the path to search                             * 
+ *         data - pointer to data pointer                           *
+ * Return: file size                                                *
+ * Global: xxxPath - the path to search                             *
 \********************************************************************/
 int gncReadFile (const char * file, char ** data);
 

Modified: gnucash/trunk/src/app-utils/gfec.c
===================================================================
--- gnucash/trunk/src/app-utils/gfec.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gfec.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -23,26 +23,26 @@
 static SCM
 gfec_catcher(void *data, SCM tag, SCM throw_args)
 {
-  SCM func;
-  SCM result;
-  char *msg = NULL;
+    SCM func;
+    SCM result;
+    char *msg = NULL;
 
-  func = scm_c_eval_string("gnc:error->string");
-  if (SCM_PROCEDUREP(func))
-  {
-    result = scm_call_2(func, tag, throw_args);
-    if (SCM_STRINGP(result))
-      msg = SCM_STRING_CHARS(result);
-  }
+    func = scm_c_eval_string("gnc:error->string");
+    if (SCM_PROCEDUREP(func))
+    {
+        result = scm_call_2(func, tag, throw_args);
+        if (SCM_STRINGP(result))
+            msg = SCM_STRING_CHARS(result);
+    }
 
-  if (msg == NULL)
-  {
-    msg = "Error running guile function.";
-  }
+    if (msg == NULL)
+    {
+        msg = "Error running guile function.";
+    }
 
-  *(char**)data = strdup(msg);
+    *(char**)data = strdup(msg);
 
-  return SCM_UNDEFINED;
+    return SCM_UNDEFINED;
 }
 
 
@@ -58,110 +58,110 @@
 static SCM
 gfec_file_helper(void *data)
 {
-  char *file = data;
+    char *file = data;
 
-  return scm_c_primitive_load(file);
+    return scm_c_primitive_load(file);
 }
 
 SCM
 gfec_eval_file(const char *file, gfec_error_handler error_handler)
 {
-  char *err_msg = NULL;
-  SCM result;
+    char *err_msg = NULL;
+    SCM result;
 
-  result = scm_internal_stack_catch(SCM_BOOL_T,
-                                    gfec_file_helper,
-                                    (void *) file,
-                                    gfec_catcher,
-                                    &err_msg);
+    result = scm_internal_stack_catch(SCM_BOOL_T,
+                                      gfec_file_helper,
+                                      (void *) file,
+                                      gfec_catcher,
+                                      &err_msg);
 
-  if (err_msg != NULL)
-  {
-    if (error_handler)
-      error_handler(err_msg);
+    if (err_msg != NULL)
+    {
+        if (error_handler)
+            error_handler(err_msg);
 
-    free(err_msg);
+        free(err_msg);
 
-    return SCM_UNDEFINED;
-  }
+        return SCM_UNDEFINED;
+    }
 
-  return result;
+    return result;
 }
 
 static SCM
 gfec_string_helper(void *data)
 {
-  char *string = data;
+    char *string = data;
 
-  return scm_c_eval_string(string);
+    return scm_c_eval_string(string);
 }
 
 SCM
 gfec_eval_string(const char *str, gfec_error_handler error_handler)
 {
-  char *err_msg = NULL;
-  SCM result;
+    char *err_msg = NULL;
+    SCM result;
 
-  result = scm_internal_stack_catch(SCM_BOOL_T,
-                                    gfec_string_helper,
-                                    (void *) str,
-                                    gfec_catcher,
-                                    &err_msg);
+    result = scm_internal_stack_catch(SCM_BOOL_T,
+                                      gfec_string_helper,
+                                      (void *) str,
+                                      gfec_catcher,
+                                      &err_msg);
 
-  if (err_msg != NULL)
-  {
-    if (error_handler)
-      error_handler(err_msg);
+    if (err_msg != NULL)
+    {
+        if (error_handler)
+            error_handler(err_msg);
 
-    free(err_msg);
+        free(err_msg);
 
-    return SCM_UNDEFINED;
-  }
+        return SCM_UNDEFINED;
+    }
 
-  return result;
+    return result;
 }
 
 struct gfec_apply_rec
 {
-  SCM proc;
-  SCM arglist;
+    SCM proc;
+    SCM arglist;
 };
 
 static SCM
 gfec_apply_helper(void *data)
 {
-  struct gfec_apply_rec *apply_rec = (struct gfec_apply_rec *)data;
+    struct gfec_apply_rec *apply_rec = (struct gfec_apply_rec *)data;
 
-  return scm_apply(apply_rec->proc, apply_rec->arglist, SCM_EOL);
+    return scm_apply(apply_rec->proc, apply_rec->arglist, SCM_EOL);
 }
 
 SCM
 gfec_apply(SCM proc, SCM arglist, gfec_error_handler error_handler)
 {
-  char *err_msg = NULL;
-  struct gfec_apply_rec apply_rec;
-  SCM result;
+    char *err_msg = NULL;
+    struct gfec_apply_rec apply_rec;
+    SCM result;
 
-  apply_rec.proc = proc;
-  apply_rec.arglist = arglist;
+    apply_rec.proc = proc;
+    apply_rec.arglist = arglist;
 
-  result = scm_internal_stack_catch(SCM_BOOL_T,
-                                    gfec_apply_helper,
-                                    &apply_rec,
-                                    gfec_catcher,
-                                    &err_msg);
+    result = scm_internal_stack_catch(SCM_BOOL_T,
+                                      gfec_apply_helper,
+                                      &apply_rec,
+                                      gfec_catcher,
+                                      &err_msg);
 
-  if (err_msg != NULL)
-  {
-    if (error_handler)
-      error_handler(err_msg);
+    if (err_msg != NULL)
+    {
+        if (error_handler)
+            error_handler(err_msg);
 
-    free(err_msg);
+        free(err_msg);
 
-    return SCM_UNDEFINED;
-  }
+        return SCM_UNDEFINED;
+    }
 
-  return result;
+    return result;
 }
 
 static int error_in_scm_eval = FALSE;
@@ -177,7 +177,8 @@
 gfec_try_load(gchar *fn)
 {
     g_debug("looking for %s", fn);
-    if (g_file_test(fn, G_FILE_TEST_EXISTS)) {
+    if (g_file_test(fn, G_FILE_TEST_EXISTS))
+    {
         g_debug("trying to load %s", fn);
         error_in_scm_eval = FALSE;
         gfec_eval_file(fn, error_handler);

Modified: gnucash/trunk/src/app-utils/gnc-account-merge.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-account-merge.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-account-merge.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -25,57 +25,57 @@
 GncAccountMergeDisposition
 determine_account_merge_disposition(Account *existing_acct, Account *new_acct)
 {
-  g_assert(new_acct != NULL);
+    g_assert(new_acct != NULL);
 
-  if (existing_acct == NULL)
-    return GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW;
+    if (existing_acct == NULL)
+        return GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW;
 
-  return GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING;
+    return GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING;
 }
 
 GncAccountMergeDisposition
 determine_merge_disposition(Account *existing_root, Account *new_acct)
 {
-  Account *existing_acct;
-  gchar *full_name;
-  
-  full_name = gnc_account_get_full_name(new_acct);
-  existing_acct = gnc_account_lookup_by_full_name(existing_root, full_name);
-  g_free(full_name);
+    Account *existing_acct;
+    gchar *full_name;
 
-  return determine_account_merge_disposition(existing_acct, new_acct);
+    full_name = gnc_account_get_full_name(new_acct);
+    existing_acct = gnc_account_lookup_by_full_name(existing_root, full_name);
+    g_free(full_name);
+
+    return determine_account_merge_disposition(existing_acct, new_acct);
 }
 
 void
 account_trees_merge(Account *existing_root, Account *new_accts_root)
 {
-  GList *accounts, *node;
-  g_return_if_fail(new_accts_root != NULL);
-  g_return_if_fail(existing_root != NULL);
+    GList *accounts, *node;
+    g_return_if_fail(new_accts_root != NULL);
+    g_return_if_fail(existing_root != NULL);
 
-  /* since we're have a chance of mutating the list (via
-   * gnc_account_add_child) while we're iterating over it, iterate
-   * over a copy. */
-  accounts = gnc_account_get_children(new_accts_root);
-  for (node = accounts; node; node = g_list_next(node))
-  {
-    Account *existing_named, *new_acct;
-    const char *name;
+    /* since we're have a chance of mutating the list (via
+     * gnc_account_add_child) while we're iterating over it, iterate
+     * over a copy. */
+    accounts = gnc_account_get_children(new_accts_root);
+    for (node = accounts; node; node = g_list_next(node))
+    {
+        Account *existing_named, *new_acct;
+        const char *name;
 
-    new_acct = (Account*)node->data;
-    name = xaccAccountGetName(new_acct);
-    existing_named = gnc_account_lookup_by_name(existing_root, name);
-    switch (determine_account_merge_disposition(existing_named, new_acct))
-    {
-    case GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING:
-      /* recurse */
-      account_trees_merge(existing_named, new_acct);
-      break;
-    case GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW:
-      /* merge this one in. */
-      gnc_account_append_child(existing_root, new_acct);
-      break;
+        new_acct = (Account*)node->data;
+        name = xaccAccountGetName(new_acct);
+        existing_named = gnc_account_lookup_by_name(existing_root, name);
+        switch (determine_account_merge_disposition(existing_named, new_acct))
+        {
+        case GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING:
+            /* recurse */
+            account_trees_merge(existing_named, new_acct);
+            break;
+        case GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW:
+            /* merge this one in. */
+            gnc_account_append_child(existing_root, new_acct);
+            break;
+        }
     }
-  }
-  g_list_free(accounts);
+    g_list_free(accounts);
 }

Modified: gnucash/trunk/src/app-utils/gnc-account-merge.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-account-merge.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-account-merge.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -23,15 +23,17 @@
 
 #include "Account.h"
 
-typedef enum {
-  GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING,
-  GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW
+typedef enum
+{
+    GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING,
+    GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW
 } GncAccountMergeDisposition;
 
-typedef struct _merge_error {
-  Account *existing_acct;
-  Account *new_acct;
-  GncAccountMergeDisposition disposition;
+typedef struct _merge_error
+{
+    Account *existing_acct;
+    Account *new_acct;
+    GncAccountMergeDisposition disposition;
 } GncAccountMergeError;
 
 GncAccountMergeDisposition determine_account_merge_disposition(Account *existing_acct, Account *new_acct);

Modified: gnucash/trunk/src/app-utils/gnc-accounting-period.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-accounting-period.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-accounting-period.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -1,5 +1,5 @@
 /*
- * gnc-accounting-period.c -- 
+ * gnc-accounting-period.c --
  *
  * Copyright (c) 2005 David Hampton <hampton at employees.org>
  * All rights reserved.
@@ -61,63 +61,69 @@
 
 static time_t
 lookup_start_date_option(const gchar *section,
-			 const gchar *key_choice,
-			 const gchar *key_absolute,
-			 const gchar *key_relative,
-			 GDate *fy_end)
+                         const gchar *key_choice,
+                         const gchar *key_absolute,
+                         const gchar *key_relative,
+                         GDate *fy_end)
 {
-  gchar *choice;
-  time_t time;
-  int which;
+    gchar *choice;
+    time_t time;
+    int which;
 
-  choice = gnc_gconf_get_string(section, key_choice, NULL);
-  if (choice && strcmp(choice, "absolute") == 0) {
-    time = gnc_gconf_get_int(section, key_absolute, NULL);
-  } else {
-    which = gnc_gconf_get_int(section, key_relative, NULL);
-    time = gnc_accounting_period_start_timet(which, fy_end, NULL);
-  }
-  g_free(choice);
-  /* we will need the balance of the last transaction before the start
-     date, so subtract 1 from start date */
-  /* CAS: we don't actually do what this comment says.  I think that's
-     because a bug in the engine has been fixed. */
-  return time;
+    choice = gnc_gconf_get_string(section, key_choice, NULL);
+    if (choice && strcmp(choice, "absolute") == 0)
+    {
+        time = gnc_gconf_get_int(section, key_absolute, NULL);
+    }
+    else
+    {
+        which = gnc_gconf_get_int(section, key_relative, NULL);
+        time = gnc_accounting_period_start_timet(which, fy_end, NULL);
+    }
+    g_free(choice);
+    /* we will need the balance of the last transaction before the start
+       date, so subtract 1 from start date */
+    /* CAS: we don't actually do what this comment says.  I think that's
+       because a bug in the engine has been fixed. */
+    return time;
 }
 
 
 static time_t
 lookup_end_date_option(const gchar *section,
-		       const gchar *key_choice,
-		       const gchar *key_absolute,
-		       const gchar *key_relative,
-		       GDate *fy_end)
+                       const gchar *key_choice,
+                       const gchar *key_absolute,
+                       const gchar *key_relative,
+                       GDate *fy_end)
 {
-  gchar *choice;
-  time_t time;
-  int which;
+    gchar *choice;
+    time_t time;
+    int which;
 
-  choice = gnc_gconf_get_string(section, key_choice, NULL);
-  if (choice && strcmp(choice, "absolute") == 0) {
-    time = gnc_gconf_get_int(section, key_absolute, NULL);
-    time = gnc_timet_get_day_end(time);
-  } else {
-    which = gnc_gconf_get_int(section, key_relative, NULL);
-    time = gnc_accounting_period_end_timet(which, fy_end, NULL);
-  }
-  g_free(choice);
-  if (time == 0)
-    time = -1;
-  return time;
+    choice = gnc_gconf_get_string(section, key_choice, NULL);
+    if (choice && strcmp(choice, "absolute") == 0)
+    {
+        time = gnc_gconf_get_int(section, key_absolute, NULL);
+        time = gnc_timet_get_day_end(time);
+    }
+    else
+    {
+        which = gnc_gconf_get_int(section, key_relative, NULL);
+        time = gnc_accounting_period_end_timet(which, fy_end, NULL);
+    }
+    g_free(choice);
+    if (time == 0)
+        time = -1;
+    return time;
 }
 
 static GDate *
-get_fy_end(void) 
+get_fy_end(void)
 {
     QofBook *book;
     KvpFrame *book_frame;
     gint64 month, day;
-    
+
     book = gnc_get_current_book();
     book_frame = qof_book_get_slots(book);
     month = kvp_frame_get_gint64(book_frame, "/book/fyear_end/month");
@@ -144,7 +150,7 @@
 {
     time_t t;
     GDate *fy_end = get_fy_end();
-    
+
     t = lookup_end_date_option(GCONF_SECTION, KEY_END_CHOICE,
                                KEY_END_DATE, KEY_END_PERIOD, fy_end);
     if (fy_end)
@@ -154,179 +160,191 @@
 
 GDate *
 gnc_accounting_period_start_gdate (GncAccountingPeriod which,
-				   const GDate *fy_end,
-				   const GDate *contains)
+                                   const GDate *fy_end,
+                                   const GDate *contains)
 {
-  GDate *date;
+    GDate *date;
 
-  if (contains) {
-    date = g_date_new_dmy(g_date_get_day(contains),
-			  g_date_get_month(contains),
-			  g_date_get_year(contains));
-  } else {
-    date = g_date_new();
-    g_date_set_time_t(date, time(NULL));
-  }
+    if (contains)
+    {
+        date = g_date_new_dmy(g_date_get_day(contains),
+                              g_date_get_month(contains),
+                              g_date_get_year(contains));
+    }
+    else
+    {
+        date = g_date_new();
+        g_date_set_time_t(date, time(NULL));
+    }
 
-  switch (which) {
-  default:
-    g_message("Undefined relative time constant %d", which);
-    g_date_free(date);
-    return NULL;
+    switch (which)
+    {
+    default:
+        g_message("Undefined relative time constant %d", which);
+        g_date_free(date);
+        return NULL;
 
-  case GNC_ACCOUNTING_PERIOD_TODAY:
-    /* Already have today's date */
-    break;
+    case GNC_ACCOUNTING_PERIOD_TODAY:
+        /* Already have today's date */
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_MONTH:
-    gnc_gdate_set_month_start(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_MONTH:
+        gnc_gdate_set_month_start(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_MONTH_PREV:
-    gnc_gdate_set_prev_month_start(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_MONTH_PREV:
+        gnc_gdate_set_prev_month_start(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_QUARTER:
-    gnc_gdate_set_quarter_start(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_QUARTER:
+        gnc_gdate_set_quarter_start(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_QUARTER_PREV:
-    gnc_gdate_set_prev_quarter_start(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_QUARTER_PREV:
+        gnc_gdate_set_prev_quarter_start(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_CYEAR:
-    gnc_gdate_set_year_start(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_CYEAR:
+        gnc_gdate_set_year_start(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_CYEAR_PREV:
-    gnc_gdate_set_prev_year_start(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_CYEAR_PREV:
+        gnc_gdate_set_prev_year_start(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_FYEAR:
-    if (fy_end == NULL) {
-      g_message("Request for fisal year value but no fiscal year end value provided.");
-      g_date_free(date);
-      return NULL;
-    }
-    gnc_gdate_set_fiscal_year_start(date, fy_end);
-    break;
+    case GNC_ACCOUNTING_PERIOD_FYEAR:
+        if (fy_end == NULL)
+        {
+            g_message("Request for fisal year value but no fiscal year end value provided.");
+            g_date_free(date);
+            return NULL;
+        }
+        gnc_gdate_set_fiscal_year_start(date, fy_end);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_FYEAR_PREV:
-    if (fy_end == NULL) {
-      g_message("Request for fisal year value but no fiscal year end value provided.");
-      g_date_free(date);
-      return NULL;
+    case GNC_ACCOUNTING_PERIOD_FYEAR_PREV:
+        if (fy_end == NULL)
+        {
+            g_message("Request for fisal year value but no fiscal year end value provided.");
+            g_date_free(date);
+            return NULL;
+        }
+        gnc_gdate_set_prev_fiscal_year_start(date, fy_end);
+        break;
     }
-    gnc_gdate_set_prev_fiscal_year_start(date, fy_end);
-    break;
-  }
-  return date;
+    return date;
 }
 
 time_t
 gnc_accounting_period_start_timet (GncAccountingPeriod which,
-				   const GDate *fy_end,
-				   const GDate *contains)
+                                   const GDate *fy_end,
+                                   const GDate *contains)
 {
-  GDate *date;
-  time_t secs;
+    GDate *date;
+    time_t secs;
 
-  date = gnc_accounting_period_start_gdate(which, fy_end, contains);
-  if (!date)
-    return 0;
+    date = gnc_accounting_period_start_gdate(which, fy_end, contains);
+    if (!date)
+        return 0;
 
-  secs = gnc_timet_get_day_start_gdate(date);
-  g_date_free(date);
-  return secs;
+    secs = gnc_timet_get_day_start_gdate(date);
+    g_date_free(date);
+    return secs;
 }
 
 GDate *
 gnc_accounting_period_end_gdate (GncAccountingPeriod which,
-				 const GDate *fy_end,
-				 const GDate *contains)
+                                 const GDate *fy_end,
+                                 const GDate *contains)
 {
-  GDate *date;
+    GDate *date;
 
-  if (contains) {
-    date = g_date_new_dmy(g_date_get_day(contains),
-			  g_date_get_month(contains),
-			  g_date_get_year(contains));
-  } else {
-    date = g_date_new();
-    g_date_set_time_t(date, time(NULL));
-  }
+    if (contains)
+    {
+        date = g_date_new_dmy(g_date_get_day(contains),
+                              g_date_get_month(contains),
+                              g_date_get_year(contains));
+    }
+    else
+    {
+        date = g_date_new();
+        g_date_set_time_t(date, time(NULL));
+    }
 
-  switch (which) {
-  default:
-    g_message("Undefined relative time constant %d", which);
-    g_date_free(date);
-    return 0;
+    switch (which)
+    {
+    default:
+        g_message("Undefined relative time constant %d", which);
+        g_date_free(date);
+        return 0;
 
-  case GNC_ACCOUNTING_PERIOD_TODAY:
-    /* Already have today's date */
-    break;
+    case GNC_ACCOUNTING_PERIOD_TODAY:
+        /* Already have today's date */
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_MONTH:
-    gnc_gdate_set_month_end(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_MONTH:
+        gnc_gdate_set_month_end(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_MONTH_PREV:
-    gnc_gdate_set_prev_month_end(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_MONTH_PREV:
+        gnc_gdate_set_prev_month_end(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_QUARTER:
-    gnc_gdate_set_quarter_end(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_QUARTER:
+        gnc_gdate_set_quarter_end(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_QUARTER_PREV:
-    gnc_gdate_set_prev_quarter_end(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_QUARTER_PREV:
+        gnc_gdate_set_prev_quarter_end(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_CYEAR:
-    gnc_gdate_set_year_end(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_CYEAR:
+        gnc_gdate_set_year_end(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_CYEAR_PREV:
-    gnc_gdate_set_prev_year_end(date);
-    break;
+    case GNC_ACCOUNTING_PERIOD_CYEAR_PREV:
+        gnc_gdate_set_prev_year_end(date);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_FYEAR:
-    if (fy_end == NULL) {
-      g_message("Request for fisal year value but no fiscal year end value provided.");
-      g_date_free(date);
-      return 0;
-    }
-    gnc_gdate_set_fiscal_year_end(date, fy_end);
-    break;
+    case GNC_ACCOUNTING_PERIOD_FYEAR:
+        if (fy_end == NULL)
+        {
+            g_message("Request for fisal year value but no fiscal year end value provided.");
+            g_date_free(date);
+            return 0;
+        }
+        gnc_gdate_set_fiscal_year_end(date, fy_end);
+        break;
 
-  case GNC_ACCOUNTING_PERIOD_FYEAR_PREV:
-    if (fy_end == NULL) {
-      g_message("Request for fisal year value but no fiscal year end value provided.");
-      g_date_free(date);
-      return 0;
+    case GNC_ACCOUNTING_PERIOD_FYEAR_PREV:
+        if (fy_end == NULL)
+        {
+            g_message("Request for fisal year value but no fiscal year end value provided.");
+            g_date_free(date);
+            return 0;
+        }
+        gnc_gdate_set_prev_fiscal_year_end(date, fy_end);
+        break;
     }
-    gnc_gdate_set_prev_fiscal_year_end(date, fy_end);
-    break;
-  }
 
-  return date;
+    return date;
 }
 
 time_t
 gnc_accounting_period_end_timet (GncAccountingPeriod which,
-				 const GDate *fy_end,
-				 const GDate *contains)
+                                 const GDate *fy_end,
+                                 const GDate *contains)
 {
-  GDate *date;
-  time_t secs;
+    GDate *date;
+    time_t secs;
 
-  date = gnc_accounting_period_end_gdate(which, fy_end, contains);
-  if (!date)
-    return 0;
+    date = gnc_accounting_period_end_gdate(which, fy_end, contains);
+    if (!date)
+        return 0;
 
-  secs = gnc_timet_get_day_end_gdate(date);
-  g_date_free(date);
-  return secs ;
+    secs = gnc_timet_get_day_end_gdate(date);
+    g_date_free(date);
+    return secs ;
 }
 
 

Modified: gnucash/trunk/src/app-utils/gnc-accounting-period.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-accounting-period.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-accounting-period.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -1,5 +1,5 @@
 /*
- * gnc-accounting-period.h -- 
+ * gnc-accounting-period.h --
  *
  * Copyright (c) 2005 David Hampton <hampton at employees.org>
  * All rights reserved.
@@ -51,20 +51,21 @@
 /**
  * This specifies a time interval.
  */
-typedef enum {
-  GNC_ACCOUNTING_PERIOD_TODAY,
-  GNC_ACCOUNTING_PERIOD_MONTH,
-  GNC_ACCOUNTING_PERIOD_MONTH_PREV,
-  GNC_ACCOUNTING_PERIOD_QUARTER,
-  GNC_ACCOUNTING_PERIOD_QUARTER_PREV,
-  GNC_ACCOUNTING_PERIOD_CYEAR,
-  GNC_ACCOUNTING_PERIOD_CYEAR_PREV,
-  GNC_ACCOUNTING_PERIOD_CYEAR_LAST,
+typedef enum
+{
+    GNC_ACCOUNTING_PERIOD_TODAY,
+    GNC_ACCOUNTING_PERIOD_MONTH,
+    GNC_ACCOUNTING_PERIOD_MONTH_PREV,
+    GNC_ACCOUNTING_PERIOD_QUARTER,
+    GNC_ACCOUNTING_PERIOD_QUARTER_PREV,
+    GNC_ACCOUNTING_PERIOD_CYEAR,
+    GNC_ACCOUNTING_PERIOD_CYEAR_PREV,
+    GNC_ACCOUNTING_PERIOD_CYEAR_LAST,
 
-  GNC_ACCOUNTING_PERIOD_FYEAR = GNC_ACCOUNTING_PERIOD_CYEAR_LAST,
-  GNC_ACCOUNTING_PERIOD_FYEAR_PREV,
-  GNC_ACCOUNTING_PERIOD_FYEAR_LAST,
-  GNC_ACCOUNTING_PERIOD_LAST = GNC_ACCOUNTING_PERIOD_FYEAR_LAST,
+    GNC_ACCOUNTING_PERIOD_FYEAR = GNC_ACCOUNTING_PERIOD_CYEAR_LAST,
+    GNC_ACCOUNTING_PERIOD_FYEAR_PREV,
+    GNC_ACCOUNTING_PERIOD_FYEAR_LAST,
+    GNC_ACCOUNTING_PERIOD_LAST = GNC_ACCOUNTING_PERIOD_FYEAR_LAST,
 } GncAccountingPeriod;
 
 
@@ -91,8 +92,8 @@
  *  @return The starting day of the specified time interval, as a
  *  GDate. */
 GDate *gnc_accounting_period_start_gdate (GncAccountingPeriod which,
-					  const GDate *fy_end,
-					  const GDate *contains);
+        const GDate *fy_end,
+        const GDate *contains);
 
 
 /** This function returns the starting time for an accounting period.
@@ -115,8 +116,8 @@
  *  @return The starting second of the specified time interval, based
  *  on a zero value of January 1st, 1970. */
 time_t gnc_accounting_period_start_timet (GncAccountingPeriod which,
-					  const GDate *fy_end,
-					  const GDate *contains);
+        const GDate *fy_end,
+        const GDate *contains);
 
 
 /** This function returns the ending date for an accounting period.
@@ -139,8 +140,8 @@
  *  @return The final day of the specified time interval, as a
  *  GDate. */
 GDate *gnc_accounting_period_end_gdate (GncAccountingPeriod which,
-					const GDate *fy_end,
-					const GDate *contains);
+                                        const GDate *fy_end,
+                                        const GDate *contains);
 
 
 /** This function returns the ending time for an accounting period.
@@ -163,8 +164,8 @@
  *  @return The ending second of the specified time interval, based
  *  on a zero value of January 1st, 1970. */
 time_t gnc_accounting_period_end_timet (GncAccountingPeriod which,
-					const GDate *fy_end,
-					const GDate *contains);
+                                        const GDate *fy_end,
+                                        const GDate *contains);
 
 
 /* Get the fiscal accounting period from the preferences and return

Modified: gnucash/trunk/src/app-utils/gnc-component-manager.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-component-manager.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-component-manager.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -32,29 +32,29 @@
 
 typedef struct
 {
-  GNCIdType entity_type;
-  QofEventId event_mask;
+    GNCIdType entity_type;
+    QofEventId event_mask;
 } EntityTypeEventInfo;
 
 typedef struct
 {
-  GHashTable * event_masks;
-  GHashTable * entity_events;
+    GHashTable * event_masks;
+    GHashTable * entity_events;
 
-  gboolean match;
+    gboolean match;
 } ComponentEventInfo;
 
 typedef struct
 {
-  GNCComponentRefreshHandler refresh_handler;
-  GNCComponentCloseHandler close_handler;
-  gpointer user_data;
+    GNCComponentRefreshHandler refresh_handler;
+    GNCComponentCloseHandler close_handler;
+    gpointer user_data;
 
-  ComponentEventInfo watch_info;
+    ComponentEventInfo watch_info;
 
-  char *component_class;
-  gint component_id;
-  gpointer session;
+    char *component_class;
+    gint component_id;
+    gpointer session;
 } ComponentInfo;
 
 
@@ -84,29 +84,29 @@
 static void
 dump_components (void)
 {
-  GList *node;
+    GList *node;
 
-  fprintf (stderr, "Components:\n");
+    fprintf (stderr, "Components:\n");
 
-  for (node = components; node; node = node->next)
-  {
-    ComponentInfo *ci = node->data;
+    for (node = components; node; node = node->next)
+    {
+        ComponentInfo *ci = node->data;
 
-    fprintf (stderr, "  %s:\t%d\n",
-             ci->component_class ? ci->component_class : "(null)",
-             ci->component_id);
-  }
+        fprintf (stderr, "  %s:\t%d\n",
+                 ci->component_class ? ci->component_class : "(null)",
+                 ci->component_id);
+    }
 
-  fprintf (stderr, "\n");
+    fprintf (stderr, "\n");
 }
 #endif
 
 static void
 clear_mask_hash_helper (gpointer key, gpointer value, gpointer user_data)
 {
-  QofEventId * et = value;
+    QofEventId * et = value;
 
-  *et = 0;
+    *et = 0;
 }
 
 /* clear a hash table of the form string --> QofEventId,
@@ -115,38 +115,38 @@
 static void
 clear_mask_hash (GHashTable *hash)
 {
-  if (hash == NULL)
-    return;
+    if (hash == NULL)
+        return;
 
-  g_hash_table_foreach (hash, clear_mask_hash_helper, NULL);
+    g_hash_table_foreach (hash, clear_mask_hash_helper, NULL);
 }
 
 static gboolean
 destroy_mask_hash_helper (gpointer key, gpointer value, gpointer user_data)
 {
-  qof_util_string_cache_remove (key);
-  g_free (value);
+    qof_util_string_cache_remove (key);
+    g_free (value);
 
-  return TRUE;
+    return TRUE;
 }
 
 static void
 destroy_mask_hash (GHashTable *hash)
 {
-  g_hash_table_foreach_remove (hash, destroy_mask_hash_helper, NULL);
-  g_hash_table_destroy (hash);
+    g_hash_table_foreach_remove (hash, destroy_mask_hash_helper, NULL);
+    g_hash_table_destroy (hash);
 }
 
 static gboolean
 destroy_event_hash_helper (gpointer key, gpointer value, gpointer user_data)
 {
-  GUID *guid = key;
-  EventInfo *ei = value;
+    GUID *guid = key;
+    EventInfo *ei = value;
 
-  xaccGUIDFree (guid);
-  g_free (ei);
+    xaccGUIDFree (guid);
+    g_free (ei);
 
-  return TRUE;
+    return TRUE;
 }
 
 /* clear a hash table of the form GUID --> EventInfo, where
@@ -154,131 +154,131 @@
 static void
 clear_event_hash (GHashTable *hash)
 {
-  if (hash == NULL)
-    return;
+    if (hash == NULL)
+        return;
 
-  g_hash_table_foreach_remove (hash, destroy_event_hash_helper, NULL);
+    g_hash_table_foreach_remove (hash, destroy_event_hash_helper, NULL);
 }
 
 static void
 destroy_event_hash (GHashTable *hash)
 {
-  clear_event_hash (hash);
-  g_hash_table_destroy (hash);
+    clear_event_hash (hash);
+    g_hash_table_destroy (hash);
 }
 
 static void
 clear_event_info (ComponentEventInfo *cei)
 {
-  if (!cei)
-    return;
+    if (!cei)
+        return;
 
-  clear_mask_hash (cei->event_masks);
-  clear_event_hash (cei->entity_events);
+    clear_mask_hash (cei->event_masks);
+    clear_event_hash (cei->entity_events);
 }
 
 static void
 add_event (ComponentEventInfo *cei, const GUID *entity,
            QofEventId event_mask, gboolean or_in)
 {
-  GHashTable *hash;
+    GHashTable *hash;
 
-  if (!cei || !cei->entity_events || !entity)
-    return;
+    if (!cei || !cei->entity_events || !entity)
+        return;
 
-  hash = cei->entity_events;
+    hash = cei->entity_events;
 
-  if (event_mask == 0)
-  {
-    gpointer key;
-    gpointer value;
+    if (event_mask == 0)
+    {
+        gpointer key;
+        gpointer value;
 
-    if (or_in)
-      return;
+        if (or_in)
+            return;
 
-    if (g_hash_table_lookup_extended (hash, entity, &key, &value))
-    {
-      g_hash_table_remove (hash, entity);
-      xaccGUIDFree (key);
-      g_free (value);
+        if (g_hash_table_lookup_extended (hash, entity, &key, &value))
+        {
+            g_hash_table_remove (hash, entity);
+            xaccGUIDFree (key);
+            g_free (value);
+        }
     }
-  }
-  else
-  {
-    EventInfo *ei;
-
-    ei = g_hash_table_lookup (hash, entity);
-    if (ei == NULL)
+    else
     {
-      GUID *key;
+        EventInfo *ei;
 
-      key = xaccGUIDMalloc ();
-      *key = *entity;
+        ei = g_hash_table_lookup (hash, entity);
+        if (ei == NULL)
+        {
+            GUID *key;
 
-      ei = g_new (EventInfo, 1);
-      ei->event_mask = 0;
+            key = xaccGUIDMalloc ();
+            *key = *entity;
 
-      g_hash_table_insert (hash, key, ei);
+            ei = g_new (EventInfo, 1);
+            ei->event_mask = 0;
+
+            g_hash_table_insert (hash, key, ei);
+        }
+
+        if (or_in)
+            ei->event_mask |= event_mask;
+        else
+            ei->event_mask = event_mask;
     }
-
-    if (or_in)
-      ei->event_mask |= event_mask;
-    else
-      ei->event_mask = event_mask;
-  }
 }
 
 static void
 add_event_type (ComponentEventInfo *cei, GNCIdTypeConst entity_type,
                 QofEventId event_mask, gboolean or_in)
 {
-  QofEventId *mask;
+    QofEventId *mask;
 
-  g_return_if_fail (cei);
-  g_return_if_fail (cei->event_masks);
-  g_return_if_fail (entity_type);
+    g_return_if_fail (cei);
+    g_return_if_fail (cei->event_masks);
+    g_return_if_fail (entity_type);
 
-  mask = g_hash_table_lookup (cei->event_masks, entity_type);
-  if (!mask)
-  {
-    char * key = qof_util_string_cache_insert ((gpointer) entity_type);
-    mask = g_new0 (QofEventId, 1);
-    g_hash_table_insert (cei->event_masks, key, mask);
-  }
+    mask = g_hash_table_lookup (cei->event_masks, entity_type);
+    if (!mask)
+    {
+        char * key = qof_util_string_cache_insert ((gpointer) entity_type);
+        mask = g_new0 (QofEventId, 1);
+        g_hash_table_insert (cei->event_masks, key, mask);
+    }
 
-  if (or_in)
-    *mask |= event_mask;
-  else
-    *mask = event_mask;
+    if (or_in)
+        *mask |= event_mask;
+    else
+        *mask = event_mask;
 }
 
 static void
 gnc_cm_event_handler (QofInstance *entity,
                       QofEventId event_type,
                       gpointer user_data,
-		      gpointer event_data)
+                      gpointer event_data)
 {
-  const GUID *guid = qof_entity_get_guid(entity);
+    const GUID *guid = qof_entity_get_guid(entity);
 #if CM_DEBUG
-  fprintf (stderr, "event_handler: event %d, entity %p, guid %s\n", event_type,
-	   entity, guid_to_string(guid));
+    fprintf (stderr, "event_handler: event %d, entity %p, guid %s\n", event_type,
+             entity, guid_to_string(guid));
 #endif
-  add_event (&changes, guid, event_type, TRUE);
+    add_event (&changes, guid, event_type, TRUE);
 
-  if (QOF_CHECK_TYPE(entity, GNC_ID_SPLIT))
-  {
-    /* split events are never generated by the engine, but might
-     * be generated by a backend (viz. the postgres backend.)
-     * Handle them like a transaction modify event. */
-    add_event_type (&changes, GNC_ID_TRANS, QOF_EVENT_MODIFY, TRUE);
-  }
-  else
-    add_event_type (&changes, entity->e_type, event_type, TRUE);
+    if (QOF_CHECK_TYPE(entity, GNC_ID_SPLIT))
+    {
+        /* split events are never generated by the engine, but might
+         * be generated by a backend (viz. the postgres backend.)
+         * Handle them like a transaction modify event. */
+        add_event_type (&changes, GNC_ID_TRANS, QOF_EVENT_MODIFY, TRUE);
+    }
+    else
+        add_event_type (&changes, entity->e_type, event_type, TRUE);
 
-  got_events = TRUE;
+    got_events = TRUE;
 
-  if (suspend_counter == 0)
-    gnc_gui_refresh_internal (FALSE);
+    if (suspend_counter == 0)
+        gnc_gui_refresh_internal (FALSE);
 }
 
 static gint handler_id;
@@ -286,139 +286,139 @@
 void
 gnc_component_manager_init (void)
 {
-  if (changes.entity_events)
-  {
-    PERR ("component manager already initialized");
-    return;
-  }
+    if (changes.entity_events)
+    {
+        PERR ("component manager already initialized");
+        return;
+    }
 
-  changes.event_masks = g_hash_table_new (g_str_hash, g_str_equal);
-  changes.entity_events = guid_hash_table_new ();
+    changes.event_masks = g_hash_table_new (g_str_hash, g_str_equal);
+    changes.entity_events = guid_hash_table_new ();
 
-  changes_backup.event_masks = g_hash_table_new (g_str_hash, g_str_equal);
-  changes_backup.entity_events = guid_hash_table_new ();
+    changes_backup.event_masks = g_hash_table_new (g_str_hash, g_str_equal);
+    changes_backup.entity_events = guid_hash_table_new ();
 
-  handler_id = qof_event_register_handler (gnc_cm_event_handler, NULL);
+    handler_id = qof_event_register_handler (gnc_cm_event_handler, NULL);
 }
 
 void
 gnc_component_manager_shutdown (void)
 {
-  if (!changes.entity_events)
-  {
-    PERR ("component manager not initialized");
-    return;
-  }
+    if (!changes.entity_events)
+    {
+        PERR ("component manager not initialized");
+        return;
+    }
 
-  destroy_mask_hash (changes.event_masks);
-  changes.event_masks = NULL;
+    destroy_mask_hash (changes.event_masks);
+    changes.event_masks = NULL;
 
-  destroy_event_hash (changes.entity_events);
-  changes.entity_events = NULL;
+    destroy_event_hash (changes.entity_events);
+    changes.entity_events = NULL;
 
-  destroy_mask_hash (changes_backup.event_masks);
-  changes_backup.event_masks = NULL;
+    destroy_mask_hash (changes_backup.event_masks);
+    changes_backup.event_masks = NULL;
 
-  destroy_event_hash (changes_backup.entity_events);
-  changes_backup.entity_events = NULL;
+    destroy_event_hash (changes_backup.entity_events);
+    changes_backup.entity_events = NULL;
 
-  qof_event_unregister_handler (handler_id);
+    qof_event_unregister_handler (handler_id);
 }
 
 static ComponentInfo *
 find_component (gint component_id)
 {
-  GList *node;
+    GList *node;
 
-  for (node = components; node; node = node->next)
-  {
-    ComponentInfo *ci = node->data;
+    for (node = components; node; node = node->next)
+    {
+        ComponentInfo *ci = node->data;
 
-    if (ci->component_id == component_id)
-      return ci;
-  }
+        if (ci->component_id == component_id)
+            return ci;
+    }
 
-  return NULL;
+    return NULL;
 }
 
 static GList *
 find_components_by_data (gpointer user_data)
 {
-  GList *list = NULL;
-  GList *node;
+    GList *list = NULL;
+    GList *node;
 
-  for (node = components; node; node = node->next)
-  {
-    ComponentInfo *ci = node->data;
+    for (node = components; node; node = node->next)
+    {
+        ComponentInfo *ci = node->data;
 
-    if (ci->user_data == user_data)
-      list = g_list_prepend (list, ci);
-  }
+        if (ci->user_data == user_data)
+            list = g_list_prepend (list, ci);
+    }
 
-  return list;
+    return list;
 }
 
 static GList *
 find_components_by_session (gpointer session)
 {
-  GList *list = NULL;
-  GList *node;
+    GList *list = NULL;
+    GList *node;
 
-  for (node = components; node; node = node->next)
-  {
-    ComponentInfo *ci = node->data;
+    for (node = components; node; node = node->next)
+    {
+        ComponentInfo *ci = node->data;
 
-    if (ci->session == session)
-      list = g_list_prepend (list, ci);
-  }
+        if (ci->session == session)
+            list = g_list_prepend (list, ci);
+    }
 
-  return list;
+    return list;
 }
 
 static ComponentInfo *
 gnc_register_gui_component_internal (const char * component_class)
 {
-  ComponentInfo *ci;
-  gint component_id;
+    ComponentInfo *ci;
+    gint component_id;
 
-  g_return_val_if_fail (component_class, NULL);
+    g_return_val_if_fail (component_class, NULL);
 
-  /* look for a free handler id */
-  component_id = next_component_id;
+    /* look for a free handler id */
+    component_id = next_component_id;
 
-  /* design warning: if we ever get 2^32-1 components, 
-     this loop is infinite.  Instead of fixing it, we'll just 
-     complain when (if) we get half way there (probably never).
-  */ 
-  while (find_component (component_id))
-    if (++component_id == NO_COMPONENT)
-      component_id++;
+    /* design warning: if we ever get 2^32-1 components,
+       this loop is infinite.  Instead of fixing it, we'll just
+       complain when (if) we get half way there (probably never).
+    */
+    while (find_component (component_id))
+        if (++component_id == NO_COMPONENT)
+            component_id++;
 
-  if (component_id < 0) 
-    PERR("Amazing! Half way to running out of component_ids.");
-  
-  /* found one, add the handler */
-  ci = g_new0 (ComponentInfo, 1);
+    if (component_id < 0)
+        PERR("Amazing! Half way to running out of component_ids.");
 
-  ci->watch_info.event_masks = g_hash_table_new (g_str_hash, g_str_equal);
-  ci->watch_info.entity_events = guid_hash_table_new ();
+    /* found one, add the handler */
+    ci = g_new0 (ComponentInfo, 1);
 
-  ci->component_class = g_strdup (component_class);
-  ci->component_id = component_id;
-  ci->session = NULL;
+    ci->watch_info.event_masks = g_hash_table_new (g_str_hash, g_str_equal);
+    ci->watch_info.entity_events = guid_hash_table_new ();
 
-  components = g_list_prepend (components, ci);
+    ci->component_class = g_strdup (component_class);
+    ci->component_id = component_id;
+    ci->session = NULL;
 
-  /* update id for next registration */
-  next_component_id = component_id + 1;
+    components = g_list_prepend (components, ci);
 
+    /* update id for next registration */
+    next_component_id = component_id + 1;
+
 #if CM_DEBUG
-  fprintf (stderr, "Register component %d in class %s\n",
-           component_id, component_class ? component_class : "(null)");
-  dump_components ();
+    fprintf (stderr, "Register component %d in class %s\n",
+             component_id, component_class ? component_class : "(null)");
+    dump_components ();
 #endif
 
-  return ci;
+    return ci;
 }
 
 gint
@@ -427,23 +427,23 @@
                             GNCComponentCloseHandler close_handler,
                             gpointer user_data)
 {
-  ComponentInfo *ci;
+    ComponentInfo *ci;
 
-  /* sanity check */
-  if (!component_class)
-  {
-    PERR ("no class specified");
-    return NO_COMPONENT;
-  }
+    /* sanity check */
+    if (!component_class)
+    {
+        PERR ("no class specified");
+        return NO_COMPONENT;
+    }
 
-  ci = gnc_register_gui_component_internal (component_class);
-  g_return_val_if_fail (ci, NO_COMPONENT);
+    ci = gnc_register_gui_component_internal (component_class);
+    g_return_val_if_fail (ci, NO_COMPONENT);
 
-  ci->refresh_handler = refresh_handler;
-  ci->close_handler = close_handler;
-  ci->user_data = user_data;
+    ci->refresh_handler = refresh_handler;
+    ci->close_handler = close_handler;
+    ci->user_data = user_data;
 
-  return ci->component_id;
+    return ci->component_id;
 }
 
 void
@@ -451,19 +451,19 @@
                                 const GUID *entity,
                                 QofEventId event_mask)
 {
-  ComponentInfo *ci;
+    ComponentInfo *ci;
 
-  if (entity == NULL)
-    return;
+    if (entity == NULL)
+        return;
 
-  ci = find_component (component_id);
-  if (!ci)
-  {
-    PERR ("component not found");
-    return;
-  }
+    ci = find_component (component_id);
+    if (!ci)
+    {
+        PERR ("component not found");
+        return;
+    }
 
-  add_event (&ci->watch_info, entity, event_mask, FALSE);
+    add_event (&ci->watch_info, entity, event_mask, FALSE);
 }
 
 void
@@ -471,7 +471,7 @@
                                        GUID entity,
                                        QofEventId event_mask)
 {
-  gnc_gui_component_watch_entity (component_id, &entity, event_mask);
+    gnc_gui_component_watch_entity (component_id, &entity, event_mask);
 }
 
 void
@@ -479,77 +479,77 @@
                                      GNCIdTypeConst entity_type,
                                      QofEventId event_mask)
 {
-  ComponentInfo *ci;
+    ComponentInfo *ci;
 
-  ci = find_component (component_id);
-  if (!ci)
-  {
-    PERR ("component not found");
-    return;
-  }
+    ci = find_component (component_id);
+    if (!ci)
+    {
+        PERR ("component not found");
+        return;
+    }
 
-  add_event_type (&ci->watch_info, entity_type, event_mask, FALSE);
+    add_event_type (&ci->watch_info, entity_type, event_mask, FALSE);
 }
 
 const EventInfo *
 gnc_gui_get_entity_events (GHashTable *changes, const GUID *entity)
 {
-  if (!changes || !entity)
-    return QOF_EVENT_NONE;
+    if (!changes || !entity)
+        return QOF_EVENT_NONE;
 
-  return g_hash_table_lookup (changes, entity);
+    return g_hash_table_lookup (changes, entity);
 }
 
 void
 gnc_gui_component_clear_watches (gint component_id)
 {
-  ComponentInfo *ci;
+    ComponentInfo *ci;
 
-  ci = find_component (component_id);
-  if (!ci)
-  {
-    PERR ("component not found");
-    return;
-  }
+    ci = find_component (component_id);
+    if (!ci)
+    {
+        PERR ("component not found");
+        return;
+    }
 
-  clear_event_info (&ci->watch_info);
+    clear_event_info (&ci->watch_info);
 }
 
 void
 gnc_unregister_gui_component (gint component_id)
 {
-  ComponentInfo *ci;
+    ComponentInfo *ci;
 
-  ci = find_component (component_id);
-  if (!ci)
-  {
-    PERR ("component %d not found", component_id);
-    return;
-  }
+    ci = find_component (component_id);
+    if (!ci)
+    {
+        PERR ("component %d not found", component_id);
+        return;
+    }
 
 #if CM_DEBUG
-  fprintf (stderr, "Unregister component %d in class %s\n",
-           ci->component_id,
-           ci->component_class ? ci->component_class : "(null)");
+    fprintf (stderr, "Unregister component %d in class %s\n",
+             ci->component_id,
+             ci->component_class ? ci->component_class : "(null)");
 #endif
 
-  gnc_gui_component_clear_watches (component_id);
+    gnc_gui_component_clear_watches (component_id);
 
-  components = g_list_remove (components, ci);
+    components = g_list_remove (components, ci);
 
-  destroy_mask_hash (ci->watch_info.event_masks);
-  ci->watch_info.event_masks = NULL;
+    destroy_mask_hash (ci->watch_info.event_masks);
+    ci->watch_info.event_masks = NULL;
 
-  destroy_event_hash (ci->watch_info.entity_events);
-  ci->watch_info.entity_events = NULL;
+    destroy_event_hash (ci->watch_info.entity_events);
+    ci->watch_info.entity_events = NULL;
 
-  g_free (ci->component_class);
-  ci->component_class = NULL;
+    g_free (ci->component_class);
+    ci->component_class = NULL;
 
-  g_free (ci);
+    g_free (ci);
 
 #if CM_DEBUG
-  dump_components ();
+    dump_components ();
 #endif
 }
 
@@ -557,285 +557,288 @@
 gnc_unregister_gui_component_by_data (const char *component_class,
                                       gpointer user_data)
 {
-  GList *list;
-  GList *node;
+    GList *list;
+    GList *node;
 
-  list = find_components_by_data (user_data);
+    list = find_components_by_data (user_data);
 
-  for (node = list; node; node = node->next)
-  {
-    ComponentInfo *ci = node->data;
+    for (node = list; node; node = node->next)
+    {
+        ComponentInfo *ci = node->data;
 
-    if (component_class &&
-        safe_strcmp (component_class, ci->component_class) != 0)
-      continue;
+        if (component_class &&
+                safe_strcmp (component_class, ci->component_class) != 0)
+            continue;
 
-    gnc_unregister_gui_component (ci->component_id);
-  }
+        gnc_unregister_gui_component (ci->component_id);
+    }
 
-  g_list_free (list);
+    g_list_free (list);
 }
 
 void
 gnc_suspend_gui_refresh (void)
 {
-  suspend_counter++;
+    suspend_counter++;
 
-  if (suspend_counter == 0)
-  {
-    PERR ("suspend counter overflow");
-  }
+    if (suspend_counter == 0)
+    {
+        PERR ("suspend counter overflow");
+    }
 }
 
 void
 gnc_resume_gui_refresh (void)
 {
-  if (suspend_counter == 0)
-  {
-    PERR ("suspend counter underflow");
-    return;
-  }
+    if (suspend_counter == 0)
+    {
+        PERR ("suspend counter underflow");
+        return;
+    }
 
-  suspend_counter--;
+    suspend_counter--;
 
-  if (suspend_counter == 0)
-    gnc_gui_refresh_internal (FALSE);
+    if (suspend_counter == 0)
+        gnc_gui_refresh_internal (FALSE);
 }
 
 static void
 match_type_helper (gpointer key, gpointer value, gpointer user_data)
 {
-  ComponentEventInfo *cei = user_data;
-  GNCIdType id_type = key;
-  QofEventId * et = value;
-  QofEventId * et_2;
+    ComponentEventInfo *cei = user_data;
+    GNCIdType id_type = key;
+    QofEventId * et = value;
+    QofEventId * et_2;
 
-  et_2 = g_hash_table_lookup (cei->event_masks, id_type);
-  if (!et_2)
-    return;
+    et_2 = g_hash_table_lookup (cei->event_masks, id_type);
+    if (!et_2)
+        return;
 
-  if (*et & *et_2)
-    cei->match = TRUE;
+    if (*et & *et_2)
+        cei->match = TRUE;
 }
 
 static void
 match_helper (gpointer key, gpointer value, gpointer user_data)
 {
-  GUID *guid = key;
-  EventInfo *ei_1 = value;
-  EventInfo *ei_2;
-  ComponentEventInfo *cei = user_data;
+    GUID *guid = key;
+    EventInfo *ei_1 = value;
+    EventInfo *ei_2;
+    ComponentEventInfo *cei = user_data;
 
-  ei_2 = g_hash_table_lookup (cei->entity_events, guid);
-  if (!ei_2)
-    return;
+    ei_2 = g_hash_table_lookup (cei->entity_events, guid);
+    if (!ei_2)
+        return;
 
-  if (ei_1->event_mask & ei_2->event_mask)
-    cei->match = TRUE;
+    if (ei_1->event_mask & ei_2->event_mask)
+        cei->match = TRUE;
 }
 
 static gboolean
 changes_match (ComponentEventInfo *cei, ComponentEventInfo *changes)
 {
-  ComponentEventInfo *big_cei;
-  GHashTable *smalltable;
+    ComponentEventInfo *big_cei;
+    GHashTable *smalltable;
 
-  if (cei == NULL)
-    return FALSE;
+    if (cei == NULL)
+        return FALSE;
 
-  /* check types first, for efficiency */
-  cei->match = FALSE;
-  g_hash_table_foreach (changes->event_masks, match_type_helper, cei);
-  if (cei->match)
-    return TRUE;
+    /* check types first, for efficiency */
+    cei->match = FALSE;
+    g_hash_table_foreach (changes->event_masks, match_type_helper, cei);
+    if (cei->match)
+        return TRUE;
 
-  if (g_hash_table_size (cei->entity_events) <=
-      g_hash_table_size (changes->entity_events))
-  {
-    smalltable = cei->entity_events;
-    big_cei = changes;
-  }
-  else
-  {
-    smalltable = changes->entity_events;
-    big_cei = cei;
-  }
+    if (g_hash_table_size (cei->entity_events) <=
+            g_hash_table_size (changes->entity_events))
+    {
+        smalltable = cei->entity_events;
+        big_cei = changes;
+    }
+    else
+    {
+        smalltable = changes->entity_events;
+        big_cei = cei;
+    }
 
-  big_cei->match = FALSE;
+    big_cei->match = FALSE;
 
-  g_hash_table_foreach (smalltable, match_helper, big_cei);
+    g_hash_table_foreach (smalltable, match_helper, big_cei);
 
-  return big_cei->match;
+    return big_cei->match;
 }
 
 static void
 gnc_gui_refresh_internal (gboolean force)
 {
-  GList *list;
-  GList *node;
+    GList *list;
+    GList *node;
 
-  if (!got_events && !force)
-    return;
+    if (!got_events && !force)
+        return;
 
-  gnc_suspend_gui_refresh ();
+    gnc_suspend_gui_refresh ();
 
-  {
-    GHashTable *table;
+    {
+        GHashTable *table;
 
-    table = changes_backup.event_masks;
-    changes_backup.event_masks = changes.event_masks;
-    changes.event_masks = table;
+        table = changes_backup.event_masks;
+        changes_backup.event_masks = changes.event_masks;
+        changes.event_masks = table;
 
-    table = changes_backup.entity_events;
-    changes_backup.entity_events = changes.entity_events;
-    changes.entity_events = table;
-  }
+        table = changes_backup.entity_events;
+        changes_backup.entity_events = changes.entity_events;
+        changes.entity_events = table;
+    }
 
 #if CM_DEBUG
-  fprintf (stderr, "%srefresh!\n", force ? "forced " : "");
+    fprintf (stderr, "%srefresh!\n", force ? "forced " : "");
 #endif
 
-  list = find_component_ids_by_class (NULL);
+    list = find_component_ids_by_class (NULL);
 
-  for (node = list; node; node = node->next)
-  {
-    ComponentInfo *ci = find_component (GPOINTER_TO_INT (node->data));
+    for (node = list; node; node = node->next)
+    {
+        ComponentInfo *ci = find_component (GPOINTER_TO_INT (node->data));
 
-    if (!ci)
-      continue;
+        if (!ci)
+            continue;
 
-    if (!ci->refresh_handler) {
+        if (!ci->refresh_handler)
+        {
 #if CM_DEBUG
-      fprintf (stderr, "no handlers for %s:%d\n", ci->component_class, ci->component_id);
+            fprintf (stderr, "no handlers for %s:%d\n", ci->component_class, ci->component_id);
 #endif
-      continue;
-    }
+            continue;
+        }
 
-    if (force)
-    {
-      if (ci->refresh_handler) {
+        if (force)
+        {
+            if (ci->refresh_handler)
+            {
 #if CM_DEBUG
-	fprintf (stderr, "calling %s:%d C handler\n", ci->component_class, ci->component_id);
+                fprintf (stderr, "calling %s:%d C handler\n", ci->component_class, ci->component_id);
 #endif
-        ci->refresh_handler (NULL, ci->user_data);
-      }
-    }
-    else if (changes_match (&ci->watch_info, &changes_backup))
-    {
-      if (ci->refresh_handler) {
+                ci->refresh_handler (NULL, ci->user_data);
+            }
+        }
+        else if (changes_match (&ci->watch_info, &changes_backup))
+        {
+            if (ci->refresh_handler)
+            {
 #if CM_DEBUG
-	fprintf (stderr, "calling %s:%d C handler\n", ci->component_class, ci->component_id);
+                fprintf (stderr, "calling %s:%d C handler\n", ci->component_class, ci->component_id);
 #endif
-        ci->refresh_handler (changes_backup.entity_events, ci->user_data);
-      }
-    }
-    else
-    {
+                ci->refresh_handler (changes_backup.entity_events, ci->user_data);
+            }
+        }
+        else
+        {
 #if CM_DEBUG
-      fprintf (stderr, "no match for %s:%d\n", ci->component_class, ci->component_id);
+            fprintf (stderr, "no match for %s:%d\n", ci->component_class, ci->component_id);
 #endif
+        }
     }
-  }
 
-  clear_event_info (&changes_backup);
-  got_events = FALSE;
+    clear_event_info (&changes_backup);
+    got_events = FALSE;
 
-  g_list_free (list);
+    g_list_free (list);
 
-  gnc_resume_gui_refresh ();
+    gnc_resume_gui_refresh ();
 }
 
 void
 gnc_gui_refresh_all (void)
 {
-  if (suspend_counter != 0)
-  {
-    PERR ("suspend counter not zero");
-    return;
-  }
+    if (suspend_counter != 0)
+    {
+        PERR ("suspend counter not zero");
+        return;
+    }
 
-  gnc_gui_refresh_internal (TRUE);
+    gnc_gui_refresh_internal (TRUE);
 }
 
 gboolean
 gnc_gui_refresh_suspended (void)
 {
-  return suspend_counter != 0;
+    return suspend_counter != 0;
 }
 
 void
 gnc_close_gui_component (gint component_id)
 {
-  ComponentInfo *ci;
+    ComponentInfo *ci;
 
-  ci = find_component (component_id);
-  if (!ci)
-  {
-    PERR ("component not found");
-    return;
-  }
+    ci = find_component (component_id);
+    if (!ci)
+    {
+        PERR ("component not found");
+        return;
+    }
 
-  if (!ci->close_handler)
-    return;
+    if (!ci->close_handler)
+        return;
 
-  if (ci->close_handler)
-    ci->close_handler (ci->user_data);
+    if (ci->close_handler)
+        ci->close_handler (ci->user_data);
 }
 
 void
 gnc_close_gui_component_by_data (const char *component_class,
                                  gpointer user_data)
 {
-  GList *list;
-  GList *node;
+    GList *list;
+    GList *node;
 
-  list = find_components_by_data (user_data);
+    list = find_components_by_data (user_data);
 
-  for (node = list; node; node = node->next)
-  {
-    ComponentInfo *ci = node->data;
+    for (node = list; node; node = node->next)
+    {
+        ComponentInfo *ci = node->data;
 
-    if (component_class &&
-        safe_strcmp (component_class, ci->component_class) != 0)
-      continue;
+        if (component_class &&
+                safe_strcmp (component_class, ci->component_class) != 0)
+            continue;
 
-    gnc_close_gui_component (ci->component_id);
-  }
+        gnc_close_gui_component (ci->component_id);
+    }
 
-  g_list_free (list);
+    g_list_free (list);
 }
 
 void
 gnc_gui_component_set_session (gint component_id, gpointer session)
 {
-  ComponentInfo *ci;
+    ComponentInfo *ci;
 
-  ci = find_component (component_id);
-  if (!ci)
-  {
-    PERR ("component not found");
-    return;
-  }
+    ci = find_component (component_id);
+    if (!ci)
+    {
+        PERR ("component not found");
+        return;
+    }
 
-  ci->session = session;
+    ci->session = session;
 }
 
 void
 gnc_close_gui_component_by_session (gpointer session)
 {
-  GList *list;
-  GList *node;
+    GList *list;
+    GList *node;
 
-  list = find_components_by_session (session);
+    list = find_components_by_session (session);
 
-  for (node = list; node; node = node->next)
-  {
-    ComponentInfo *ci = node->data;
+    for (node = list; node; node = node->next)
+    {
+        ComponentInfo *ci = node->data;
 
-    gnc_close_gui_component (ci->component_id);
-  }
+        gnc_close_gui_component (ci->component_id);
+    }
 
-  g_list_free (list);
+    g_list_free (list);
 }
 
 GList *
@@ -843,26 +846,26 @@
                          GNCComponentFindHandler find_handler,
                          gpointer find_data)
 {
-  GList *list = NULL;
-  GList *node;
+    GList *list = NULL;
+    GList *node;
 
-  if (!component_class)
-    return NULL;
+    if (!component_class)
+        return NULL;
 
-  for (node = components; node; node = node->next)
-  {
-    ComponentInfo *ci = node->data;
+    for (node = components; node; node = node->next)
+    {
+        ComponentInfo *ci = node->data;
 
-    if (safe_strcmp (component_class, ci->component_class) != 0)
-      continue;
+        if (safe_strcmp (component_class, ci->component_class) != 0)
+            continue;
 
-    if (find_handler && !find_handler (find_data, ci->user_data))
-      continue;
+        if (find_handler && !find_handler (find_data, ci->user_data))
+            continue;
 
-    list = g_list_prepend (list, ci->user_data);
-  }
+        list = g_list_prepend (list, ci->user_data);
+    }
 
-  return list;
+    return list;
 }
 
 gpointer
@@ -870,48 +873,48 @@
                               GNCComponentFindHandler find_handler,
                               gpointer find_data)
 {
-  GList *list;
-  gpointer user_data;
+    GList *list;
+    gpointer user_data;
 
 #if CM_DEBUG
-  fprintf (stderr, "find: class %s, fn %p, data %p\n", component_class,
-	   find_handler, find_data);
+    fprintf (stderr, "find: class %s, fn %p, data %p\n", component_class,
+             find_handler, find_data);
 #endif
-  if (!component_class)
-    return NULL;
+    if (!component_class)
+        return NULL;
 
-  list = gnc_find_gui_components (component_class, find_handler, find_data);
-  if (!list)
-    return NULL;
+    list = gnc_find_gui_components (component_class, find_handler, find_data);
+    if (!list)
+        return NULL;
 
-  user_data = list->data;
+    user_data = list->data;
 
-  g_list_free (list);
+    g_list_free (list);
 
 #if CM_DEBUG
-  fprintf (stderr, "found: data %p\n", user_data);
+    fprintf (stderr, "found: data %p\n", user_data);
 #endif
-  return user_data;
+    return user_data;
 }
 
 static GList *
 find_component_ids_by_class (const char *component_class)
 {
-  GList *list = NULL;
-  GList *node;
+    GList *list = NULL;
+    GList *node;
 
-  for (node = components; node; node = node->next)
-  {
-    ComponentInfo *ci = node->data;
+    for (node = components; node; node = node->next)
+    {
+        ComponentInfo *ci = node->data;
 
-    if (component_class &&
-        safe_strcmp (component_class, ci->component_class) != 0)
-      continue;
+        if (component_class &&
+                safe_strcmp (component_class, ci->component_class) != 0)
+            continue;
 
-    list = g_list_prepend (list, GINT_TO_POINTER (ci->component_id));
-  }
+        list = g_list_prepend (list, GINT_TO_POINTER (ci->component_id));
+    }
 
-  return list;
+    return list;
 }
 
 gint
@@ -919,27 +922,27 @@
                            GNCComponentHandler handler,
                            gpointer iter_data)
 {
-  GList *list;
-  GList *node;
-  gint count = 0;
+    GList *list;
+    GList *node;
+    gint count = 0;
 
-  if (!handler)
-    return(0);
+    if (!handler)
+        return(0);
 
-  /* so components can be destroyed during the forall */
-  list = find_component_ids_by_class (component_class);
+    /* so components can be destroyed during the forall */
+    list = find_component_ids_by_class (component_class);
 
-  for (node = list; node; node = node->next)
-  {
-    ComponentInfo *ci = find_component (GPOINTER_TO_INT (node->data));
+    for (node = list; node; node = node->next)
+    {
+        ComponentInfo *ci = find_component (GPOINTER_TO_INT (node->data));
 
-    if (!ci)
-      continue;
+        if (!ci)
+            continue;
 
-    if (handler (ci->component_class, ci->component_id, ci->user_data, iter_data))
-      count++;
-  }
+        if (handler (ci->component_class, ci->component_id, ci->user_data, iter_data))
+            count++;
+    }
 
-  g_list_free (list);
-  return(count);
+    g_list_free (list);
+    return(count);
 }

Modified: gnucash/trunk/src/app-utils/gnc-component-manager.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-component-manager.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-component-manager.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -30,7 +30,7 @@
 
 typedef struct
 {
-  QofEventId event_mask;
+    QofEventId event_mask;
 } EventInfo;
 
 
@@ -44,7 +44,7 @@
  *          GUIDs to EventInfo structs describing which
  *          events have been received. Entities not in
  *          the hash have not generated any events.
- *          Entities which have been destroyed will be in 
+ *          Entities which have been destroyed will be in
  *          the hash, but may not exist anymore.
  *
  *          Note since refreshes may not occur with every change,
@@ -58,7 +58,7 @@
  *                      entities used by the component may have
  *                      already been deleted. 'Refreshing' the
  *                      component may require closing the component.
- * 
+ *
  * Notes on dealing with destroyed entities: As stated above, entities
  * in the changes GHashTable may no longer exist.  So how can you
  * determine if this has happened?  Well, it's a good idea to check
@@ -71,7 +71,7 @@
  * user_data: user_data supplied when component was registered.
  */
 typedef void (*GNCComponentRefreshHandler) (GHashTable *changes,
-                                            gpointer user_data);
+        gpointer user_data);
 
 /* GNCComponentCloseHandler
  *   Handler invoked to close the component.
@@ -94,7 +94,7 @@
  * Return: TRUE if the component matches the search criteria.
  */
 typedef gboolean (*GNCComponentFindHandler) (gpointer find_data,
-                                             gpointer user_data);
+        gpointer user_data);
 
 /* GNCComponentHandler
  *   Generic handler used in iterating over components.
@@ -106,9 +106,9 @@
  * Return: TRUE if the callback did something
  */
 typedef gboolean (*GNCComponentHandler) (const char *class,
-					 gint component_id,
-					 gpointer user_data,
-					 gpointer iter_data);
+        gint component_id,
+        gpointer user_data,
+        gpointer iter_data);
 
 /* gnc_component_manager_init
  *   Initialize the component manager.
@@ -183,8 +183,8 @@
  *               setting the mask to 0 turns off watching for the entity.
  */
 void gnc_gui_component_watch_entity_direct (gint component_id,
-                                            GUID entity,
-                                            QofEventId event_mask);
+        GUID entity,
+        QofEventId event_mask);
 
 /* gnc_gui_component_watch_entity_type
  *   Watch all entities of a particular type.
@@ -196,8 +196,8 @@
  *               setting the mask to 0 turns off watching for the entity type
  */
 void gnc_gui_component_watch_entity_type (gint component_id,
-                                          GNCIdTypeConst entity_type,
-                                          QofEventId event_mask);
+        GNCIdTypeConst entity_type,
+        QofEventId event_mask);
 
 /* gnc_gui_get_entity_events
  *   Return the event info of the events which have been generated by
@@ -210,7 +210,7 @@
  *          if it is not found.
  */
 const EventInfo * gnc_gui_get_entity_events (GHashTable *changes,
-                                             const GUID *entity);
+        const GUID *entity);
 
 /* gnc_gui_component_clear_watches
  *   Clear all watches for the component.
@@ -235,7 +235,7 @@
  *                  class are unregistered.
  */
 void gnc_unregister_gui_component_by_data (const char *component_class,
-                                           gpointer user_data);
+        gpointer user_data);
 
 /* gnc_suspend_gui_refresh
  *   Suspend refresh handlers by the component manager.

Modified: gnucash/trunk/src/app-utils/gnc-druid-cb.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-cb.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-cb.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -22,4 +22,4 @@
 #include "gnc-basic-gobject.h"
 
 GNC_BASIC_GOBJECT(GNCDruidCB, GNCDruidCBClass, G_TYPE_OBJECT, NULL, NULL,
-		  gnc_druid_cb_get_type, gnc_druid_cb_new)
+                  gnc_druid_cb_get_type, gnc_druid_cb_new)

Modified: gnucash/trunk/src/app-utils/gnc-druid-cb.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-cb.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-cb.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -41,16 +41,16 @@
 
 struct _GNCDruidCB
 {
-  GObject obj;
+    GObject obj;
 
-  GNCDruid* druid_ctx;
-  GNCDruidProvider* prov_ctx;
-  gpointer be_ctx;
+    GNCDruid* druid_ctx;
+    GNCDruidProvider* prov_ctx;
+    gpointer be_ctx;
 };
 
 struct _GNCDruidCBClass
 {
-  GObjectClass parent_class;
+    GObjectClass parent_class;
 };
 
 GType	gnc_druid_cb_get_type(void);

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider-desc-edge.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider-desc-edge.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider-desc-edge.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -28,78 +28,78 @@
 static GNCDruidProviderDescClass *parent_class;
 
 GNC_BASIC_GOBJECT(GNCDruidProviderDescEdge, GNCDruidProviderDescEdgeClass,
-		  G_TYPE_GNC_DRUID_PROVIDER_DESC,
-		  gnc_druid_provider_desc_edge_class_init,
-		  gnc_druid_provider_desc_edge_init,
-		  gnc_druid_provider_desc_edge_get_type,
-		  gnc_druid_provider_desc_edge_new)
+                  G_TYPE_GNC_DRUID_PROVIDER_DESC,
+                  gnc_druid_provider_desc_edge_class_init,
+                  gnc_druid_provider_desc_edge_init,
+                  gnc_druid_provider_desc_edge_get_type,
+                  gnc_druid_provider_desc_edge_new)
 
 static void
 gnc_druid_provider_desc_edge_class_init (GNCDruidProviderDescEdgeClass *klass)
 {
-  GObjectClass *object_class;
-	
-  object_class = G_OBJECT_CLASS (klass);
-  parent_class = g_type_class_peek_parent (klass);
+    GObjectClass *object_class;
 
-  object_class->finalize = gnc_druid_provider_desc_edge_finalize;
+    object_class = G_OBJECT_CLASS (klass);
+    parent_class = g_type_class_peek_parent (klass);
+
+    object_class->finalize = gnc_druid_provider_desc_edge_finalize;
 }
 
 static void
 gnc_druid_provider_desc_edge_finalize (GObject *obj)
 {
-  GNCDruidProviderDescEdge *desc = (GNCDruidProviderDescEdge *)obj;
+    GNCDruidProviderDescEdge *desc = (GNCDruidProviderDescEdge *)obj;
 
-  if (desc->text)
-    g_free(desc->text);
+    if (desc->text)
+        g_free(desc->text);
 
-  G_OBJECT_CLASS (parent_class)->finalize(obj);
+    G_OBJECT_CLASS (parent_class)->finalize(obj);
 }
 
 static void
 gnc_druid_provider_desc_edge_init (GNCDruidProviderDescEdge *o)
 {
-  o->parent.name = GNC_DRUID_PROVIDER_TYPE_EDGE;
+    o->parent.name = GNC_DRUID_PROVIDER_TYPE_EDGE;
 }
 
 GNCDruidProviderDescEdge*
 gnc_druid_provider_desc_edge_new_with_data(GNCDruidProviderDescEdgeWhich which,
-					   const gchar* title,
-					   const gchar* text)
+        const gchar* title,
+        const gchar* text)
 {
-  GNCDruidProviderDescEdge* desc;
+    GNCDruidProviderDescEdge* desc;
 
-  desc = gnc_druid_provider_desc_edge_new();
-  g_assert(desc);
+    desc = gnc_druid_provider_desc_edge_new();
+    g_assert(desc);
 
-  gnc_druid_provider_desc_edge_set_which(desc, which);
-  if (text)
-    gnc_druid_provider_desc_edge_set_text(desc, text);
-  if (title)
-    gnc_druid_provider_desc_set_title(&(desc->parent), title);
+    gnc_druid_provider_desc_edge_set_which(desc, which);
+    if (text)
+        gnc_druid_provider_desc_edge_set_text(desc, text);
+    if (title)
+        gnc_druid_provider_desc_set_title(&(desc->parent), title);
 
-  return desc;
+    return desc;
 }
 
 void
 gnc_druid_provider_desc_edge_set_text(GNCDruidProviderDescEdge* desc,
-				      const gchar* text)
+                                      const gchar* text)
 {
-  g_return_if_fail(desc);
-  g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_EDGE(desc));
-  g_return_if_fail(text);
+    g_return_if_fail(desc);
+    g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_EDGE(desc));
+    g_return_if_fail(text);
 
-  if (desc->text)
-    g_free(desc->text);
-  desc->text = g_strdup(text);
+    if (desc->text)
+        g_free(desc->text);
+    desc->text = g_strdup(text);
 }
 
 void
 gnc_druid_provider_desc_edge_set_which(GNCDruidProviderDescEdge* desc,
-				       GNCDruidProviderDescEdgeWhich which)
+                                       GNCDruidProviderDescEdgeWhich which)
 {
-  g_return_if_fail(desc);
-  g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_EDGE(desc));
+    g_return_if_fail(desc);
+    g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_EDGE(desc));
 
-  desc->first_or_last = which;
+    desc->first_or_last = which;
 }

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider-desc-edge.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider-desc-edge.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider-desc-edge.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -36,37 +36,38 @@
 
 #include "gnc-druid.h"
 
-typedef enum {
-  GNC_DPE_FIRST = 1,
-  GNC_DPE_LAST
+typedef enum
+{
+    GNC_DPE_FIRST = 1,
+    GNC_DPE_LAST
 } GNCDruidProviderDescEdgeWhich;
 
 #define GNC_DRUID_PROVIDER_TYPE_EDGE	"edge"
 
 struct _GNCDruidProviderDescEdge
 {
-  GNCDruidProviderDesc parent;
+    GNCDruidProviderDesc parent;
 
-  gchar* text;
-  GNCDruidProviderDescEdgeWhich first_or_last;
+    gchar* text;
+    GNCDruidProviderDescEdgeWhich first_or_last;
 };
 
 struct _GNCDruidProviderDescEdgeClass
 {
-  GNCDruidProviderDescClass parent;
+    GNCDruidProviderDescClass parent;
 };
 
 GType	gnc_druid_provider_desc_edge_get_type(void);
 GNCDruidProviderDescEdge* gnc_druid_provider_desc_edge_new(void);
 GNCDruidProviderDescEdge*
 gnc_druid_provider_desc_edge_new_with_data(GNCDruidProviderDescEdgeWhich,
-					   const gchar* title,
-					   const gchar* text);
+        const gchar* title,
+        const gchar* text);
 
 void	gnc_druid_provider_desc_edge_set_text(GNCDruidProviderDescEdge*,
-					       const gchar* text);
+        const gchar* text);
 void	gnc_druid_provider_desc_edge_set_which(GNCDruidProviderDescEdge*,
-					       GNCDruidProviderDescEdgeWhich);
+        GNCDruidProviderDescEdgeWhich);
 
 
 /* methods */

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider-desc-file.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider-desc-file.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider-desc-file.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -28,109 +28,109 @@
 static GNCDruidProviderDescClass *parent_class;
 
 GNC_BASIC_GOBJECT(GNCDruidProviderDescFile, GNCDruidProviderDescFileClass,
-		  G_TYPE_GNC_DRUID_PROVIDER_DESC,
-		  gnc_druid_provider_desc_file_class_init,
-		  gnc_druid_provider_desc_file_init,
-		  gnc_druid_provider_desc_file_get_type,
-		  gnc_druid_provider_desc_file_new)
+                  G_TYPE_GNC_DRUID_PROVIDER_DESC,
+                  gnc_druid_provider_desc_file_class_init,
+                  gnc_druid_provider_desc_file_init,
+                  gnc_druid_provider_desc_file_get_type,
+                  gnc_druid_provider_desc_file_new)
 
 static void
 gnc_druid_provider_desc_file_class_init (GNCDruidProviderDescFileClass *klass)
 {
-  GObjectClass *object_class;
-	
-  object_class = G_OBJECT_CLASS (klass);
-  parent_class = g_type_class_peek_parent (klass);
+    GObjectClass *object_class;
 
-  object_class->finalize = gnc_druid_provider_desc_file_finalize;
+    object_class = G_OBJECT_CLASS (klass);
+    parent_class = g_type_class_peek_parent (klass);
+
+    object_class->finalize = gnc_druid_provider_desc_file_finalize;
 }
 
 static void
 gnc_druid_provider_desc_file_finalize (GObject *obj)
 {
-  GNCDruidProviderDescFile *desc = (GNCDruidProviderDescFile *)obj;
+    GNCDruidProviderDescFile *desc = (GNCDruidProviderDescFile *)obj;
 
-  if (desc->text)
-    g_free(desc->text);
-  if (desc->last_dir)
-    g_free(desc->last_dir);
-  if (desc->history_id)
-    g_free(desc->history_id);
+    if (desc->text)
+        g_free(desc->text);
+    if (desc->last_dir)
+        g_free(desc->last_dir);
+    if (desc->history_id)
+        g_free(desc->history_id);
 
-  G_OBJECT_CLASS (parent_class)->finalize(obj);
+    G_OBJECT_CLASS (parent_class)->finalize(obj);
 }
 
 static void
 gnc_druid_provider_desc_file_init (GNCDruidProviderDescFile *o)
 {
-  o->parent.name = GNC_DRUID_PROVIDER_TYPE_FILE;
+    o->parent.name = GNC_DRUID_PROVIDER_TYPE_FILE;
 }
 
 GNCDruidProviderDescFile*
 gnc_druid_provider_desc_file_new_with_data(const gchar* title,
-					   const gchar* text,
-					   const gchar* history_id,
-					   const gchar* last_dir,
-					   gboolean glob,
-					   GNCDruidProviderCB next_cb,
-					   void (*remove_file)(gpointer, gpointer))
+        const gchar* text,
+        const gchar* history_id,
+        const gchar* last_dir,
+        gboolean glob,
+        GNCDruidProviderCB next_cb,
+        void (*remove_file)(gpointer, gpointer))
 {
-  GNCDruidProviderDescFile* desc;
+    GNCDruidProviderDescFile* desc;
 
-  desc = gnc_druid_provider_desc_file_new();
-  g_assert(desc);
+    desc = gnc_druid_provider_desc_file_new();
+    g_assert(desc);
 
-  desc->parent.next_cb = next_cb;
-  desc->remove_file = remove_file;
-  desc->glob = glob;
+    desc->parent.next_cb = next_cb;
+    desc->remove_file = remove_file;
+    desc->glob = glob;
 
-  if (text)
-    gnc_druid_provider_desc_file_set_text(desc, text);
-  if (history_id)
-    gnc_druid_provider_desc_file_set_history_id(desc, history_id);
-  if (last_dir)
-    gnc_druid_provider_desc_file_set_last_dir(desc, last_dir);
-  if (title)
-    gnc_druid_provider_desc_set_title(&(desc->parent), title);
+    if (text)
+        gnc_druid_provider_desc_file_set_text(desc, text);
+    if (history_id)
+        gnc_druid_provider_desc_file_set_history_id(desc, history_id);
+    if (last_dir)
+        gnc_druid_provider_desc_file_set_last_dir(desc, last_dir);
+    if (title)
+        gnc_druid_provider_desc_set_title(&(desc->parent), title);
 
-  return desc;
+    return desc;
 }
 
 void
 gnc_druid_provider_desc_file_set_text(GNCDruidProviderDescFile* desc,
-				      const gchar* text)
+                                      const gchar* text)
 {
-  g_return_if_fail(desc);
-  g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_FILE(desc));
-  g_return_if_fail(text);
+    g_return_if_fail(desc);
+    g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_FILE(desc));
+    g_return_if_fail(text);
 
-  if (desc->text)
-    g_free(desc->text);
-  desc->text = g_strdup(text);
+    if (desc->text)
+        g_free(desc->text);
+    desc->text = g_strdup(text);
 }
 
 void
 gnc_druid_provider_desc_file_set_last_dir(GNCDruidProviderDescFile* desc,
-					  const gchar* last_dir)
+        const gchar* last_dir)
 {
-  g_return_if_fail(desc);
-  g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_FILE(desc));
-  g_return_if_fail(last_dir);
+    g_return_if_fail(desc);
+    g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_FILE(desc));
+    g_return_if_fail(last_dir);
 
-  if (desc->last_dir)
-    g_free(desc->last_dir);
-  desc->last_dir = g_strdup(last_dir);
+    if (desc->last_dir)
+        g_free(desc->last_dir);
+    desc->last_dir = g_strdup(last_dir);
 }
 
 void
 gnc_druid_provider_desc_file_set_history_id(GNCDruidProviderDescFile* desc,
-					    const gchar* history_id)
+        const gchar* history_id)
 {
-  g_return_if_fail(desc);
-  g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_FILE(desc));
-  g_return_if_fail(history_id);
+    g_return_if_fail(desc);
+    g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_FILE(desc));
+    g_return_if_fail(history_id);
 
-  if (desc->history_id)
-    g_free(desc->history_id);
-  desc->history_id = g_strdup(history_id);
+    if (desc->history_id)
+        g_free(desc->history_id);
+    desc->history_id = g_strdup(history_id);
 }

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider-desc-file.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider-desc-file.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider-desc-file.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -42,39 +42,39 @@
 
 struct _GNCDruidProviderDescFile
 {
-  GNCDruidProviderDesc parent;
+    GNCDruidProviderDesc parent;
 
-  gchar* text;
-  gchar* last_dir;
-  gchar* history_id;
-  gboolean glob;
-  void (*remove_file)(gpointer be_ctx, gpointer file_ctx);
+    gchar* text;
+    gchar* last_dir;
+    gchar* history_id;
+    gboolean glob;
+    void (*remove_file)(gpointer be_ctx, gpointer file_ctx);
 
-  GNCDruidProviderDescMultifile *multifile_provider;
+    GNCDruidProviderDescMultifile *multifile_provider;
 };
 
 struct _GNCDruidProviderDescFileClass
 {
-  GNCDruidProviderDescClass parent;
+    GNCDruidProviderDescClass parent;
 };
 
 GType	gnc_druid_provider_desc_file_get_type(void);
 GNCDruidProviderDescFile* gnc_druid_provider_desc_file_new(void);
 GNCDruidProviderDescFile*
 gnc_druid_provider_desc_file_new_with_data(const gchar* title,
-					   const gchar* text,
-					   const gchar* history_id,
-					   const gchar* last_dir,
-					   gboolean glob,
-					   GNCDruidProviderCB next_cb,
-					   void (*remove_file)(gpointer, gpointer));
+        const gchar* text,
+        const gchar* history_id,
+        const gchar* last_dir,
+        gboolean glob,
+        GNCDruidProviderCB next_cb,
+        void (*remove_file)(gpointer, gpointer));
 
 void	gnc_druid_provider_desc_file_set_text(GNCDruidProviderDescFile*,
-					       const gchar* text);
+        const gchar* text);
 void	gnc_druid_provider_desc_file_set_last_dir(GNCDruidProviderDescFile*,
-						    const gchar* last_dir);
+        const gchar* last_dir);
 void	gnc_druid_provider_desc_file_set_history_id(GNCDruidProviderDescFile*,
-						    const gchar* history_id);
+        const gchar* history_id);
 
 /* methods */
 

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider-desc-multifile.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider-desc-multifile.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider-desc-multifile.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -28,75 +28,75 @@
 static GNCDruidProviderDescClass *parent_class;
 
 GNC_BASIC_GOBJECT(GNCDruidProviderDescMultifile, GNCDruidProviderDescMultifileClass,
-		  G_TYPE_GNC_DRUID_PROVIDER_DESC,
-		  gnc_druid_provider_desc_multifile_class_init,
-		  gnc_druid_provider_desc_multifile_init,
-		  gnc_druid_provider_desc_multifile_get_type,
-		  gnc_druid_provider_desc_multifile_new)
+                  G_TYPE_GNC_DRUID_PROVIDER_DESC,
+                  gnc_druid_provider_desc_multifile_class_init,
+                  gnc_druid_provider_desc_multifile_init,
+                  gnc_druid_provider_desc_multifile_get_type,
+                  gnc_druid_provider_desc_multifile_new)
 
 static void
 gnc_druid_provider_desc_multifile_class_init (GNCDruidProviderDescMultifileClass *klass)
 {
-  GObjectClass *object_class;
-	
-  object_class = G_OBJECT_CLASS (klass);
-  parent_class = g_type_class_peek_parent (klass);
+    GObjectClass *object_class;
 
-  object_class->finalize = gnc_druid_provider_desc_multifile_finalize;
+    object_class = G_OBJECT_CLASS (klass);
+    parent_class = g_type_class_peek_parent (klass);
+
+    object_class->finalize = gnc_druid_provider_desc_multifile_finalize;
 }
 
 static void
 gnc_druid_provider_desc_multifile_finalize (GObject *obj)
 {
-  GNCDruidProviderDescMultifile *desc = (GNCDruidProviderDescMultifile *)obj;
+    GNCDruidProviderDescMultifile *desc = (GNCDruidProviderDescMultifile *)obj;
 
-  if (desc->text)
-    g_free(desc->text);
+    if (desc->text)
+        g_free(desc->text);
 
-  G_OBJECT_CLASS (parent_class)->finalize(obj);
+    G_OBJECT_CLASS (parent_class)->finalize(obj);
 }
 
 static void
 gnc_druid_provider_desc_multifile_init (GNCDruidProviderDescMultifile *o)
 {
-  o->parent.name = GNC_DRUID_PROVIDER_TYPE_MULTIFILE;
+    o->parent.name = GNC_DRUID_PROVIDER_TYPE_MULTIFILE;
 }
 
 GNCDruidProviderDescMultifile*
 gnc_druid_provider_desc_multifile_new_with_data(const gchar* title,
-						const gchar* text,
-						GNCDruidProviderDescFile *file_prov,
-						GNCDruidProviderCB next_cb,
-						GList* (*get_files)(gpointer),
-						const gchar* (*get_filename)(gpointer, gpointer))
+        const gchar* text,
+        GNCDruidProviderDescFile *file_prov,
+        GNCDruidProviderCB next_cb,
+        GList* (*get_files)(gpointer),
+        const gchar* (*get_filename)(gpointer, gpointer))
 {
-  GNCDruidProviderDescMultifile* desc;
+    GNCDruidProviderDescMultifile* desc;
 
-  desc = gnc_druid_provider_desc_multifile_new();
-  g_assert(desc);
+    desc = gnc_druid_provider_desc_multifile_new();
+    g_assert(desc);
 
-  desc->file_provider = file_prov;
-  desc->get_files = get_files;
-  desc->get_filename = get_filename;
-  desc->parent.next_cb = next_cb;
+    desc->file_provider = file_prov;
+    desc->get_files = get_files;
+    desc->get_filename = get_filename;
+    desc->parent.next_cb = next_cb;
 
-  if (text)
-    gnc_druid_provider_desc_multifile_set_text(desc, text);
-  if (title)
-    gnc_druid_provider_desc_set_title(&(desc->parent), title);
+    if (text)
+        gnc_druid_provider_desc_multifile_set_text(desc, text);
+    if (title)
+        gnc_druid_provider_desc_set_title(&(desc->parent), title);
 
-  return desc;
+    return desc;
 }
 
 void
 gnc_druid_provider_desc_multifile_set_text(GNCDruidProviderDescMultifile* desc,
-					   const gchar* text)
+        const gchar* text)
 {
-  g_return_if_fail(desc);
-  g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_MULTIFILE(desc));
-  g_return_if_fail(text);
+    g_return_if_fail(desc);
+    g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC_MULTIFILE(desc));
+    g_return_if_fail(text);
 
-  if (desc->text)
-    g_free(desc->text);
-  desc->text = g_strdup(text);
+    if (desc->text)
+        g_free(desc->text);
+    desc->text = g_strdup(text);
 }

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider-desc-multifile.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider-desc-multifile.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider-desc-multifile.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -41,31 +41,31 @@
 
 struct _GNCDruidProviderDescMultifile
 {
-  GNCDruidProviderDesc parent;
+    GNCDruidProviderDesc parent;
 
-  gchar* text;
-  GNCDruidProviderDescFile* file_provider;
-  GList* (*get_files)(gpointer be_ctx);
-  const gchar* (*get_filename)(gpointer be_ctx, gpointer file_ctx);
+    gchar* text;
+    GNCDruidProviderDescFile* file_provider;
+    GList* (*get_files)(gpointer be_ctx);
+    const gchar* (*get_filename)(gpointer be_ctx, gpointer file_ctx);
 };
 
 struct _GNCDruidProviderDescMultifileClass
 {
-  GNCDruidProviderDescClass parent;
+    GNCDruidProviderDescClass parent;
 };
 
 GType	gnc_druid_provider_desc_multifile_get_type(void);
 GNCDruidProviderDescMultifile* gnc_druid_provider_desc_multifile_new(void);
 GNCDruidProviderDescMultifile*
 gnc_druid_provider_desc_multifile_new_with_data(const gchar* title,
-						const gchar* text,
-						GNCDruidProviderDescFile *file_prov,
-						GNCDruidProviderCB next_cb,
-						GList* (*get_files)(gpointer),
-						const gchar* (*get_filename)(gpointer, gpointer));
+        const gchar* text,
+        GNCDruidProviderDescFile *file_prov,
+        GNCDruidProviderCB next_cb,
+        GList* (*get_files)(gpointer),
+        const gchar* (*get_filename)(gpointer, gpointer));
 
 void	gnc_druid_provider_desc_multifile_set_text(GNCDruidProviderDescMultifile*,
-						   const gchar* text);
+        const gchar* text);
 
 /* methods */
 

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider-desc.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider-desc.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider-desc.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -27,39 +27,39 @@
 static GObjectClass *parent_class;
 
 GNC_BASIC_GOBJECT_TYPE(GNCDruidProviderDesc, GNCDruidProviderDescClass,
-		       G_TYPE_OBJECT, gnc_druid_provider_desc_class_init, NULL,
-		       gnc_druid_provider_desc_get_type)
+                       G_TYPE_OBJECT, gnc_druid_provider_desc_class_init, NULL,
+                       gnc_druid_provider_desc_get_type)
 
 static void
 gnc_druid_provider_desc_class_init (GNCDruidProviderDescClass *klass)
 {
-  GObjectClass *object_class;
-	
-  object_class = G_OBJECT_CLASS (klass);
-  parent_class = g_type_class_peek_parent (klass);
+    GObjectClass *object_class;
 
-  object_class->finalize = gnc_druid_provider_desc_finalize;
+    object_class = G_OBJECT_CLASS (klass);
+    parent_class = g_type_class_peek_parent (klass);
+
+    object_class->finalize = gnc_druid_provider_desc_finalize;
 }
 
 static void
 gnc_druid_provider_desc_finalize (GObject *obj)
 {
-  GNCDruidProviderDesc *desc = (GNCDruidProviderDesc *)obj;
+    GNCDruidProviderDesc *desc = (GNCDruidProviderDesc *)obj;
 
-  if (desc->title)
-    g_free(desc->title);
+    if (desc->title)
+        g_free(desc->title);
 
-  G_OBJECT_CLASS (parent_class)->finalize(obj);
+    G_OBJECT_CLASS (parent_class)->finalize(obj);
 }
 
 void
 gnc_druid_provider_desc_set_title(GNCDruidProviderDesc* desc, const gchar* title)
 {
-  g_return_if_fail(desc);
-  g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC(desc));
-  g_return_if_fail(title);
+    g_return_if_fail(desc);
+    g_return_if_fail(IS_GNC_DRUID_PROVIDER_DESC(desc));
+    g_return_if_fail(title);
 
-  if (desc->title)
-    g_free(desc->title);
-  desc->title = g_strdup(title);
+    if (desc->title)
+        g_free(desc->title);
+    desc->title = g_strdup(title);
 }

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider-desc.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider-desc.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider-desc.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -44,22 +44,22 @@
 
 struct _GNCDruidProviderDesc
 {
-  GObject obj;
-  const gchar *name;		/* the (system-provided)name of this provider */
-  gchar *title;			/* the (user-supplied) druid page title */
+    GObject obj;
+    const gchar *name;		/* the (system-provided)name of this provider */
+    gchar *title;			/* the (user-supplied) druid page title */
 
-  /* Some providers require these, but not all. */
-  GNCDruidProviderCB	next_cb;
-  GNCDruidProviderCB	prev_cb;
-  GNCDruidProviderCB	provider_needed;
+    /* Some providers require these, but not all. */
+    GNCDruidProviderCB	next_cb;
+    GNCDruidProviderCB	prev_cb;
+    GNCDruidProviderCB	provider_needed;
 
-  /* The following are set internally for use by the backend */
-  GNCDruidProvider *	provider; /* a pointer to the provider */
+    /* The following are set internally for use by the backend */
+    GNCDruidProvider *	provider; /* a pointer to the provider */
 };
 
 struct _GNCDruidProviderDescClass
 {
-  GObjectClass obj;
+    GObjectClass obj;
 };
 
 GType	gnc_druid_provider_desc_get_type(void);

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider-file-cb.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider-file-cb.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider-file-cb.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -22,6 +22,6 @@
 #include "gnc-basic-gobject.h"
 
 GNC_BASIC_GOBJECT(GNCDruidProviderFileCB, GNCDruidProviderFileCBClass,
-		  G_TYPE_GNC_DRUID_CB, NULL, NULL,
-		  gnc_druid_provider_file_cb_get_type,
-		  gnc_druid_provider_file_cb_new)
+                  G_TYPE_GNC_DRUID_CB, NULL, NULL,
+                  gnc_druid_provider_file_cb_get_type,
+                  gnc_druid_provider_file_cb_new)

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider-file-cb.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider-file-cb.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider-file-cb.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -40,16 +40,16 @@
 
 struct _GNCDruidProviderFileCB
 {
-  GNCDruidCB parent;
+    GNCDruidCB parent;
 
-  const gchar* filename;	/* owned by the provider */
+    const gchar* filename;	/* owned by the provider */
 
-  gpointer this_file;		/* set by the backend (return to the provider) */
+    gpointer this_file;		/* set by the backend (return to the provider) */
 };
 
 struct _GNCDruidProviderFileCBClass
 {
-  GNCDruidCBClass parent_class;
+    GNCDruidCBClass parent_class;
 };
 
 GType	gnc_druid_provider_file_cb_get_type(void);

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -30,120 +30,122 @@
 static GHashTable *typeTable = NULL;
 
 GNC_BASIC_GOBJECT_TYPE(GNCDruidProvider, GNCDruidProviderClass,
-		       G_TYPE_OBJECT, gnc_druid_provider_class_init, NULL,
-		       gnc_druid_provider_get_type)
+                       G_TYPE_OBJECT, gnc_druid_provider_class_init, NULL,
+                       gnc_druid_provider_get_type)
 
 static void
 gnc_druid_provider_class_init (GNCDruidProviderClass *klass)
 {
-  GObjectClass *object_class;
-	
-  object_class = G_OBJECT_CLASS (klass);
-  parent_class = g_type_class_peek_parent (klass);
+    GObjectClass *object_class;
 
-  object_class->finalize = gnc_druid_provider_finalize;
+    object_class = G_OBJECT_CLASS (klass);
+    parent_class = g_type_class_peek_parent (klass);
 
-  /* override methods */
-  klass->first_page = invalid_page;
-  klass->last_page = invalid_page;
-  klass->next_page = null_page;
-  klass->prev_page = null_page;
+    object_class->finalize = gnc_druid_provider_finalize;
+
+    /* override methods */
+    klass->first_page = invalid_page;
+    klass->last_page = invalid_page;
+    klass->next_page = null_page;
+    klass->prev_page = null_page;
 }
 
 static void
 gnc_druid_provider_finalize (GObject *obj)
 {
-  GNCDruidProvider *provider = (GNCDruidProvider *)obj;
+    GNCDruidProvider *provider = (GNCDruidProvider *)obj;
 
-  /* Destroy the page list */
-  g_list_free(provider->pages);
+    /* Destroy the page list */
+    g_list_free(provider->pages);
 
-  /* Destroy the provider descriptor */
-  g_object_unref(G_OBJECT(provider->desc));
+    /* Destroy the provider descriptor */
+    g_object_unref(G_OBJECT(provider->desc));
 
-  G_OBJECT_CLASS (parent_class)->finalize(obj);
+    G_OBJECT_CLASS (parent_class)->finalize(obj);
 }
 
 static GNCDruidPage*
 invalid_page(GNCDruidProvider* provider)
 {
-  g_warning("Provider without a valid first/last page method");
-  return NULL;
+    g_warning("Provider without a valid first/last page method");
+    return NULL;
 }
 
 static GNCDruidPage*
 null_page(GNCDruidProvider* provider)
 {
-  return NULL;
+    return NULL;
 }
 
 static GHashTable*
 find_or_make_table(GHashTable* table, const gchar *str)
 {
-  GHashTable *ret;
+    GHashTable *ret;
 
-  g_return_val_if_fail(table, NULL);
-  g_return_val_if_fail(str, NULL);
+    g_return_val_if_fail(table, NULL);
+    g_return_val_if_fail(str, NULL);
 
-  ret = g_hash_table_lookup(table, str);
-  if (!ret) {
-    ret = g_hash_table_new(g_str_hash, g_str_equal);
-    g_hash_table_insert(table, (gpointer)str, ret);
-  }
-  return ret;
+    ret = g_hash_table_lookup(table, str);
+    if (!ret)
+    {
+        ret = g_hash_table_new(g_str_hash, g_str_equal);
+        g_hash_table_insert(table, (gpointer)str, ret);
+    }
+    return ret;
 }
 
 void
 gnc_druid_provider_register(const gchar* ui_type, const gchar* name,
-			    GNCDruidProviderNew new_provider)
+                            GNCDruidProviderNew new_provider)
 {
-  GHashTable *table;
+    GHashTable *table;
 
-  g_return_if_fail(ui_type);
-  g_return_if_fail(name);
-  g_return_if_fail(new_provider);
+    g_return_if_fail(ui_type);
+    g_return_if_fail(name);
+    g_return_if_fail(new_provider);
 
-  if (!typeTable)
-    typeTable = g_hash_table_new(g_str_hash, g_str_equal);
+    if (!typeTable)
+        typeTable = g_hash_table_new(g_str_hash, g_str_equal);
 
-  table = find_or_make_table(typeTable, ui_type);
-  g_return_if_fail(table);
+    table = find_or_make_table(typeTable, ui_type);
+    g_return_if_fail(table);
 
-  g_hash_table_insert(table, (gpointer)name, new_provider);  
+    g_hash_table_insert(table, (gpointer)name, new_provider);
 }
 
 GNCDruidProvider* gnc_druid_provider_new(GNCDruid* druid_ctx,
-					 GNCDruidProviderDesc* desc)
+        GNCDruidProviderDesc* desc)
 {
-  GHashTable *table;
-  GNCDruidProviderNew new_provider;
-  GNCDruidProvider *provider;
+    GHashTable *table;
+    GNCDruidProviderNew new_provider;
+    GNCDruidProvider *provider;
 
-  g_return_val_if_fail(desc, NULL);
-  g_return_val_if_fail(IS_GNC_DRUID_PROVIDER_DESC(desc), NULL);
-  g_return_val_if_fail(druid_ctx, NULL);
-  g_return_val_if_fail(IS_GNC_DRUID(druid_ctx), NULL);
-  g_return_val_if_fail(typeTable, NULL);
-  g_return_val_if_fail(desc->name, NULL);
-  g_return_val_if_fail(!desc->provider, NULL);
+    g_return_val_if_fail(desc, NULL);
+    g_return_val_if_fail(IS_GNC_DRUID_PROVIDER_DESC(desc), NULL);
+    g_return_val_if_fail(druid_ctx, NULL);
+    g_return_val_if_fail(IS_GNC_DRUID(druid_ctx), NULL);
+    g_return_val_if_fail(typeTable, NULL);
+    g_return_val_if_fail(desc->name, NULL);
+    g_return_val_if_fail(!desc->provider, NULL);
 
-  /* Lookup the UI Type provider table */
-  table = g_hash_table_lookup(typeTable, druid_ctx->ui_type);
-  g_return_val_if_fail(table, NULL);
+    /* Lookup the UI Type provider table */
+    table = g_hash_table_lookup(typeTable, druid_ctx->ui_type);
+    g_return_val_if_fail(table, NULL);
 
-  /* Now look up the actual provider creator for this provider type */
-  new_provider = g_hash_table_lookup(table, desc->name);
-  g_return_val_if_fail(new_provider, NULL);
+    /* Now look up the actual provider creator for this provider type */
+    new_provider = g_hash_table_lookup(table, desc->name);
+    g_return_val_if_fail(new_provider, NULL);
 
-  /* Create the new provider, then set the local parameters */
-  provider = new_provider(druid_ctx, desc);
-  if (provider) {
-    provider->druid = druid_ctx;
-    provider->desc = desc;
-    desc->provider = provider;
-  }
+    /* Create the new provider, then set the local parameters */
+    provider = new_provider(druid_ctx, desc);
+    if (provider)
+    {
+        provider->druid = druid_ctx;
+        provider->desc = desc;
+        desc->provider = provider;
+    }
 
-  return provider;
+    return provider;
 }
 
 /* methods */
@@ -151,44 +153,44 @@
 GNCDruidPage*
 gnc_druid_provider_first_page(GNCDruidProvider* provider)
 {
-  g_return_val_if_fail(provider, NULL);
-  g_return_val_if_fail(IS_GNC_DRUID_PROVIDER(provider), NULL);
+    g_return_val_if_fail(provider, NULL);
+    g_return_val_if_fail(IS_GNC_DRUID_PROVIDER(provider), NULL);
 
-  return ((GNC_DRUID_PROVIDER_GET_CLASS(provider))->first_page)(provider);
+    return ((GNC_DRUID_PROVIDER_GET_CLASS(provider))->first_page)(provider);
 }
 
 GNCDruidPage*
 gnc_druid_provider_last_page(GNCDruidProvider* provider)
 {
-  g_return_val_if_fail(provider, NULL);
-  g_return_val_if_fail(IS_GNC_DRUID_PROVIDER(provider), NULL);
+    g_return_val_if_fail(provider, NULL);
+    g_return_val_if_fail(IS_GNC_DRUID_PROVIDER(provider), NULL);
 
-  return ((GNC_DRUID_PROVIDER_GET_CLASS(provider))->last_page)(provider);
+    return ((GNC_DRUID_PROVIDER_GET_CLASS(provider))->last_page)(provider);
 }
 
 GNCDruidPage*
 gnc_druid_provider_next_page(GNCDruidProvider* provider)
 {
-  g_return_val_if_fail(provider, NULL);
-  g_return_val_if_fail(IS_GNC_DRUID_PROVIDER(provider), NULL);
+    g_return_val_if_fail(provider, NULL);
+    g_return_val_if_fail(IS_GNC_DRUID_PROVIDER(provider), NULL);
 
-  return ((GNC_DRUID_PROVIDER_GET_CLASS(provider))->next_page)(provider);
+    return ((GNC_DRUID_PROVIDER_GET_CLASS(provider))->next_page)(provider);
 }
 
 GNCDruidPage*
 gnc_druid_provider_prev_page(GNCDruidProvider* provider)
 {
-  g_return_val_if_fail(provider, NULL);
-  g_return_val_if_fail(IS_GNC_DRUID_PROVIDER(provider), NULL);
+    g_return_val_if_fail(provider, NULL);
+    g_return_val_if_fail(IS_GNC_DRUID_PROVIDER(provider), NULL);
 
-  return ((GNC_DRUID_PROVIDER_GET_CLASS(provider))->prev_page)(provider);
+    return ((GNC_DRUID_PROVIDER_GET_CLASS(provider))->prev_page)(provider);
 }
 
 GList*
 gnc_druid_provider_get_pages(GNCDruidProvider* provider)
 {
-  g_return_val_if_fail(provider, NULL);
-  g_return_val_if_fail(IS_GNC_DRUID_PROVIDER(provider), NULL);
+    g_return_val_if_fail(provider, NULL);
+    g_return_val_if_fail(IS_GNC_DRUID_PROVIDER(provider), NULL);
 
-  return provider->pages;
+    return provider->pages;
 }

Modified: gnucash/trunk/src/app-utils/gnc-druid-provider.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid-provider.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid-provider.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -42,38 +42,38 @@
 
 struct _GNCDruidProvider
 {
-  GObject obj;
+    GObject obj;
 
-  GNCDruid *druid;		/* The druid this object belongs to,
+    GNCDruid *druid;		/* The druid this object belongs to,
 				 * inserted by this class. */
-  GNCDruidProviderDesc *desc;	/* The description for this provider.
+    GNCDruidProviderDesc *desc;	/* The description for this provider.
 				 * inserted by this class,
 				 * destroyed at finalize() */
-  GList *pages;			/* list of ALL druid pages created by the
+    GList *pages;			/* list of ALL druid pages created by the
 				 * subclass. destroyed at finalize() */
-  GNCDruidPage* page;		/* The current page, used for reference */
+    GNCDruidPage* page;		/* The current page, used for reference */
 };
 
 struct _GNCDruidProviderClass
 {
-  GObjectClass parent_class;
+    GObjectClass parent_class;
 
-  /* virtual methods */
+    /* virtual methods */
 
-  GNCDruidPage* (*first_page)(GNCDruidProvider*);
-  GNCDruidPage* (*last_page)(GNCDruidProvider*);
-  GNCDruidPage* (*next_page)(GNCDruidProvider*);
-  GNCDruidPage* (*prev_page)(GNCDruidProvider*);
+    GNCDruidPage* (*first_page)(GNCDruidProvider*);
+    GNCDruidPage* (*last_page)(GNCDruidProvider*);
+    GNCDruidPage* (*next_page)(GNCDruidProvider*);
+    GNCDruidPage* (*prev_page)(GNCDruidProvider*);
 };
 
 GType	gnc_druid_provider_get_type(void);
 GNCDruidProvider* gnc_druid_provider_new(GNCDruid* druid,
-					 GNCDruidProviderDesc* desc);
+        GNCDruidProviderDesc* desc);
 
 
 typedef GNCDruidProvider* (*GNCDruidProviderNew)(GNCDruid*, GNCDruidProviderDesc*);
 void	gnc_druid_provider_register(const gchar* ui_type, const gchar* name,
-				    GNCDruidProviderNew new_provider);
+                                 GNCDruidProviderNew new_provider);
 
 /* methods */
 

Modified: gnucash/trunk/src/app-utils/gnc-druid.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -30,73 +30,75 @@
 GType
 gnc_druid_get_type (void)
 {
-  static GType type = 0;
+    static GType type = 0;
 
-  if (type == 0) {
-    GTypeInfo type_info = {
-      sizeof (GNCDruidClass),
-      NULL,
-      NULL,
-      (GClassInitFunc)gnc_druid_class_init,
-      NULL,
-      NULL,
-      sizeof (GNCDruid),
-      0,
-      NULL,
-    };
-		
-    type = g_type_register_static (G_TYPE_OBJECT, "GNCDruid", &type_info, 0);
-  }
-  
-  return type;
+    if (type == 0)
+    {
+        GTypeInfo type_info =
+        {
+            sizeof (GNCDruidClass),
+            NULL,
+            NULL,
+            (GClassInitFunc)gnc_druid_class_init,
+            NULL,
+            NULL,
+            sizeof (GNCDruid),
+            0,
+            NULL,
+        };
+
+        type = g_type_register_static (G_TYPE_OBJECT, "GNCDruid", &type_info, 0);
+    }
+
+    return type;
 }
 
 static void
 gnc_druid_class_init (GNCDruidClass *klass)
 {
-  GObjectClass *object_class;
-	
-  object_class = G_OBJECT_CLASS (klass);
-  parent_class = g_type_class_peek_parent (klass);
+    GObjectClass *object_class;
 
-  object_class->finalize = gnc_druid_finalize;
+    object_class = G_OBJECT_CLASS (klass);
+    parent_class = g_type_class_peek_parent (klass);
 
-  /* override methods */
-  klass->set_page = invalid_setpage;
+    object_class->finalize = gnc_druid_finalize;
+
+    /* override methods */
+    klass->set_page = invalid_setpage;
 }
 
 static void
 gnc_druid_finalize (GObject *obj)
 {
-  GNCDruid *druid = (GNCDruid *)obj;
-  GList *node;
+    GNCDruid *druid = (GNCDruid *)obj;
+    GList *node;
 
-  /* Cancel the backend context */
-  if (druid->cancel)
-    (druid->cancel)(druid->be_ctx);
+    /* Cancel the backend context */
+    if (druid->cancel)
+        (druid->cancel)(druid->be_ctx);
 
-  /* Destroy list of providers */
-  for (node = druid->providers; node; node = node->next)
-    g_object_unref(G_OBJECT(node->data));
-  g_list_free(druid->providers);
+    /* Destroy list of providers */
+    for (node = druid->providers; node; node = node->next)
+        g_object_unref(G_OBJECT(node->data));
+    g_list_free(druid->providers);
 
-  G_OBJECT_CLASS (parent_class)->finalize(obj);
+    G_OBJECT_CLASS (parent_class)->finalize(obj);
 }
 
 static void invalid_setpage(GNCDruid* druid, GNCDruidPage* page)
 {
-  g_warning("druid with invalid set-page");
-  return;
+    g_warning("druid with invalid set-page");
+    return;
 }
 
 void
 gnc_druid_register_ui(const gchar* ui_type, GNCDruidNew new_druid)
 {
-  g_return_if_fail(ui_type);
-  g_return_if_fail(new_druid);
-  g_return_if_fail(!new_druid_fcn);
+    g_return_if_fail(ui_type);
+    g_return_if_fail(new_druid);
+    g_return_if_fail(!new_druid_fcn);
 
-  new_druid_fcn = new_druid;
+    new_druid_fcn = new_druid;
 }
 
 /* methods */
@@ -104,159 +106,170 @@
 void
 gnc_druid_set_page(GNCDruid* druid, GNCDruidPage* page)
 {
-  g_return_if_fail(druid);
-  g_return_if_fail(IS_GNC_DRUID(druid));
+    g_return_if_fail(druid);
+    g_return_if_fail(IS_GNC_DRUID(druid));
 
-  ((GNC_DRUID_GET_CLASS(druid))->set_page)(druid, page);
+    ((GNC_DRUID_GET_CLASS(druid))->set_page)(druid, page);
 }
 
 static GNCDruidProvider*
 gnc_druid_set_provider_node(GNCDruid* druid, GList *node)
 {
-  druid->this_provider = node;
-  druid->provider = (node ? node->data : NULL);
-  return druid->provider;
+    druid->this_provider = node;
+    druid->provider = (node ? node->data : NULL);
+    return druid->provider;
 }
 
 GNCDruidProvider*
 gnc_druid_next_provider(GNCDruid* druid)
 {
-  GList *node;
+    GList *node;
 
-  g_return_val_if_fail(druid, NULL);
-  g_return_val_if_fail(IS_GNC_DRUID(druid), NULL);
+    g_return_val_if_fail(druid, NULL);
+    g_return_val_if_fail(IS_GNC_DRUID(druid), NULL);
 
-  if (!druid->this_provider) {
-    node = druid->providers;
-  } else {
-    node = druid->this_provider->next;
-  }
+    if (!druid->this_provider)
+    {
+        node = druid->providers;
+    }
+    else
+    {
+        node = druid->this_provider->next;
+    }
 
-  return gnc_druid_set_provider_node(druid, node);
+    return gnc_druid_set_provider_node(druid, node);
 }
 
 GNCDruidProvider*
 gnc_druid_prev_provider(GNCDruid* druid)
 {
-  GList *node;
+    GList *node;
 
-  g_return_val_if_fail(druid, NULL);
-  g_return_val_if_fail(IS_GNC_DRUID(druid), NULL);
+    g_return_val_if_fail(druid, NULL);
+    g_return_val_if_fail(IS_GNC_DRUID(druid), NULL);
 
-  if (!druid->provider) {
-    node = g_list_last(druid->providers);
-  } else {
-    node = druid->this_provider->prev;
-  }
+    if (!druid->provider)
+    {
+        node = g_list_last(druid->providers);
+    }
+    else
+    {
+        node = druid->this_provider->prev;
+    }
 
-  return gnc_druid_set_provider_node(druid, node);
+    return gnc_druid_set_provider_node(druid, node);
 }
 
 
 static void
 gnc_druid_change_page(GNCDruid *druid,
-		      GNCDruidProvider* (*next_prov)(GNCDruid*),
-		      GNCDruidPage* (*first_page)(GNCDruidProvider*),
-		      GNCDruidPage* (*next_page)(GNCDruidProvider*),
-		      gboolean first)
+                      GNCDruidProvider* (*next_prov)(GNCDruid*),
+                      GNCDruidPage* (*first_page)(GNCDruidProvider*),
+                      GNCDruidPage* (*next_page)(GNCDruidProvider*),
+                      gboolean first)
 {
-  GNCDruidProvider *prov;
-  GNCDruidPage* page = NULL;
+    GNCDruidProvider *prov;
+    GNCDruidPage* page = NULL;
 
-  for (prov = druid->provider; !page; ) {
+    for (prov = druid->provider; !page; )
+    {
 
-    /* How we behave depends on whether we have a provider... 
-     * if we do not have a provider, then get the next one and
-     * try to get the first page.  If we DO have a provider, then
-     * ask for the next page.  If neither gave us a page then we
-     * should go to the next provider.  Once we get a page or if
-     * we hit the next of the provider list, we're done.
-     */
+        /* How we behave depends on whether we have a provider...
+         * if we do not have a provider, then get the next one and
+         * try to get the first page.  If we DO have a provider, then
+         * ask for the next page.  If neither gave us a page then we
+         * should go to the next provider.  Once we get a page or if
+         * we hit the next of the provider list, we're done.
+         */
 
-    if (!prov || first) {
+        if (!prov || first)
+        {
 
-      /* Nope, no provider */
-      if (!prov || !first)
-	prov = next_prov(druid);
+            /* Nope, no provider */
+            if (!prov || !first)
+                prov = next_prov(druid);
 
-      if (!prov)
-	break;
+            if (!prov)
+                break;
 
-      /* New provider -- get the first page */
-      page = first_page(prov);
+            /* New provider -- get the first page */
+            page = first_page(prov);
 
-    } else {
+        }
+        else
+        {
 
-      /* Yep, try to get the next page */
-      page = next_page(prov);
-    }
+            /* Yep, try to get the next page */
+            page = next_page(prov);
+        }
 
-    /* If we didn't get a page then we need to change providers.  If
-     * the callback didn't jump us elsewhere, then we should set prov
-     * to NULL and go to the next provider.  But if we jumped, then
-     * we'll assume the jump set the pages properly and we'll just go
-     * there.  Note that this means we cannot "jump" into ourself, but
-     * that's ok, because we could have jump returned our own page if
-     * we wanted to do that.
-     */
-    if (!page) {
-      if (druid->jump_count)
-	return;
-      prov = NULL;
+        /* If we didn't get a page then we need to change providers.  If
+         * the callback didn't jump us elsewhere, then we should set prov
+         * to NULL and go to the next provider.  But if we jumped, then
+         * we'll assume the jump set the pages properly and we'll just go
+         * there.  Note that this means we cannot "jump" into ourself, but
+         * that's ok, because we could have jump returned our own page if
+         * we wanted to do that.
+         */
+        if (!page)
+        {
+            if (druid->jump_count)
+                return;
+            prov = NULL;
+        }
     }
-  }
 
-  if (page)
-    gnc_druid_set_page(druid, page);
+    if (page)
+        gnc_druid_set_page(druid, page);
 
-  g_return_if_fail(page);
+    g_return_if_fail(page);
 }
 
 static void
 gnc_druid_next_page_internal(GNCDruid* druid, gboolean first)
 {
-  gnc_druid_change_page(druid, gnc_druid_next_provider,
-			gnc_druid_provider_first_page, gnc_druid_provider_next_page,
-			first);
+    gnc_druid_change_page(druid, gnc_druid_next_provider,
+                          gnc_druid_provider_first_page, gnc_druid_provider_next_page,
+                          first);
 }
 
 void
 gnc_druid_next_page(GNCDruid* druid)
 {
-  g_return_if_fail(druid);
-  g_return_if_fail(IS_GNC_DRUID(druid));
+    g_return_if_fail(druid);
+    g_return_if_fail(IS_GNC_DRUID(druid));
 
-  gnc_druid_next_page_internal(druid, FALSE);
+    gnc_druid_next_page_internal(druid, FALSE);
 }
 
 void
 gnc_druid_prev_page(GNCDruid* druid)
 {
-  g_return_if_fail(druid);
-  g_return_if_fail(IS_GNC_DRUID(druid));
+    g_return_if_fail(druid);
+    g_return_if_fail(IS_GNC_DRUID(druid));
 
-  gnc_druid_change_page(druid, gnc_druid_prev_provider,
-			gnc_druid_provider_last_page, gnc_druid_provider_prev_page,
-			FALSE);
+    gnc_druid_change_page(druid, gnc_druid_prev_provider,
+                          gnc_druid_provider_last_page, gnc_druid_provider_prev_page,
+                          FALSE);
 }
 
 void
 gnc_druid_jump_to_provider(GNCDruid* druid, GNCDruidProvider* prov)
 {
-  GList *node;
+    GList *node;
 
-  g_return_if_fail(druid);
-  g_return_if_fail(IS_GNC_DRUID(druid));
-  g_return_if_fail(prov);
-  g_return_if_fail(IS_GNC_DRUID_PROVIDER(prov));
+    g_return_if_fail(druid);
+    g_return_if_fail(IS_GNC_DRUID(druid));
+    g_return_if_fail(prov);
+    g_return_if_fail(IS_GNC_DRUID_PROVIDER(prov));
 
-  node = g_list_find(druid->providers, prov);
-  g_return_if_fail(node);
+    node = g_list_find(druid->providers, prov);
+    g_return_if_fail(node);
 
-  druid->jump_count++;
-  gnc_druid_set_provider_node(druid, node);
-  gnc_druid_next_page_internal(druid, TRUE);
-  druid->jump_count--;
+    druid->jump_count++;
+    gnc_druid_set_provider_node(druid, node);
+    gnc_druid_next_page_internal(druid, TRUE);
+    druid->jump_count--;
 }
 
 /* Other functions */
@@ -273,53 +286,54 @@
  * the druid and will be freed by the druid.
  */
 GNCDruid* gnc_druid_new(const gchar* title, GList *providers, gpointer backend_ctx,
-			gboolean (*finish)(gpointer be_ctx),
-			void (*cancel)(gpointer be_ctx))
+                        gboolean (*finish)(gpointer be_ctx),
+                        void (*cancel)(gpointer be_ctx))
 {
-  GNCDruid *druid;
-  GList *prov_list = NULL;
-  GList *node;
-  GNCDruidProvider *prov;
-  GNCDruidClass *gdc;
+    GNCDruid *druid;
+    GList *prov_list = NULL;
+    GList *node;
+    GNCDruidProvider *prov;
+    GNCDruidClass *gdc;
 
-  g_return_val_if_fail(title, NULL);
-  g_return_val_if_fail(providers, NULL);
-  g_return_val_if_fail(new_druid_fcn, NULL);
+    g_return_val_if_fail(title, NULL);
+    g_return_val_if_fail(providers, NULL);
+    g_return_val_if_fail(new_druid_fcn, NULL);
 
-  /* Build the druid */
-  druid = new_druid_fcn(title);
-  g_return_val_if_fail(druid, NULL);
-  g_return_val_if_fail(druid->ui_type, NULL);
+    /* Build the druid */
+    druid = new_druid_fcn(title);
+    g_return_val_if_fail(druid, NULL);
+    g_return_val_if_fail(druid->ui_type, NULL);
 
-  /* Fill in local data */
-  druid->be_ctx = backend_ctx;
-  druid->finish = finish;
-  druid->cancel = cancel;
+    /* Fill in local data */
+    druid->be_ctx = backend_ctx;
+    druid->finish = finish;
+    druid->cancel = cancel;
 
-  gdc = GNC_DRUID_GET_CLASS(druid);
-  g_return_val_if_fail(gdc->append_provider, NULL);
+    gdc = GNC_DRUID_GET_CLASS(druid);
+    g_return_val_if_fail(gdc->append_provider, NULL);
 
-  /* Now build the set of providers */
-  for (node = providers; node; node = node->next) {
-    GNCDruidProviderDesc *prov_desc = node->data;
-    
-    /* create the provider */
-    g_assert(prov_desc);
-    prov = gnc_druid_provider_new(druid, prov_desc);
-    g_assert(prov);
+    /* Now build the set of providers */
+    for (node = providers; node; node = node->next)
+    {
+        GNCDruidProviderDesc *prov_desc = node->data;
 
-    /* add the provider to the druid */
-    gdc->append_provider(druid, prov);
-    prov_list = g_list_prepend(prov_list, prov);
-  }
-  druid->providers = g_list_reverse(prov_list);
+        /* create the provider */
+        g_assert(prov_desc);
+        prov = gnc_druid_provider_new(druid, prov_desc);
+        g_assert(prov);
 
-  /* Free the list (the provider descriptions are in the providers) */
-  g_list_free(providers);
+        /* add the provider to the druid */
+        gdc->append_provider(druid, prov);
+        prov_list = g_list_prepend(prov_list, prov);
+    }
+    druid->providers = g_list_reverse(prov_list);
 
-  /* Set the first page of the druid */
-  gnc_druid_next_page(druid);
+    /* Free the list (the provider descriptions are in the providers) */
+    g_list_free(providers);
 
-  /* And return the new druid. */
-  return druid;
+    /* Set the first page of the druid */
+    gnc_druid_next_page(druid);
+
+    /* And return the new druid. */
+    return druid;
 }

Modified: gnucash/trunk/src/app-utils/gnc-druid.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-druid.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-druid.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -44,31 +44,31 @@
 
 struct _GNCDruid
 {
-  GObject obj;
+    GObject obj;
 
-  /* PROVIDED BY TOOLKIT IMPLEMENTATION... */
-  const gchar *ui_type;
+    /* PROVIDED BY TOOLKIT IMPLEMENTATION... */
+    const gchar *ui_type;
 
-  /* PROVIDED HEREIN */
-  GList *providers;		/* list of GNCProvider*; list is owned herein */
-  GList *this_provider;		/* a pointer to the current provider */
-  GNCDruidProvider *provider;	/* current provider */
+    /* PROVIDED HEREIN */
+    GList *providers;		/* list of GNCProvider*; list is owned herein */
+    GList *this_provider;		/* a pointer to the current provider */
+    GNCDruidProvider *provider;	/* current provider */
 
-  /* Backend information */
-  gpointer be_ctx;		/* backend context pointer */
-  gboolean (*finish)(gpointer);	/* backend 'finish process' pointer */
-  void (*cancel)(gpointer);	/* backend 'cancel process' pointer */
+    /* Backend information */
+    gpointer be_ctx;		/* backend context pointer */
+    gboolean (*finish)(gpointer);	/* backend 'finish process' pointer */
+    void (*cancel)(gpointer);	/* backend 'cancel process' pointer */
 
-  gint jump_count;
+    gint jump_count;
 };
 
 struct _GNCDruidClass
 {
-  GObjectClass parent_class;
+    GObjectClass parent_class;
 
-  /* virtual methods */
-  void	(*set_page)(GNCDruid*, GNCDruidPage*);
-  void	(*append_provider)(GNCDruid*, GNCDruidProvider*);
+    /* virtual methods */
+    void	(*set_page)(GNCDruid*, GNCDruidPage*);
+    void	(*append_provider)(GNCDruid*, GNCDruidProvider*);
 };
 
 GType	gnc_druid_get_type(void);
@@ -102,9 +102,9 @@
  * the druid and will be freed by the druid.
  */
 GNCDruid* gnc_druid_new(const gchar* title,
-			GList *providers, gpointer backend_ctx,
-			gboolean (*finish)(gpointer be_ctx),
-			void (*cancel)(gpointer be_ctx));
+                        GList *providers, gpointer backend_ctx,
+                        gboolean (*finish)(gpointer be_ctx),
+                        void (*cancel)(gpointer be_ctx));
 
 #ifdef __cplusplus
 //}

Modified: gnucash/trunk/src/app-utils/gnc-euro.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-euro.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-euro.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -32,8 +32,8 @@
 /* local structs */
 typedef struct
 {
-  const char *currency;
-  double rate;
+    const char *currency;
+    double rate;
 } gnc_euro_rate_struct;
 
 
@@ -41,60 +41,60 @@
 /* The rates are per EURO */
 static gnc_euro_rate_struct gnc_euro_rates[] =
 {
-  { "ATS",  13.7603 },  /* austrian schilling */
-  { "BEF",  40.3399 },  /* belgian franc */
-  { "BFR",  40.3399 },  /* belgian franc */
-  { "CYP",  .585274 },  /* cyprus pound */
-  { "DEM",  1.95583 },  /* german mark */
-  { "DM",   1.95583 },  /* german mark */
-  { "ESC",  200.482 },  /* portugese escudo */
-  { "ESP",  166.386 },  /* spanish peseta */
-  { "EUR",  1.00000 },  /* euro */
-  { "EURO", 1.00000 },  /* euro */
-  { "FF",   6.55957 },  /* french franc */
-  { "FIM",  5.94573 },  /* finnmark */
-  { "FMK",  5.94573 },  /* finnmark */
-  { "FRF",  6.55957 },  /* french franc */
-  { "GRD",  340.750 },  /* greek drachma */
-  { "HFL",  2.20371 },  /* netherland gulden */
-  { "IEP",  .787564 },  /* irish pound */
-  { "IRP",  .787564 },  /* irish pound */
-  { "ITL",  1936.27 },  /* italian lira */
-  { "LFR",  40.3399 },  /* luxembourg franc */
-  { "LIT",  1936.27 },  /* italian lira */
-  { "LUF",  40.3399 },  /* luxembourg franc */
-  { "MTL",  .429300 },  /* maltese lira */
-  { "NLG",  2.20371 },  /* netherland gulden */
-  { "PTA",  166.386 },  /* spanish peseta */
-  { "PTE",  200.482 },  /* portugese escudo */
-  { "S",    13.7603 },  /* austrian schilling */
-  { "SCH",  13.7603 },  /* austrian schilling */
-  { "SIT",  239.640 },  /* slovenian tolar */
-  { "SKK",  30.1260 }   /* slovak koruna */
+    { "ATS",  13.7603 },  /* austrian schilling */
+    { "BEF",  40.3399 },  /* belgian franc */
+    { "BFR",  40.3399 },  /* belgian franc */
+    { "CYP",  .585274 },  /* cyprus pound */
+    { "DEM",  1.95583 },  /* german mark */
+    { "DM",   1.95583 },  /* german mark */
+    { "ESC",  200.482 },  /* portugese escudo */
+    { "ESP",  166.386 },  /* spanish peseta */
+    { "EUR",  1.00000 },  /* euro */
+    { "EURO", 1.00000 },  /* euro */
+    { "FF",   6.55957 },  /* french franc */
+    { "FIM",  5.94573 },  /* finnmark */
+    { "FMK",  5.94573 },  /* finnmark */
+    { "FRF",  6.55957 },  /* french franc */
+    { "GRD",  340.750 },  /* greek drachma */
+    { "HFL",  2.20371 },  /* netherland gulden */
+    { "IEP",  .787564 },  /* irish pound */
+    { "IRP",  .787564 },  /* irish pound */
+    { "ITL",  1936.27 },  /* italian lira */
+    { "LFR",  40.3399 },  /* luxembourg franc */
+    { "LIT",  1936.27 },  /* italian lira */
+    { "LUF",  40.3399 },  /* luxembourg franc */
+    { "MTL",  .429300 },  /* maltese lira */
+    { "NLG",  2.20371 },  /* netherland gulden */
+    { "PTA",  166.386 },  /* spanish peseta */
+    { "PTE",  200.482 },  /* portugese escudo */
+    { "S",    13.7603 },  /* austrian schilling */
+    { "SCH",  13.7603 },  /* austrian schilling */
+    { "SIT",  239.640 },  /* slovenian tolar */
+    { "SKK",  30.1260 }   /* slovak koruna */
 };
 
-static int 
+static int
 gnc_euro_rate_compare (const void * key, const void * value)
 {
-  const gnc_commodity * curr = key;
-  const gnc_euro_rate_struct * euro = value;
+    const gnc_commodity * curr = key;
+    const gnc_euro_rate_struct * euro = value;
 
-  if (!key || !value)
-    return -1;
+    if (!key || !value)
+        return -1;
 
-  return strcasecmp(gnc_commodity_get_mnemonic(curr), euro->currency);
+    return strcasecmp(gnc_commodity_get_mnemonic(curr), euro->currency);
 }
 
-static int 
+static int
 gnc_euro_rate_compare_code (const void * key, const void * value)
 {
-  const char *code = key;
-  const gnc_euro_rate_struct * euro = value;
+    const char *code = key;
+    const gnc_euro_rate_struct * euro = value;
 
-  if (!key || !value)
-    return -1;
+    if (!key || !value)
+        return -1;
 
-  return strcasecmp (code, euro->currency);
+    return strcasecmp (code, euro->currency);
 }
 
 /* ------------------------------------------------------ */
@@ -102,40 +102,40 @@
 gboolean
 gnc_is_euro_currency_code (const char *code)
 {
-  gnc_euro_rate_struct *result;
+    gnc_euro_rate_struct *result;
 
-  if (!code) return FALSE;
+    if (!code) return FALSE;
 
-  result = bsearch (code,
-                    gnc_euro_rates,
-                    sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct), 
-                    sizeof(gnc_euro_rate_struct),
-                    gnc_euro_rate_compare_code);
+    result = bsearch (code,
+                      gnc_euro_rates,
+                      sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
+                      sizeof(gnc_euro_rate_struct),
+                      gnc_euro_rate_compare_code);
 
-  return result != NULL;
+    return result != NULL;
 }
 
 gboolean
 gnc_is_euro_currency(const gnc_commodity * currency)
 {
-  gnc_euro_rate_struct *result;
+    gnc_euro_rate_struct *result;
 
-  if (currency == NULL)
-    return FALSE;
+    if (currency == NULL)
+        return FALSE;
 
-  if (!gnc_commodity_is_iso(currency))
-    return FALSE;
+    if (!gnc_commodity_is_iso(currency))
+        return FALSE;
 
-  result = bsearch(currency,
-                   gnc_euro_rates,
-                   sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct), 
-                   sizeof(gnc_euro_rate_struct),
-                   gnc_euro_rate_compare);
+    result = bsearch(currency,
+                     gnc_euro_rates,
+                     sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
+                     sizeof(gnc_euro_rate_struct),
+                     gnc_euro_rate_compare);
 
-  if (result == NULL)
-    return FALSE;
+    if (result == NULL)
+        return FALSE;
 
-  return TRUE;
+    return TRUE;
 }
 
 /* ------------------------------------------------------ */
@@ -143,34 +143,34 @@
 gnc_numeric
 gnc_convert_to_euro(const gnc_commodity * currency, gnc_numeric value)
 {
-  gnc_euro_rate_struct *result;
+    gnc_euro_rate_struct *result;
 
-  if (currency == NULL)
-    return gnc_numeric_zero ();
+    if (currency == NULL)
+        return gnc_numeric_zero ();
 
-  if (!gnc_commodity_is_iso(currency))
-    return gnc_numeric_zero ();
+    if (!gnc_commodity_is_iso(currency))
+        return gnc_numeric_zero ();
 
-  result = bsearch(currency,
-                   gnc_euro_rates,
-                   sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct), 
-                   sizeof(gnc_euro_rate_struct),
-                   gnc_euro_rate_compare);
+    result = bsearch(currency,
+                     gnc_euro_rates,
+                     sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
+                     sizeof(gnc_euro_rate_struct),
+                     gnc_euro_rate_compare);
 
-  if (result == NULL)
-    return gnc_numeric_zero ();
+    if (result == NULL)
+        return gnc_numeric_zero ();
 
-  /* round to 2 decimal places */
-  {
-    gnc_numeric rate;
+    /* round to 2 decimal places */
+    {
+        gnc_numeric rate;
 
-    rate = double_to_gnc_numeric (result->rate, 100000, GNC_RND_ROUND);
+        rate = double_to_gnc_numeric (result->rate, 100000, GNC_RND_ROUND);
 
-    /* Which rounding should be used here? H. Thoma said
-       GNC_RND_FLOOR, but I (cstim) think he's wrong -- the official
-       rules say you *have* to use GNC_RND_ROUND! */
-    return gnc_numeric_div (value, rate, 100, GNC_RND_ROUND);
-  }
+        /* Which rounding should be used here? H. Thoma said
+           GNC_RND_FLOOR, but I (cstim) think he's wrong -- the official
+           rules say you *have* to use GNC_RND_ROUND! */
+        return gnc_numeric_div (value, rate, 100, GNC_RND_ROUND);
+    }
 }
 
 /* ------------------------------------------------------ */
@@ -178,31 +178,31 @@
 gnc_numeric
 gnc_convert_from_euro(const gnc_commodity * currency, gnc_numeric value)
 {
-  gnc_euro_rate_struct * result;
+    gnc_euro_rate_struct * result;
 
-  if (currency == NULL)
-    return gnc_numeric_zero ();
+    if (currency == NULL)
+        return gnc_numeric_zero ();
 
-  if (!gnc_commodity_is_iso(currency))
-    return gnc_numeric_zero ();
+    if (!gnc_commodity_is_iso(currency))
+        return gnc_numeric_zero ();
 
-  result = bsearch(currency,
-                   gnc_euro_rates,
-                   sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct), 
-                   sizeof(gnc_euro_rate_struct),
-                   gnc_euro_rate_compare);
+    result = bsearch(currency,
+                     gnc_euro_rates,
+                     sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
+                     sizeof(gnc_euro_rate_struct),
+                     gnc_euro_rate_compare);
 
-  if (result == NULL)
-    return gnc_numeric_zero ();
+    if (result == NULL)
+        return gnc_numeric_zero ();
 
-  {
-    gnc_numeric rate;
+    {
+        gnc_numeric rate;
 
-    rate = double_to_gnc_numeric (result->rate, 100000, GNC_RND_ROUND);
+        rate = double_to_gnc_numeric (result->rate, 100000, GNC_RND_ROUND);
 
-    return gnc_numeric_mul (value, rate, gnc_commodity_get_fraction (currency),
-                            GNC_RND_ROUND);
-  }
+        return gnc_numeric_mul (value, rate, gnc_commodity_get_fraction (currency),
+                                GNC_RND_ROUND);
+    }
 }
 
 /* ------------------------------------------------------ */
@@ -210,25 +210,25 @@
 gnc_numeric
 gnc_euro_currency_get_rate (const gnc_commodity *currency)
 {
-  gnc_euro_rate_struct * result;
+    gnc_euro_rate_struct * result;
 
-  if (currency == NULL)
-    return gnc_numeric_zero ();
+    if (currency == NULL)
+        return gnc_numeric_zero ();
 
-  if (!gnc_commodity_is_iso(currency))
-    return gnc_numeric_zero ();
+    if (!gnc_commodity_is_iso(currency))
+        return gnc_numeric_zero ();
 
-  result = bsearch(currency,
-                   gnc_euro_rates,
-                   sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct), 
-                   sizeof(gnc_euro_rate_struct),
-                   gnc_euro_rate_compare);
+    result = bsearch(currency,
+                     gnc_euro_rates,
+                     sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
+                     sizeof(gnc_euro_rate_struct),
+                     gnc_euro_rate_compare);
 
-  if (result == NULL)
-    return gnc_numeric_zero ();
+    if (result == NULL)
+        return gnc_numeric_zero ();
 
-  return double_to_gnc_numeric (result->rate, GNC_DENOM_AUTO, 
-                                GNC_DENOM_SIGFIGS(6) | GNC_RND_ROUND);
+    return double_to_gnc_numeric (result->rate, GNC_DENOM_AUTO,
+                                  GNC_DENOM_SIGFIGS(6) | GNC_RND_ROUND);
 }
 
 /* ------------------------------------------------------ */
@@ -236,9 +236,9 @@
 gnc_commodity *
 gnc_get_euro (void)
 {
-  gnc_commodity_table *table;
+    gnc_commodity_table *table;
 
-  table = gnc_book_get_commodity_table (gnc_get_current_book ());
+    table = gnc_book_get_commodity_table (gnc_get_current_book ());
 
-  return gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_CURRENCY, "EUR");
+    return gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_CURRENCY, "EUR");
 }

Modified: gnucash/trunk/src/app-utils/gnc-exp-parser.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-exp-parser.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-exp-parser.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -44,7 +44,7 @@
 
 typedef struct ParserNum
 {
-  gnc_numeric value;
+    gnc_numeric value;
 } ParserNum;
 
 
@@ -60,335 +60,342 @@
 static gchar *
 gnc_exp_parser_filname (void)
 {
-  return gnc_build_dotgnucash_path("expressions-2.0");
+    return gnc_build_dotgnucash_path("expressions-2.0");
 }
 
 void
 gnc_exp_parser_init ( void )
 {
-  gnc_exp_parser_real_init( TRUE );
+    gnc_exp_parser_real_init( TRUE );
 }
 
 void
 gnc_exp_parser_real_init ( gboolean addPredefined )
 {
-  gchar *filename, **keys, **key, *str_value;
-  GKeyFile *key_file;
-  gnc_numeric value;
+    gchar *filename, **keys, **key, *str_value;
+    GKeyFile *key_file;
+    gnc_numeric value;
 
-  if (parser_inited)
-    gnc_exp_parser_shutdown ();
+    if (parser_inited)
+        gnc_exp_parser_shutdown ();
 
-  variable_bindings = g_hash_table_new (g_str_hash, g_str_equal);
+    variable_bindings = g_hash_table_new (g_str_hash, g_str_equal);
 
-  /* This comes after the statics have been initialized. Not at the end! */
-  parser_inited = TRUE;
+    /* This comes after the statics have been initialized. Not at the end! */
+    parser_inited = TRUE;
 
-  if ( addPredefined ) {
-    filename = gnc_exp_parser_filname();
-    key_file = gnc_key_file_load_from_file(filename, TRUE, FALSE, NULL);
-    if (key_file) {
-      keys = g_key_file_get_keys(key_file, GROUP_NAME, NULL, NULL);
-      for (key = keys; key && *key; key++) {
-	str_value = g_key_file_get_string(key_file, GROUP_NAME, *key, NULL);
-	if (str_value && string_to_gnc_numeric(str_value, &value)) {
-	  gnc_exp_parser_set_value (*key, gnc_numeric_reduce (value));
-	}
-      } 
-      g_strfreev(keys);
-      g_key_file_free(key_file);
+    if ( addPredefined )
+    {
+        filename = gnc_exp_parser_filname();
+        key_file = gnc_key_file_load_from_file(filename, TRUE, FALSE, NULL);
+        if (key_file)
+        {
+            keys = g_key_file_get_keys(key_file, GROUP_NAME, NULL, NULL);
+            for (key = keys; key && *key; key++)
+            {
+                str_value = g_key_file_get_string(key_file, GROUP_NAME, *key, NULL);
+                if (str_value && string_to_gnc_numeric(str_value, &value))
+                {
+                    gnc_exp_parser_set_value (*key, gnc_numeric_reduce (value));
+                }
+            }
+            g_strfreev(keys);
+            g_key_file_free(key_file);
+        }
+        g_free(filename);
     }
-    g_free(filename);
-  }
 }
 
 static gboolean
 remove_binding (gpointer key, gpointer value, gpointer not_used)
 {
-  g_free(key);
-  g_free(value);
+    g_free(key);
+    g_free(value);
 
-  return TRUE;
+    return TRUE;
 }
 
 static void
 set_one_key (gpointer key, gpointer value, gpointer data)
 {
-  char *name = key;
-  ParserNum *pnum = value;
-  char *num_str;
+    char *name = key;
+    ParserNum *pnum = value;
+    char *num_str;
 
-  num_str = gnc_numeric_to_string (gnc_numeric_reduce (pnum->value));
-  g_key_file_set_string ((GKeyFile *)data, GROUP_NAME, name, num_str);
-  g_free (num_str);
+    num_str = gnc_numeric_to_string (gnc_numeric_reduce (pnum->value));
+    g_key_file_set_string ((GKeyFile *)data, GROUP_NAME, name, num_str);
+    g_free (num_str);
 }
 
 void
 gnc_exp_parser_shutdown (void)
 {
-  GKeyFile* key_file;
-  gchar *filename;
+    GKeyFile* key_file;
+    gchar *filename;
 
-  if (!parser_inited)
-    return;
+    if (!parser_inited)
+        return;
 
-  filename = gnc_exp_parser_filname();
-  key_file = g_key_file_new();
-  g_hash_table_foreach (variable_bindings, set_one_key, key_file);
-  g_key_file_set_comment(key_file, GROUP_NAME, NULL,
-			 " Variables are in the form 'name=value'",
-			 NULL);
-  gnc_key_file_save_to_file(filename, key_file, NULL);
-  g_key_file_free(key_file);
-  g_free(filename);
+    filename = gnc_exp_parser_filname();
+    key_file = g_key_file_new();
+    g_hash_table_foreach (variable_bindings, set_one_key, key_file);
+    g_key_file_set_comment(key_file, GROUP_NAME, NULL,
+                           " Variables are in the form 'name=value'",
+                           NULL);
+    gnc_key_file_save_to_file(filename, key_file, NULL);
+    g_key_file_free(key_file);
+    g_free(filename);
 
-  g_hash_table_foreach_remove (variable_bindings, remove_binding, NULL);
-  g_hash_table_destroy (variable_bindings);
-  variable_bindings = NULL;
+    g_hash_table_foreach_remove (variable_bindings, remove_binding, NULL);
+    g_hash_table_destroy (variable_bindings);
+    variable_bindings = NULL;
 
-  last_error = PARSER_NO_ERROR;
-  last_gncp_error = NO_ERR;
+    last_error = PARSER_NO_ERROR;
+    last_gncp_error = NO_ERR;
 
-  parser_inited = FALSE;
+    parser_inited = FALSE;
 }
 
 static void
 prepend_name (gpointer key, gpointer value, gpointer data)
 {
-  GList **list = data;
+    GList **list = data;
 
-  *list = g_list_prepend (*list, key);
+    *list = g_list_prepend (*list, key);
 }
 
 GList *
 gnc_exp_parser_get_variable_names (void)
 {
-  GList *names = NULL;
+    GList *names = NULL;
 
-  if (!parser_inited)
-    return NULL;
+    if (!parser_inited)
+        return NULL;
 
-  g_hash_table_foreach (variable_bindings, prepend_name, &names);
+    g_hash_table_foreach (variable_bindings, prepend_name, &names);
 
-  return names;
+    return names;
 }
 
 void
 gnc_exp_parser_remove_variable (const char *variable_name)
 {
-  gpointer key;
-  gpointer value;
+    gpointer key;
+    gpointer value;
 
-  if (!parser_inited)
-    return;
+    if (!parser_inited)
+        return;
 
-  if (variable_name == NULL)
-    return;
+    if (variable_name == NULL)
+        return;
 
-  if (g_hash_table_lookup_extended (variable_bindings, variable_name,
-                                    &key, &value))
-  {
-    g_hash_table_remove (variable_bindings, key);
-    g_free(key);
-    g_free(value);
-  }
+    if (g_hash_table_lookup_extended (variable_bindings, variable_name,
+                                      &key, &value))
+    {
+        g_hash_table_remove (variable_bindings, key);
+        g_free(key);
+        g_free(value);
+    }
 }
 
 void
 gnc_exp_parser_remove_variable_names (GList * variable_names)
 {
-  if (!parser_inited)
-    return;
+    if (!parser_inited)
+        return;
 
-  while (variable_names != NULL)
-  {
-    gnc_exp_parser_remove_variable (variable_names->data);
-    variable_names = variable_names->next;
-  }
+    while (variable_names != NULL)
+    {
+        gnc_exp_parser_remove_variable (variable_names->data);
+        variable_names = variable_names->next;
+    }
 }
 
 gboolean
 gnc_exp_parser_get_value (const char * variable_name, gnc_numeric *value_p)
 {
-  ParserNum *pnum;
+    ParserNum *pnum;
 
-  if (!parser_inited)
-    return FALSE;
+    if (!parser_inited)
+        return FALSE;
 
-  if (variable_name == NULL)
-    return FALSE;
+    if (variable_name == NULL)
+        return FALSE;
 
-  pnum = g_hash_table_lookup (variable_bindings, variable_name);
-  if (pnum == NULL)
-    return FALSE;
+    pnum = g_hash_table_lookup (variable_bindings, variable_name);
+    if (pnum == NULL)
+        return FALSE;
 
-  if (value_p != NULL)
-    *value_p = pnum->value;
+    if (value_p != NULL)
+        *value_p = pnum->value;
 
-  return TRUE;
+    return TRUE;
 }
 
 void
 gnc_exp_parser_set_value (const char * variable_name, gnc_numeric value)
 {
-  char *key;
-  ParserNum *pnum;
+    char *key;
+    ParserNum *pnum;
 
-  if (variable_name == NULL)
-    return;
+    if (variable_name == NULL)
+        return;
 
-  if (!parser_inited)
-    gnc_exp_parser_init ();
+    if (!parser_inited)
+        gnc_exp_parser_init ();
 
-  gnc_exp_parser_remove_variable (variable_name);
+    gnc_exp_parser_remove_variable (variable_name);
 
-  key = g_strdup (variable_name);
+    key = g_strdup (variable_name);
 
-  pnum = g_new0(ParserNum, 1);
-  pnum->value = value;
+    pnum = g_new0(ParserNum, 1);
+    pnum->value = value;
 
-  g_hash_table_insert (variable_bindings, key, pnum);
+    g_hash_table_insert (variable_bindings, key, pnum);
 }
 
 static void
 make_predefined_vars_helper (gpointer key, gpointer value, gpointer data)
 {
-  var_store_ptr *vars_p = data;
-  ParserNum *pnum_old = value;
-  var_store_ptr var;
-  ParserNum *pnum;
+    var_store_ptr *vars_p = data;
+    ParserNum *pnum_old = value;
+    var_store_ptr var;
+    ParserNum *pnum;
 
-  var = g_new0 (var_store, 1);
+    var = g_new0 (var_store, 1);
 
-  pnum = g_new0 (ParserNum, 1);
-  *pnum = *pnum_old;
+    pnum = g_new0 (ParserNum, 1);
+    *pnum = *pnum_old;
 
-  var->variable_name = g_strdup(key);
-  var->value = pnum;
-  var->next_var = *vars_p;
+    var->variable_name = g_strdup(key);
+    var->value = pnum;
+    var->next_var = *vars_p;
 
-  *vars_p = var;
+    *vars_p = var;
 }
 
 static void
 make_predefined_vars_from_external_helper( gpointer key, gpointer value, gpointer data )
 {
-  ParserNum *pnum = g_new0( ParserNum, 1 );
-  if ( value != NULL )
-          pnum->value = *(gnc_numeric*)value;
+    ParserNum *pnum = g_new0( ParserNum, 1 );
+    if ( value != NULL )
+        pnum->value = *(gnc_numeric*)value;
 
-  make_predefined_vars_helper( key, pnum, data );
+    make_predefined_vars_helper( key, pnum, data );
 }
 
 static var_store_ptr
 make_predefined_variables (void)
 {
-  var_store_ptr vars = NULL;
+    var_store_ptr vars = NULL;
 
-  g_hash_table_foreach (variable_bindings, make_predefined_vars_helper, &vars);
+    g_hash_table_foreach (variable_bindings, make_predefined_vars_helper, &vars);
 
-  return vars;
+    return vars;
 }
 
 static void
 free_predefined_variables (var_store_ptr vars)
 {
-  var_store_ptr next;
+    var_store_ptr next;
 
-  while (vars != NULL)
-  {
-    next = vars->next_var;
+    while (vars != NULL)
+    {
+        next = vars->next_var;
 
-    g_free(vars->variable_name);
-    vars->variable_name = NULL;
+        g_free(vars->variable_name);
+        vars->variable_name = NULL;
 
-    g_free(vars->value);
-    vars->value = NULL;
+        g_free(vars->value);
+        vars->value = NULL;
 
-    g_free(vars);
+        g_free(vars);
 
-    vars = next;
-  }
+        vars = next;
+    }
 }
 
 static void
 update_variables (var_store_ptr vars)
 {
-  for ( ; vars ; vars = vars->next_var )
-  {
-    ParserNum *pnum = vars->value;
-    if (pnum != NULL)
-      gnc_exp_parser_set_value (vars->variable_name, pnum->value);
-  }
+    for ( ; vars ; vars = vars->next_var )
+    {
+        ParserNum *pnum = vars->value;
+        if (pnum != NULL)
+            gnc_exp_parser_set_value (vars->variable_name, pnum->value);
+    }
 }
 
 static char* _function_evaluation_error_msg = NULL;
 static void
 _exception_handler(const char *error_message)
 {
-  _function_evaluation_error_msg = (char*)error_message;
+    _function_evaluation_error_msg = (char*)error_message;
 }
 
 static
 void*
 func_op(const char *fname, int argc, void **argv)
 {
-  SCM scmFn, scmArgs, scmTmp;
-  int i;
-  var_store *vs;
-  gchar *str;
-  gnc_numeric n, *result;
-  GString *realFnName;
+    SCM scmFn, scmArgs, scmTmp;
+    int i;
+    var_store *vs;
+    gchar *str;
+    gnc_numeric n, *result;
+    GString *realFnName;
 
-  realFnName = g_string_sized_new( strlen(fname) + 5 );
-  g_string_printf( realFnName, "gnc:%s", fname );
-  scmFn = scm_internal_catch(SCM_BOOL_T,
-                     (scm_t_catch_body)scm_c_eval_string, realFnName->str,
-					 scm_handle_by_message_noexit, NULL);
-  g_string_free( realFnName, TRUE );
-  if (!SCM_PROCEDUREP(scmFn)) {
-    /* FIXME: handle errors correctly. */
-    printf( "gnc:\"%s\" is not a scm procedure\n", fname );
-    return NULL;
-  }
-  scmArgs = scm_listify( SCM_UNDEFINED );
-  for ( i=0; i<argc; i++ ) {
-    /* cons together back-to-front. */
-    vs = (var_store*)argv[argc - i - 1];
-    switch ( vs->type ) {
-    case VST_NUMERIC:
-      n = *(gnc_numeric*)(vs->value);
-      scmTmp = scm_make_real( gnc_numeric_to_double( n ) );
-      break;
-    case VST_STRING:
-      str = (char*)(vs->value);
-      scmTmp = scm_mem2string( str, strlen(str) );
-      break;
-    default:
-      /* FIXME: error */
-      printf( "argument %d not a numeric or string [type = %d]\n",
-              i, vs->type );
-      return NULL;
-      break; /* notreached */
+    realFnName = g_string_sized_new( strlen(fname) + 5 );
+    g_string_printf( realFnName, "gnc:%s", fname );
+    scmFn = scm_internal_catch(SCM_BOOL_T,
+                               (scm_t_catch_body)scm_c_eval_string, realFnName->str,
+                               scm_handle_by_message_noexit, NULL);
+    g_string_free( realFnName, TRUE );
+    if (!SCM_PROCEDUREP(scmFn))
+    {
+        /* FIXME: handle errors correctly. */
+        printf( "gnc:\"%s\" is not a scm procedure\n", fname );
+        return NULL;
     }
-    scmArgs = scm_cons( scmTmp, scmArgs );
-  }
+    scmArgs = scm_listify( SCM_UNDEFINED );
+    for ( i = 0; i < argc; i++ )
+    {
+        /* cons together back-to-front. */
+        vs = (var_store*)argv[argc - i - 1];
+        switch ( vs->type )
+        {
+        case VST_NUMERIC:
+            n = *(gnc_numeric*)(vs->value);
+            scmTmp = scm_make_real( gnc_numeric_to_double( n ) );
+            break;
+        case VST_STRING:
+            str = (char*)(vs->value);
+            scmTmp = scm_mem2string( str, strlen(str) );
+            break;
+        default:
+            /* FIXME: error */
+            printf( "argument %d not a numeric or string [type = %d]\n",
+                    i, vs->type );
+            return NULL;
+            break; /* notreached */
+        }
+        scmArgs = scm_cons( scmTmp, scmArgs );
+    }
 
-  //scmTmp = scm_apply(scmFn, scmArgs , SCM_EOL);
-  scmTmp = gfec_apply(scmFn, scmArgs, _exception_handler);
-  if (_function_evaluation_error_msg != NULL)
-  {
-    PERR("function eval error: [%s]\n", _function_evaluation_error_msg);
-    _function_evaluation_error_msg = NULL;
-    return NULL;
-  }
-    
-  result = g_new0( gnc_numeric, 1 );
-  *result = double_to_gnc_numeric( scm_num2dbl(scmTmp, G_STRFUNC),
-                                   GNC_DENOM_AUTO,
-                                   GNC_DENOM_SIGFIGS(6) | GNC_RND_ROUND );
-  /* FIXME: cleanup scmArgs = scm_list, cons'ed cells? */
-  return (void*)result;
+    //scmTmp = scm_apply(scmFn, scmArgs , SCM_EOL);
+    scmTmp = gfec_apply(scmFn, scmArgs, _exception_handler);
+    if (_function_evaluation_error_msg != NULL)
+    {
+        PERR("function eval error: [%s]\n", _function_evaluation_error_msg);
+        _function_evaluation_error_msg = NULL;
+        return NULL;
+    }
+
+    result = g_new0( gnc_numeric, 1 );
+    *result = double_to_gnc_numeric( scm_num2dbl(scmTmp, G_STRFUNC),
+                                     GNC_DENOM_AUTO,
+                                     GNC_DENOM_SIGFIGS(6) | GNC_RND_ROUND );
+    /* FIXME: cleanup scmArgs = scm_list, cons'ed cells? */
+    return (void*)result;
 }
 
 static void *
@@ -397,19 +404,19 @@
               gchar      *group_char,
               char      **rstr)
 {
-  ParserNum *pnum;
-  gnc_numeric value;
+    ParserNum *pnum;
+    gnc_numeric value;
 
-  if (digit_str == NULL)
-    return NULL;
+    if (digit_str == NULL)
+        return NULL;
 
-  if (!xaccParseAmount (digit_str, TRUE, &value, rstr))
-    return NULL;
+    if (!xaccParseAmount (digit_str, TRUE, &value, rstr))
+        return NULL;
 
-  pnum = g_new0(ParserNum, 1);
-  pnum->value = value;
+    pnum = g_new0(ParserNum, 1);
+    pnum->value = value;
 
-  return pnum;
+    return pnum;
 }
 
 static void *
@@ -417,104 +424,108 @@
             void *left_value,
             void *right_value)
 {
-  ParserNum *left = left_value;
-  ParserNum *right = right_value;
-  ParserNum *result;
+    ParserNum *left = left_value;
+    ParserNum *right = right_value;
+    ParserNum *result;
 
-  if ((left == NULL) || (right == NULL))
-    return NULL;
+    if ((left == NULL) || (right == NULL))
+        return NULL;
 
-  result = (op_sym == ASN_OP) ? left : g_new0(ParserNum, 1);
+    result = (op_sym == ASN_OP) ? left : g_new0(ParserNum, 1);
 
-  switch (op_sym)
-  {
+    switch (op_sym)
+    {
     case ADD_OP:
-      result->value = gnc_numeric_add (left->value, right->value,
-                                       GNC_DENOM_AUTO, GNC_DENOM_EXACT);
-      break;
+        result->value = gnc_numeric_add (left->value, right->value,
+                                         GNC_DENOM_AUTO, GNC_DENOM_EXACT);
+        break;
     case SUB_OP:
-      result->value = gnc_numeric_sub (left->value, right->value,
-                                       GNC_DENOM_AUTO, GNC_DENOM_EXACT);
-      break;
+        result->value = gnc_numeric_sub (left->value, right->value,
+                                         GNC_DENOM_AUTO, GNC_DENOM_EXACT);
+        break;
     case DIV_OP:
-      result->value = gnc_numeric_div (left->value, right->value,
-                                       GNC_DENOM_AUTO, GNC_DENOM_EXACT);
-      break;
+        result->value = gnc_numeric_div (left->value, right->value,
+                                         GNC_DENOM_AUTO, GNC_DENOM_EXACT);
+        break;
     case MUL_OP:
-      result->value = gnc_numeric_mul (left->value, right->value,
-                                       GNC_DENOM_AUTO, GNC_DENOM_EXACT);
-      break;
+        result->value = gnc_numeric_mul (left->value, right->value,
+                                         GNC_DENOM_AUTO, GNC_DENOM_EXACT);
+        break;
     case ASN_OP:
-      result->value = right->value;
-      break;
-  }
+        result->value = right->value;
+        break;
+    }
 
-  return result;
+    return result;
 }
 
 static void *
 negate_numeric(void *value)
 {
-  ParserNum *result = value;
+    ParserNum *result = value;
 
-  if (value == NULL)
-    return NULL;
+    if (value == NULL)
+        return NULL;
 
-  result->value = gnc_numeric_neg (result->value);
+    result->value = gnc_numeric_neg (result->value);
 
-  return result;
+    return result;
 }
 
 static
 void
 gnc_ep_tmpvarhash_check_vals( gpointer key, gpointer value, gpointer user_data )
 {
-  gboolean *allVarsHaveValues = (gboolean*)user_data;
-  gnc_numeric *num = (gnc_numeric*)value;
-  *allVarsHaveValues &= ( num && gnc_numeric_check( *num ) != GNC_ERROR_ARG );
+    gboolean *allVarsHaveValues = (gboolean*)user_data;
+    gnc_numeric *num = (gnc_numeric*)value;
+    *allVarsHaveValues &= ( num && gnc_numeric_check( *num ) != GNC_ERROR_ARG );
 }
 
 static
 void
 gnc_ep_tmpvarhash_clean( gpointer key, gpointer value, gpointer user_data )
 {
-  if ( key ) {
-    g_free( (gchar*)key );
-  }
-  if ( value ) {
-    g_free( (gnc_numeric*)value );
-  }
+    if ( key )
+    {
+        g_free( (gchar*)key );
+    }
+    if ( value )
+    {
+        g_free( (gnc_numeric*)value );
+    }
 }
 
 gboolean
 gnc_exp_parser_parse( const char * expression, gnc_numeric *value_p,
                       char **error_loc_p )
 {
-  GHashTable *tmpVarHash;
-  gboolean ret, toRet = TRUE;
-  gboolean allVarsHaveValues = TRUE;
+    GHashTable *tmpVarHash;
+    gboolean ret, toRet = TRUE;
+    gboolean allVarsHaveValues = TRUE;
 
-  tmpVarHash = g_hash_table_new( g_str_hash, g_str_equal );
-  ret = gnc_exp_parser_parse_separate_vars( expression, value_p,
-                                            error_loc_p, tmpVarHash );
-  if ( !ret ) {
-    toRet = ret;
-    goto cleanup;
-  }
+    tmpVarHash = g_hash_table_new( g_str_hash, g_str_equal );
+    ret = gnc_exp_parser_parse_separate_vars( expression, value_p,
+            error_loc_p, tmpVarHash );
+    if ( !ret )
+    {
+        toRet = ret;
+        goto cleanup;
+    }
 
-  g_hash_table_foreach( tmpVarHash,
-                        gnc_ep_tmpvarhash_check_vals,
-                        &allVarsHaveValues );
-  if ( !allVarsHaveValues ) {
-    toRet = FALSE;
-    last_gncp_error = VARIABLE_IN_EXP;
-  }
+    g_hash_table_foreach( tmpVarHash,
+                          gnc_ep_tmpvarhash_check_vals,
+                          &allVarsHaveValues );
+    if ( !allVarsHaveValues )
+    {
+        toRet = FALSE;
+        last_gncp_error = VARIABLE_IN_EXP;
+    }
 
- cleanup:
-  g_hash_table_foreach( tmpVarHash, gnc_ep_tmpvarhash_clean, NULL );
-  g_hash_table_destroy( tmpVarHash );
+cleanup:
+    g_hash_table_foreach( tmpVarHash, gnc_ep_tmpvarhash_clean, NULL );
+    g_hash_table_destroy( tmpVarHash );
 
-  return toRet;
+    return toRet;
 }
 
 gboolean
@@ -523,139 +534,149 @@
                                     char **error_loc_p,
                                     GHashTable *varHash )
 {
-  parser_env_ptr pe;
-  var_store_ptr vars;
-  struct lconv *lc;
-  var_store result;
-  char * error_loc;
-  ParserNum *pnum;
+    parser_env_ptr pe;
+    var_store_ptr vars;
+    struct lconv *lc;
+    var_store result;
+    char * error_loc;
+    ParserNum *pnum;
 
-  if (expression == NULL)
-    return FALSE;
+    if (expression == NULL)
+        return FALSE;
 
-  if (!parser_inited)
-    gnc_exp_parser_real_init ( (varHash == NULL) );
+    if (!parser_inited)
+        gnc_exp_parser_real_init ( (varHash == NULL) );
 
-  result.variable_name = NULL;
-  result.value = NULL;
-  result.next_var = NULL;
+    result.variable_name = NULL;
+    result.value = NULL;
+    result.next_var = NULL;
 
-  vars = make_predefined_variables ();
+    vars = make_predefined_variables ();
 
-  if ( varHash != NULL ) {
-    g_hash_table_foreach( varHash, make_predefined_vars_from_external_helper, &vars);
-  }
+    if ( varHash != NULL )
+    {
+        g_hash_table_foreach( varHash, make_predefined_vars_from_external_helper, &vars);
+    }
 
-  lc = gnc_localeconv ();
+    lc = gnc_localeconv ();
 
-  pe = init_parser (vars, lc->mon_decimal_point, lc->mon_thousands_sep,
-                    trans_numeric, numeric_ops, negate_numeric, g_free,
-                    func_op);
+    pe = init_parser (vars, lc->mon_decimal_point, lc->mon_thousands_sep,
+                      trans_numeric, numeric_ops, negate_numeric, g_free,
+                      func_op);
 
-  error_loc = parse_string (&result, expression, pe);
+    error_loc = parse_string (&result, expression, pe);
 
-  pnum = result.value;
+    pnum = result.value;
 
-  if (error_loc == NULL)
-  {
-    if (gnc_numeric_check (pnum->value))
+    if (error_loc == NULL)
     {
-      if (error_loc_p != NULL)
-        *error_loc_p = (char *) expression;
+        if (gnc_numeric_check (pnum->value))
+        {
+            if (error_loc_p != NULL)
+                *error_loc_p = (char *) expression;
 
-      last_error = NUMERIC_ERROR;
+            last_error = NUMERIC_ERROR;
+        }
+        else
+        {
+            if (pnum)
+            {
+                if (value_p)
+                    *value_p = gnc_numeric_reduce (pnum->value);
+
+                if (!result.variable_name)
+                    g_free (pnum);
+            }
+
+            if (error_loc_p != NULL)
+                *error_loc_p = NULL;
+
+            last_error = PARSER_NO_ERROR;
+        }
     }
     else
     {
-      if (pnum)
-      {
-        if (value_p)
-          *value_p = gnc_numeric_reduce (pnum->value);
+        if (error_loc_p != NULL)
+            *error_loc_p = error_loc;
 
-        if (!result.variable_name)
-          g_free (pnum);
-      }
-
-      if (error_loc_p != NULL)
-        *error_loc_p = NULL;
-
-      last_error = PARSER_NO_ERROR;
+        last_error = get_parse_error (pe);
     }
-  }
-  else
-  {
-    if (error_loc_p != NULL)
-      *error_loc_p = error_loc;
 
-    last_error = get_parse_error (pe);
-  }
+    if ( varHash != NULL )
+    {
+        var_store_ptr newVars;
+        gpointer maybeKey, maybeValue;
+        gnc_numeric *numericValue;
 
-  if ( varHash != NULL ) {
-      var_store_ptr newVars;
-      gpointer maybeKey, maybeValue;
-      gnc_numeric *numericValue;
-
-      newVars = parser_get_vars( pe );
-      for ( ; newVars ; newVars = newVars->next_var ) {
-        pnum = newVars->value;
-        if ( g_hash_table_lookup_extended( varHash, newVars->variable_name,
-                                           &maybeKey, &maybeValue ) ) {
-          g_hash_table_remove( varHash, maybeKey );
-          g_free( maybeKey );
-          g_free( maybeValue );
+        newVars = parser_get_vars( pe );
+        for ( ; newVars ; newVars = newVars->next_var )
+        {
+            pnum = newVars->value;
+            if ( g_hash_table_lookup_extended( varHash, newVars->variable_name,
+                                               &maybeKey, &maybeValue ) )
+            {
+                g_hash_table_remove( varHash, maybeKey );
+                g_free( maybeKey );
+                g_free( maybeValue );
+            }
+            numericValue = g_new0( gnc_numeric, 1 );
+            *numericValue = ((ParserNum*)newVars->value)->value;
+            // WTF?
+            // numericValue = NULL;
+            g_hash_table_insert( varHash,
+                                 g_strdup(newVars->variable_name),
+                                 numericValue );
         }
-        numericValue = g_new0( gnc_numeric, 1 );
-        *numericValue = ((ParserNum*)newVars->value)->value;
-        // WTF?
-        // numericValue = NULL;
-        g_hash_table_insert( varHash,
-                             g_strdup(newVars->variable_name),
-                             numericValue );
-      }
-  } else {
-    update_variables (vars);
-  }
+    }
+    else
+    {
+        update_variables (vars);
+    }
 
-  free_predefined_variables (vars);
+    free_predefined_variables (vars);
 
-  exit_parser (pe);
+    exit_parser (pe);
 
-  return last_error == PARSER_NO_ERROR;
+    return last_error == PARSER_NO_ERROR;
 }
 
 const char *
 gnc_exp_parser_error_string (void)
 {
-  if ( last_error == PARSER_NO_ERROR ) {
-    switch ( last_gncp_error ) {
-    default:
-    case NO_ERR:
-      return NULL; break;
-    case VARIABLE_IN_EXP:
-      return _("Illegal variable in expression." ); break;
+    if ( last_error == PARSER_NO_ERROR )
+    {
+        switch ( last_gncp_error )
+        {
+        default:
+        case NO_ERR:
+            return NULL;
+            break;
+        case VARIABLE_IN_EXP:
+            return _("Illegal variable in expression." );
+            break;
+        }
     }
-  }
 
-  switch (last_error)
-  {
+    switch (last_error)
+    {
     default:
     case PARSER_NO_ERROR:
-      return NULL;
+        return NULL;
     case UNBALANCED_PARENS:
-      return _("Unbalanced parenthesis");
+        return _("Unbalanced parenthesis");
     case STACK_OVERFLOW:
-      return _("Stack overflow");
+        return _("Stack overflow");
     case STACK_UNDERFLOW:
-      return _("Stack underflow");
+        return _("Stack underflow");
     case UNDEFINED_CHARACTER:
-      return _("Undefined character");
+        return _("Undefined character");
     case NOT_A_VARIABLE:
-      return _("Not a variable");
+        return _("Not a variable");
     case NOT_A_FUNC:
-      return _("Not a defined function");
+        return _("Not a defined function");
     case PARSER_OUT_OF_MEMORY:
-      return _("Out of memory");
+        return _("Out of memory");
     case NUMERIC_ERROR:
-      return _("Numeric error");
-  }
+        return _("Numeric error");
+    }
 }

Modified: gnucash/trunk/src/app-utils/gnc-exp-parser.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-exp-parser.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-exp-parser.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -27,10 +27,11 @@
 /**
  * The errors which can be determined at the gnc-exp-parser level.
  **/
-typedef enum {
-  NO_ERR,
-  VARIABLE_IN_EXP,
-  NUM_ERRORS
+typedef enum
+{
+    NO_ERR,
+    VARIABLE_IN_EXP,
+    NUM_ERRORS
 } GNCParseError;
 
 /* Initialize the expression parser. If this function is not
@@ -94,9 +95,9 @@
  * values of varHash when done.
  **/
 gboolean gnc_exp_parser_parse_separate_vars (const char * expression,
-                                             gnc_numeric *value_p,
-                                             char **error_loc_p,
-                                             GHashTable *varHash );
+        gnc_numeric *value_p,
+        char **error_loc_p,
+        GHashTable *varHash );
 
 /* If the last parse returned FALSE, return an error string describing
  * the problem. Otherwise, return NULL. */

Modified: gnucash/trunk/src/app-utils/gnc-gettext-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-gettext-util.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-gettext-util.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -7,12 +7,12 @@
  * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -32,6 +32,6 @@
 char *
 gnc_gettext_helper(const char *string)
 {
-  return strdup(string && *string ? _(string) : "");
+    return strdup(string && *string ? _(string) : "");
 }
 

Modified: gnucash/trunk/src/app-utils/gnc-gettext-util.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-gettext-util.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-gettext-util.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -7,12 +7,12 @@
  * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Modified: gnucash/trunk/src/app-utils/gnc-help-utils.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-help-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-help-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -1,4 +1,4 @@
-/* 
+/*
  * gnc-help-utils.c
  *
  * Copyright (C) 2007 Andreas Koehler <andi5.py at gmx.net>
@@ -55,12 +55,13 @@
     keyfile = g_key_file_new();
     if (!g_key_file_load_from_file(keyfile, mapfile, G_KEY_FILE_NONE, &error))
         goto cleanup_parse;
-        
+
     if (NULL == (keys = g_key_file_get_keys(keyfile, "Map", NULL, &error)))
         goto cleanup_parse;
 
     ctxtmap = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
-    for (key=keys; *key; key++) {
+    for (key = keys; *key; key++)
+    {
         value = g_key_file_get_integer(keyfile, "Map", *key, &error);
         if (error)
             goto cleanup_parse;
@@ -68,8 +69,9 @@
             g_hash_table_insert(ctxtmap, g_strdup(*key), GINT_TO_POINTER(value));
     }
 
- cleanup_parse:
-    if (error) {
+cleanup_parse:
+    if (error)
+    {
         g_warning("Could not load help map file: %s", error->message);
         g_error_free(error);
         if (ctxtmap)
@@ -98,22 +100,28 @@
 
     g_return_if_fail(chmfile);
 
-    if (anchor) {
+    if (anchor)
+    {
         G_LOCK(chmfile_ctxtmap_map);
-        if (!chmfile_ctxtmap_map) {
+        if (!chmfile_ctxtmap_map)
+        {
             chmfile_ctxtmap_map = g_hash_table_new(g_str_hash, g_str_equal);
             create_map = TRUE;
-        } else {
+        }
+        else
+        {
             create_map = !g_hash_table_lookup_extended(
-                chmfile_ctxtmap_map, chmfile, NULL, (gpointer) &ctxtmap);
+                             chmfile_ctxtmap_map, chmfile, NULL, (gpointer) & ctxtmap);
         }
 
-        if (create_map) {
+        if (create_map)
+        {
             ctxtmap = parse_hhmap_file(chmfile);
             g_hash_table_insert(chmfile_ctxtmap_map, g_strdup(chmfile), ctxtmap);
         }
 
-        if (ctxtmap) {
+        if (ctxtmap)
+        {
             gpointer ptr = g_hash_table_lookup(ctxtmap, anchor);
             if (ptr)
                 id = GPOINTER_TO_INT(ptr);

Modified: gnucash/trunk/src/app-utils/gnc-help-utils.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-help-utils.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-help-utils.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -1,4 +1,4 @@
-/* 
+/*
  * gnc-help-utils.h
  *
  * Copyright (C) 2007 Andreas Koehler <andi5.py at gmx.net>

Modified: gnucash/trunk/src/app-utils/gnc-helpers.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-helpers.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-helpers.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -38,80 +38,80 @@
 SCM
 gnc_printinfo2scm(GNCPrintAmountInfo info)
 {
-  SCM info_scm = SCM_EOL;
+    SCM info_scm = SCM_EOL;
 
-  info_scm = scm_cons (SCM_BOOL (info.round), info_scm);
-  info_scm = scm_cons (SCM_BOOL (info.force_fit), info_scm);
-  info_scm = scm_cons (SCM_BOOL (info.monetary), info_scm);
-  info_scm = scm_cons (SCM_BOOL (info.use_locale), info_scm);
-  info_scm = scm_cons (SCM_BOOL (info.use_symbol), info_scm);
-  info_scm = scm_cons (SCM_BOOL (info.use_separators), info_scm);
+    info_scm = scm_cons (SCM_BOOL (info.round), info_scm);
+    info_scm = scm_cons (SCM_BOOL (info.force_fit), info_scm);
+    info_scm = scm_cons (SCM_BOOL (info.monetary), info_scm);
+    info_scm = scm_cons (SCM_BOOL (info.use_locale), info_scm);
+    info_scm = scm_cons (SCM_BOOL (info.use_symbol), info_scm);
+    info_scm = scm_cons (SCM_BOOL (info.use_separators), info_scm);
 
-  info_scm = scm_cons (scm_int2num (info.min_decimal_places), info_scm);
-  info_scm = scm_cons (scm_int2num (info.max_decimal_places), info_scm);
+    info_scm = scm_cons (scm_int2num (info.min_decimal_places), info_scm);
+    info_scm = scm_cons (scm_int2num (info.max_decimal_places), info_scm);
 
-  info_scm = scm_cons (gnc_commodity_to_scm (info.commodity), info_scm);
+    info_scm = scm_cons (gnc_commodity_to_scm (info.commodity), info_scm);
 
-  info_scm = scm_cons (scm_str2symbol ("print-info"), info_scm);
+    info_scm = scm_cons (scm_str2symbol ("print-info"), info_scm);
 
-  return info_scm;
+    return info_scm;
 }
 
 GNCPrintAmountInfo
 gnc_scm2printinfo(SCM info_scm)
 {
-  GNCPrintAmountInfo info;
+    GNCPrintAmountInfo info;
 
-  /* skip type */
-  info_scm = SCM_CDR (info_scm);
-  info.commodity = gnc_scm_to_commodity (SCM_CAR (info_scm));
+    /* skip type */
+    info_scm = SCM_CDR (info_scm);
+    info.commodity = gnc_scm_to_commodity (SCM_CAR (info_scm));
 
-  info_scm = SCM_CDR (info_scm);
-  info.max_decimal_places = scm_num2int (SCM_CAR (info_scm), SCM_ARG1,
-                                         G_STRFUNC);
+    info_scm = SCM_CDR (info_scm);
+    info.max_decimal_places = scm_num2int (SCM_CAR (info_scm), SCM_ARG1,
+                                           G_STRFUNC);
 
-  info_scm = SCM_CDR (info_scm);
-  info.min_decimal_places = scm_num2int (SCM_CAR (info_scm), SCM_ARG1,
-                                         G_STRFUNC);
+    info_scm = SCM_CDR (info_scm);
+    info.min_decimal_places = scm_num2int (SCM_CAR (info_scm), SCM_ARG1,
+                                           G_STRFUNC);
 
-  info_scm = SCM_CDR (info_scm);
-  info.use_separators = SCM_NFALSEP (SCM_CAR (info_scm));
+    info_scm = SCM_CDR (info_scm);
+    info.use_separators = SCM_NFALSEP (SCM_CAR (info_scm));
 
-  info_scm = SCM_CDR (info_scm);
-  info.use_symbol = SCM_NFALSEP (SCM_CAR (info_scm));
+    info_scm = SCM_CDR (info_scm);
+    info.use_symbol = SCM_NFALSEP (SCM_CAR (info_scm));
 
-  info_scm = SCM_CDR (info_scm);
-  info.use_locale = SCM_NFALSEP (SCM_CAR (info_scm));
+    info_scm = SCM_CDR (info_scm);
+    info.use_locale = SCM_NFALSEP (SCM_CAR (info_scm));
 
-  info_scm = SCM_CDR (info_scm);
-  info.monetary = SCM_NFALSEP (SCM_CAR (info_scm));
+    info_scm = SCM_CDR (info_scm);
+    info.monetary = SCM_NFALSEP (SCM_CAR (info_scm));
 
-  info_scm = SCM_CDR (info_scm);
-  info.force_fit = SCM_NFALSEP (SCM_CAR (info_scm));
+    info_scm = SCM_CDR (info_scm);
+    info.force_fit = SCM_NFALSEP (SCM_CAR (info_scm));
 
-  info_scm = SCM_CDR (info_scm);
-  info.round = SCM_NFALSEP (SCM_CAR (info_scm));
+    info_scm = SCM_CDR (info_scm);
+    info.round = SCM_NFALSEP (SCM_CAR (info_scm));
 
-  return info;
+    return info;
 }
 
 int
 gnc_printinfo_p(SCM info_scm)
 {
-  const gchar *symbol;
+    const gchar *symbol;
 
-  if (!SCM_LISTP(info_scm) || SCM_NULLP(info_scm))
-    return 0;
+    if (!SCM_LISTP(info_scm) || SCM_NULLP(info_scm))
+        return 0;
 
-  info_scm = SCM_CAR (info_scm);
-  if (!SCM_SYMBOLP (info_scm))
-    return 0;
+    info_scm = SCM_CAR (info_scm);
+    if (!SCM_SYMBOLP (info_scm))
+        return 0;
 
-  symbol = SCM_SYMBOL_CHARS (info_scm);
-  if (symbol == NULL)
-    return 0;
+    symbol = SCM_SYMBOL_CHARS (info_scm);
+    if (symbol == NULL)
+        return 0;
 
-  return (strcmp (symbol, "print-info") == 0);
+    return (strcmp (symbol, "print-info") == 0);
 }
 
 /* This is a scaled down version of the routine that would be needed
@@ -131,41 +131,41 @@
 SCM
 gnc_quoteinfo2scm(gnc_commodity *comm)
 {
-  gnc_quote_source *source;
-  const char *name, *tz;
-  SCM info_scm = SCM_EOL, comm_scm, def_comm_scm;
+    gnc_quote_source *source;
+    const char *name, *tz;
+    SCM info_scm = SCM_EOL, comm_scm, def_comm_scm;
 
-  if (!comm)
-    return SCM_EOL;
+    if (!comm)
+        return SCM_EOL;
 
-  source = gnc_commodity_get_quote_source (comm);
-  name = gnc_quote_source_get_internal_name (source);
-  tz = gnc_commodity_get_quote_tz (comm);
-  comm_scm = SWIG_NewPointerObj(comm, SWIG_TypeQuery("_p_gnc_commodity"), 0);
-  def_comm_scm = SWIG_NewPointerObj(gnc_default_currency (),
-                                    SWIG_TypeQuery("_p_gnc_commodity"), 0);
+    source = gnc_commodity_get_quote_source (comm);
+    name = gnc_quote_source_get_internal_name (source);
+    tz = gnc_commodity_get_quote_tz (comm);
+    comm_scm = SWIG_NewPointerObj(comm, SWIG_TypeQuery("_p_gnc_commodity"), 0);
+    def_comm_scm = SWIG_NewPointerObj(gnc_default_currency (),
+                                      SWIG_TypeQuery("_p_gnc_commodity"), 0);
 
-  if (tz)
-    info_scm = scm_cons (scm_makfrom0str (tz), info_scm);
-  else
-    info_scm = scm_cons (SCM_BOOL_F, info_scm);
-  info_scm = scm_cons (def_comm_scm, info_scm);
-  info_scm = scm_cons (comm_scm, info_scm);
-  info_scm = scm_cons (scm_makfrom0str (name), info_scm);
-  return info_scm;
+    if (tz)
+        info_scm = scm_cons (scm_makfrom0str (tz), info_scm);
+    else
+        info_scm = scm_cons (SCM_BOOL_F, info_scm);
+    info_scm = scm_cons (def_comm_scm, info_scm);
+    info_scm = scm_cons (comm_scm, info_scm);
+    info_scm = scm_cons (scm_makfrom0str (name), info_scm);
+    return info_scm;
 }
 
 SCM
 gnc_parse_amount_helper (const char * string, gboolean monetary)
 {
-  gnc_numeric result;
-  gboolean ok;
+    gnc_numeric result;
+    gboolean ok;
 
-  g_return_val_if_fail (string, SCM_BOOL_F);
+    g_return_val_if_fail (string, SCM_BOOL_F);
 
-  ok = xaccParseAmount (string, monetary, &result, NULL);
-  if (!ok)
-    return SCM_BOOL_F;
+    ok = xaccParseAmount (string, monetary, &result, NULL);
+    if (!ok)
+        return SCM_BOOL_F;
 
-  return gnc_numeric_to_scm (result);
+    return gnc_numeric_to_scm (result);
 }

Modified: gnucash/trunk/src/app-utils/gnc-sx-instance-model.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-sx-instance-model.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-sx-instance-model.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -1,4 +1,4 @@
-/* 
+/*
  * gnc-sx-instance-model.c
  *
  * Copyright (C) 2006 Josh Sled <jsled at asynchronous.org>
@@ -208,7 +208,7 @@
         {
             first_cmdty = split_cmdty;
         }
-                
+
         if (! gnc_commodity_equal(split_cmdty, first_cmdty))
         {
             GncSxVariable *var;
@@ -439,11 +439,11 @@
     instances->include_disabled = include_disabled;
     instances->range_end = *range_end;
 
-    if (include_disabled) 
+    if (include_disabled)
     {
         instances->sx_instance_list = gnc_g_list_map(all_sxes, (GncGMapFunc)_gnc_sx_gen_instances, range_end);
-    } 
-    else 
+    }
+    else
     {
         GList *sx_iter = g_list_first(all_sxes);
         GList *enabled_sxes = NULL;
@@ -472,8 +472,10 @@
 gnc_sx_instance_model_get_type(void)
 {
     static GType type = 0;
-    if (type == 0) {
-        static const GTypeInfo info = {
+    if (type == 0)
+    {
+        static const GTypeInfo info =
+        {
             sizeof (GncSxInstanceModelClass),
             NULL,   /* base_init */
             NULL,   /* base_finalize */
@@ -516,7 +518,7 @@
         g_hash_table_destroy(instance->variable_bindings);
     }
     instance->variable_bindings = NULL;
-     
+
     g_free(instance);
 }
 
@@ -672,8 +674,8 @@
                 {
                     /* it's moved from disabled to enabled, add the instances */
                     instances->sx_instance_list
-                        = g_list_append(instances->sx_instance_list,
-                                        _gnc_sx_gen_instances((gpointer)sx, (gpointer)&instances->range_end));
+                    = g_list_append(instances->sx_instance_list,
+                                    _gnc_sx_gen_instances((gpointer)sx, (gpointer) & instances->range_end));
                     g_signal_emit_by_name(instances, "added", (gpointer)sx);
                 }
             }
@@ -705,8 +707,8 @@
             {
                 /* generate instances, add to instance list, emit update. */
                 instances->sx_instance_list
-                    = g_list_append(instances->sx_instance_list,
-                                    _gnc_sx_gen_instances((gpointer)sx, (gpointer)&instances->range_end));
+                = g_list_append(instances->sx_instance_list,
+                                _gnc_sx_gen_instances((gpointer)sx, (gpointer) & instances->range_end));
                 g_signal_emit_by_name(instances, "added", (gpointer)sx);
             }
         }
@@ -826,7 +828,7 @@
         {
             GList *var_iter;
             GncSxInstance *inst = (GncSxInstance*)inst_iter->data;
-            
+
             for (var_iter = removed_var_names; var_iter != NULL; var_iter = var_iter->next)
             {
                 gchar *to_remove_key = (gchar*)var_iter->data;
@@ -837,10 +839,10 @@
             {
                 gchar *to_add_key = (gchar*)var_iter->data;
                 if (!g_hash_table_lookup_extended(
-                        inst->variable_bindings, to_add_key, NULL, NULL))
+                            inst->variable_bindings, to_add_key, NULL, NULL))
                 {
                     GncSxVariable *parent_var
-                        = g_hash_table_lookup(existing->variable_names, to_add_key);
+                    = g_hash_table_lookup(existing->variable_names, to_add_key);
                     GncSxVariable *var_copy;
 
                     g_assert(parent_var != NULL);
@@ -873,8 +875,8 @@
 increment_sx_state(GncSxInstance *inst, GDate **last_occur_date, int *instance_count, int *remain_occur_count)
 {
     if (!g_date_valid(*last_occur_date)
-        || (g_date_valid(*last_occur_date)
-            && g_date_compare(*last_occur_date, &inst->date) <= 0))
+            || (g_date_valid(*last_occur_date)
+                && g_date_compare(*last_occur_date, &inst->date) <= 0))
     {
         *last_occur_date = &inst->date;
     }
@@ -974,7 +976,7 @@
             else
                 g_string_free(err, TRUE);
         }
-        
+
         if (parser_vars != NULL)
         {
             g_hash_table_destroy(parser_vars);
@@ -1030,7 +1032,7 @@
                      g_date_get_day(&creation_data->instance->date),
                      g_date_get_month(&creation_data->instance->date),
                      g_date_get_year(&creation_data->instance->date));
-        
+
     /* the accounts and amounts are in the kvp_frames of the splits. */
     template_splits = xaccTransGetSplitList(template_txn);
     txn_splits = xaccTransGetSplitList(new_txn);
@@ -1044,13 +1046,13 @@
     }
 
     for (;
-         txn_splits && template_splits;
-         txn_splits = txn_splits->next, template_splits = template_splits->next)
+            txn_splits && template_splits;
+            txn_splits = txn_splits->next, template_splits = template_splits->next)
     {
         Split *template_split;
         Account *split_acct;
         gnc_commodity *split_cmdty = NULL;
-             
+
         /* FIXME: Ick.  This assumes that the split lists will be ordered
            identically. :( They are, but we'd rather not have to count on
            it. --jsled */
@@ -1062,7 +1064,7 @@
             err_flag = TRUE;
             break;
         }
-             
+
         /* clear out any copied Split frame data. */
         qof_instance_set_slots(QOF_INSTANCE(copying_split), kvp_frame_new());
 
@@ -1084,14 +1086,14 @@
 
             _get_credit_formula_value(creation_data->instance, template_split, &credit_num, creation_data->creation_errors);
             _get_debit_formula_value(creation_data->instance, template_split, &debit_num, creation_data->creation_errors);
-                       
+
             final = gnc_numeric_sub_fixed( debit_num, credit_num );
-                        
+
             gncn_error = gnc_numeric_check(final);
             if (gncn_error != GNC_ERROR_OK)
             {
                 GString *err = g_string_new("");
-                g_string_printf(err, "error %d in SX [%s] final gnc_numeric value, using 0 instead", 
+                g_string_printf(err, "error %d in SX [%s] final gnc_numeric value, using 0 instead",
                                 gncn_error, xaccSchedXactionGetName(creation_data->instance->parent->sx));
                 g_critical("%s", err->str);
                 if (creation_data->creation_errors != NULL)
@@ -1144,7 +1146,7 @@
                                 gnc_commodity_get_mnemonic(split_cmdty),
                                 gnc_commodity_get_mnemonic(first_cmdty));
                 exchange_rate_var = (GncSxVariable*)g_hash_table_lookup(creation_data->instance->variable_bindings,
-                                                                        exchange_rate_var_name->str);
+                                    exchange_rate_var_name->str);
                 if (exchange_rate_var != NULL)
                 {
                     exchange_rate = exchange_rate_var->value;
@@ -1179,7 +1181,7 @@
     if (creation_data->created_txn_guids != NULL)
     {
         *creation_data->created_txn_guids
-            = g_list_append(*(creation_data->created_txn_guids), (gpointer)xaccTransGetGUID(new_txn));
+        = g_list_append(*(creation_data->created_txn_guids), (gpointer)xaccTransGetGUID(new_txn));
     }
 
     return FALSE;
@@ -1243,7 +1245,7 @@
             }
 
             if (inst->orig_state == SX_INSTANCE_STATE_POSTPONED
-                && inst->state != SX_INSTANCE_STATE_POSTPONED)
+                    && inst->state != SX_INSTANCE_STATE_POSTPONED)
             {
                 // remove from postponed list
                 g_assert(inst->temporal_state != NULL);
@@ -1279,7 +1281,7 @@
                 break;
             }
         }
-          
+
         xaccSchedXactionSetLastOccurDate(instances->sx, last_occur_date);
         gnc_sx_set_instance_count(instances->sx, instance_count);
         xaccSchedXactionSetRemOccur(instances->sx, remain_occur_count);
@@ -1288,8 +1290,8 @@
 
 void
 gnc_sx_instance_model_change_instance_state(GncSxInstanceModel *model,
-                                            GncSxInstance *instance,
-                                            GncSxInstanceState new_state)
+        GncSxInstance *instance,
+        GncSxInstanceState new_state)
 {
     if (instance->state == new_state)
         return;
@@ -1430,8 +1432,8 @@
     // if all the instances are 'auto-create, no-notify', then we don't need
     // the dialog.
     summary->need_dialog
-        = (summary->num_instances != 0
-           && summary->num_auto_create_no_notify_instances != summary->num_instances);
+    = (summary->num_instances != 0
+       && summary->num_auto_create_no_notify_instances != summary->num_instances);
 }
 
 void

Modified: gnucash/trunk/src/app-utils/gnc-sx-instance-model.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-sx-instance-model.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-sx-instance-model.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -1,4 +1,4 @@
-/* 
+/*
  * gnc-sx-instance-model.h
  *
  * Copyright (C) 2006 Josh Sled <jsled at asynchronous.org>
@@ -40,45 +40,45 @@
 
 typedef struct _GncSxInstanceModel
 {
-     GObject parent;
-     gboolean disposed;
+    GObject parent;
+    gboolean disposed;
 
-     /* private */
-     gint qof_event_handler_id;
+    /* private */
+    gint qof_event_handler_id;
 
-     /* signals */
-     /* void (*added)(SchedXaction *sx); // gpointer user_data */
-     /* void (*updated)(SchedXaction *sx); // gpointer user_data */
-     /* void (*removing)(SchedXaction *sx); // gpointer user_data */
+    /* signals */
+    /* void (*added)(SchedXaction *sx); // gpointer user_data */
+    /* void (*updated)(SchedXaction *sx); // gpointer user_data */
+    /* void (*removing)(SchedXaction *sx); // gpointer user_data */
 
-     /* public */
-     GDate range_end;
-     gboolean include_disabled;
-     GList *sx_instance_list; /* <GncSxInstances*> */
+    /* public */
+    GDate range_end;
+    gboolean include_disabled;
+    GList *sx_instance_list; /* <GncSxInstances*> */
 } GncSxInstanceModel;
 
 typedef struct _GncSxInstanceModelClass
 {
-     GObjectClass parent;
+    GObjectClass parent;
 
-     guint removing_signal_id;
-     guint updated_signal_id;
-     guint added_signal_id;
+    guint removing_signal_id;
+    guint updated_signal_id;
+    guint added_signal_id;
 } GncSxInstanceModelClass;
 
 typedef struct _GncSxInstances
 {
-     SchedXaction *sx;
-     GHashTable /** <name:char*,GncSxVariable*> **/ *variable_names;
-     gboolean variable_names_parsed;
-     
-     GDate next_instance_date;
-     
-     /** GList<GncSxInstance*> **/
+    SchedXaction *sx;
+    GHashTable /** <name:char*,GncSxVariable*> **/ *variable_names;
+    gboolean variable_names_parsed;
+
+    GDate next_instance_date;
+
+    /** GList<GncSxInstance*> **/
     GList *instance_list;
 } GncSxInstances;
 
-typedef enum 
+typedef enum
 {
     SX_INSTANCE_STATE_IGNORED,
     SX_INSTANCE_STATE_POSTPONED,
@@ -145,29 +145,29 @@
  * but upcoming reminders are not.  As such, a reminder can never be before any
  * other (modeled) instance type.  For instance, the following sequences are
  * disallowed:
- * 
+ *
  * [...]
  * remind    <- will be lost/skipped over; must be converted to `postponed`.
  * to-create <- this will be the last-recorded state.
  * [...]
- * 
+ *
  * [...]
  * remind    <- same as previous; will be lost/skipped; must be `postponed`.
  * postponed
  * [...]
- * 
+ *
  * remind    <- same...
  * ignore
  * [...]
- * 
- * 
+ *
+ *
  * As such, the SinceLastRun model will enforce that there are no previous
  * `remind` instances at every state change.  They will be silently converted to
  * `postponed`-state transactions.
  **/
 void gnc_sx_instance_model_change_instance_state(GncSxInstanceModel *model,
-                                                 GncSxInstance *instance,
-                                                 GncSxInstanceState new_state);
+        GncSxInstance *instance,
+        GncSxInstanceState new_state);
 
 void gnc_sx_instance_model_set_variable(GncSxInstanceModel *model,
                                         GncSxInstance *instance,
@@ -180,9 +180,9 @@
  **/
 GList* gnc_sx_instance_model_check_variables(GncSxInstanceModel *model);
 void gnc_sx_instance_model_effect_change(GncSxInstanceModel *model,
-                                         gboolean auto_create_only,
-                                         GList **created_transaction_guids,
-                                         GList **creation_errors);
+        gboolean auto_create_only,
+        GList **created_transaction_guids,
+        GList **creation_errors);
 
 typedef struct _GncSxSummary
 {

Modified: gnucash/trunk/src/app-utils/gnc-ui-common.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-common.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-ui-common.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -26,19 +26,19 @@
 #define GNC_UI_COMMON_H
 
 #if defined(GNOME)
-  #include <gtk/gtk.h>
+#include <gtk/gtk.h>
 #elif defined(MOTIF)
-  #include <Xm/Xm.h>
+#include <Xm/Xm.h>
 #else
-  **** No GUI selected ***
+**** No GUI selected ***
 #endif
 
 #if defined(GNOME)
-  typedef GtkWidget *gncUIWidget;
+typedef GtkWidget *gncUIWidget;
 #elif defined(MOTIF)
-  typedef Widget gncUIWidget;
+typedef Widget gncUIWidget;
 #elif defined(KDE)
-  typedef void *gncUIWidget;
+typedef void *gncUIWidget;
 #endif
 
 #endif

Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -79,191 +79,191 @@
 static void
 gnc_configure_account_separator (void)
 {
-  const gchar *separator;
-  char *string;
+    const gchar *separator;
+    char *string;
 
-  string = gnc_gconf_get_string(GCONF_GENERAL, KEY_ACCOUNT_SEPARATOR, NULL);
+    string = gnc_gconf_get_string(GCONF_GENERAL, KEY_ACCOUNT_SEPARATOR, NULL);
 
-  if (!string || !*string || safe_strcmp(string, "colon") == 0)
-    separator = ":";
-  else if (safe_strcmp(string, "slash") == 0)
-    separator = "/";
-  else if (safe_strcmp(string, "backslash") == 0)
-    separator = "\\";
-  else if (safe_strcmp(string, "dash") == 0)
-    separator = "-";
-  else if (safe_strcmp(string, "period") == 0)
-    separator = ".";
-  else
-    separator = string;
+    if (!string || !*string || safe_strcmp(string, "colon") == 0)
+        separator = ":";
+    else if (safe_strcmp(string, "slash") == 0)
+        separator = "/";
+    else if (safe_strcmp(string, "backslash") == 0)
+        separator = "\\";
+    else if (safe_strcmp(string, "dash") == 0)
+        separator = "-";
+    else if (safe_strcmp(string, "period") == 0)
+        separator = ".";
+    else
+        separator = string;
 
-  gnc_set_account_separator(separator);
+    gnc_set_account_separator(separator);
 
-  if (string != NULL)
-    free(string);
+    if (string != NULL)
+        free(string);
 }
 
 
 static void
 gnc_configure_reverse_balance (void)
 {
-  gchar *choice;
-  gint i;
+    gchar *choice;
+    gint i;
 
-  for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
-    reverse_type[i] = FALSE;
+    for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
+        reverse_type[i] = FALSE;
 
-  choice = gnc_gconf_get_string(GCONF_GENERAL, KEY_REVERSED_ACCOUNTS, NULL);
+    choice = gnc_gconf_get_string(GCONF_GENERAL, KEY_REVERSED_ACCOUNTS, NULL);
 
-  if (safe_strcmp (choice, "none") == 0)
-  {
-  }
-  else if (safe_strcmp (choice, "income_expense") == 0)
-  {
-    reverse_type[ACCT_TYPE_INCOME]  = TRUE;
-    reverse_type[ACCT_TYPE_EXPENSE] = TRUE;
-  }
-  else
-  {
-    if (safe_strcmp (choice, "credit") != 0)
-      PERR("bad value '%s'", choice ? choice : "(null)");
-    reverse_type[ACCT_TYPE_LIABILITY] = TRUE;
-    reverse_type[ACCT_TYPE_PAYABLE]   = TRUE;
-    reverse_type[ACCT_TYPE_EQUITY]    = TRUE;
-    reverse_type[ACCT_TYPE_INCOME]    = TRUE;
-    reverse_type[ACCT_TYPE_CREDIT]    = TRUE;
-  }
+    if (safe_strcmp (choice, "none") == 0)
+    {
+    }
+    else if (safe_strcmp (choice, "income_expense") == 0)
+    {
+        reverse_type[ACCT_TYPE_INCOME]  = TRUE;
+        reverse_type[ACCT_TYPE_EXPENSE] = TRUE;
+    }
+    else
+    {
+        if (safe_strcmp (choice, "credit") != 0)
+            PERR("bad value '%s'", choice ? choice : "(null)");
+        reverse_type[ACCT_TYPE_LIABILITY] = TRUE;
+        reverse_type[ACCT_TYPE_PAYABLE]   = TRUE;
+        reverse_type[ACCT_TYPE_EQUITY]    = TRUE;
+        reverse_type[ACCT_TYPE_INCOME]    = TRUE;
+        reverse_type[ACCT_TYPE_CREDIT]    = TRUE;
+    }
 
-  if (choice != NULL)
-    free (choice);
+    if (choice != NULL)
+        free (choice);
 }
 
 static void
 gnc_reverse_balance_init (void)
 {
-  gnc_configure_reverse_balance ();
-  reverse_balance_inited = TRUE;
+    gnc_configure_reverse_balance ();
+    reverse_balance_inited = TRUE;
 }
 
 gboolean
 gnc_reverse_balance_type (GNCAccountType type)
 {
-  if ((type < 0) || (type >= NUM_ACCOUNT_TYPES))
-    return FALSE;
+    if ((type < 0) || (type >= NUM_ACCOUNT_TYPES))
+        return FALSE;
 
-  if (!reverse_balance_inited)
-    gnc_reverse_balance_init ();
+    if (!reverse_balance_inited)
+        gnc_reverse_balance_init ();
 
-  return reverse_type[type];
+    return reverse_type[type];
 }
 
 gboolean
 gnc_reverse_balance (const Account *account)
 {
-  int type;
+    int type;
 
-  if (account == NULL)
-    return FALSE;
+    if (account == NULL)
+        return FALSE;
 
-  type = xaccAccountGetType (account);
-  if ((type < 0) || (type >= NUM_ACCOUNT_TYPES))
-    return FALSE;
+    type = xaccAccountGetType (account);
+    if ((type < 0) || (type >= NUM_ACCOUNT_TYPES))
+        return FALSE;
 
-  if (!reverse_balance_inited)
-    gnc_reverse_balance_init ();
+    if (!reverse_balance_inited)
+        gnc_reverse_balance_init ();
 
-  return reverse_type[type];
+    return reverse_type[type];
 }
 
 
 gchar *
 gnc_get_default_directory (const gchar *gconf_section)
 {
-  gchar *dir;
+    gchar *dir;
 
-  dir = gnc_gconf_get_string (gconf_section, KEY_LAST_PATH, NULL);
-  if (!dir)
-    dir = g_strdup (g_get_home_dir ());
+    dir = gnc_gconf_get_string (gconf_section, KEY_LAST_PATH, NULL);
+    if (!dir)
+        dir = g_strdup (g_get_home_dir ());
 
-  return dir;
+    return dir;
 }
 
 void
 gnc_set_default_directory (const gchar *gconf_section, const gchar *directory)
 {
-  gnc_gconf_set_string(gconf_section, KEY_LAST_PATH, directory, NULL);
+    gnc_gconf_set_string(gconf_section, KEY_LAST_PATH, directory, NULL);
 }
 
 QofBook *
 gnc_get_current_book (void)
 {
-  return qof_session_get_book (gnc_get_current_session ());
+    return qof_session_get_book (gnc_get_current_session ());
 }
 
 void
 gnc_set_current_book_tax_name (const gchar *tax_name)
 {
-  kvp_frame_set_string (qof_book_get_slots (gnc_get_current_book()),
-                         "book/tax_US/name", tax_name);
+    kvp_frame_set_string (qof_book_get_slots (gnc_get_current_book()),
+                          "book/tax_US/name", tax_name);
 }
 
 const gchar *
 gnc_get_current_book_tax_name (void)
 {
-  return kvp_frame_get_string (qof_book_get_slots (gnc_get_current_book()),
-                         "book/tax_US/name");
+    return kvp_frame_get_string (qof_book_get_slots (gnc_get_current_book()),
+                                 "book/tax_US/name");
 }
 
 void
 gnc_set_current_book_tax_type (const gchar *tax_type)
 {
-  kvp_frame_set_string(qof_book_get_slots(gnc_get_current_book()),
+    kvp_frame_set_string(qof_book_get_slots(gnc_get_current_book()),
                          "book/tax_US/type", tax_type);
 }
 
 const gchar *
 gnc_get_current_book_tax_type (void)
 {
-  return kvp_frame_get_string(qof_book_get_slots(gnc_get_current_book()),
-                         "book/tax_US/type");
+    return kvp_frame_get_string(qof_book_get_slots(gnc_get_current_book()),
+                                "book/tax_US/type");
 }
 
 Account *
 gnc_get_current_root_account (void)
 {
-  return gnc_book_get_root_account (gnc_get_current_book ());
+    return gnc_book_get_root_account (gnc_get_current_book ());
 }
 
 gnc_commodity_table *
 gnc_get_current_commodities (void)
 {
-  return gnc_book_get_commodity_table (gnc_get_current_book ());
+    return gnc_book_get_commodity_table (gnc_get_current_book ());
 }
 
 gchar *
 gnc_get_account_name_for_register(const Account *account)
 {
-  gboolean show_leaf_accounts;
-  show_leaf_accounts = gnc_gconf_get_bool(GCONF_GENERAL_REGISTER,
-					  KEY_SHOW_LEAF_ACCOUNT_NAMES, NULL);
+    gboolean show_leaf_accounts;
+    show_leaf_accounts = gnc_gconf_get_bool(GCONF_GENERAL_REGISTER,
+                                            KEY_SHOW_LEAF_ACCOUNT_NAMES, NULL);
 
-  if (show_leaf_accounts)
-    return g_strdup (xaccAccountGetName (account));
-  else
-    return gnc_account_get_full_name (account);
+    if (show_leaf_accounts)
+        return g_strdup (xaccAccountGetName (account));
+    else
+        return gnc_account_get_full_name (account);
 }
 
 Account *
 gnc_account_lookup_for_register(const Account *base_account, const char *name)
 {
-  gboolean show_leaf_accounts;
-  show_leaf_accounts = gnc_gconf_get_bool(GCONF_GENERAL_REGISTER,
-					  KEY_SHOW_LEAF_ACCOUNT_NAMES, NULL);
+    gboolean show_leaf_accounts;
+    show_leaf_accounts = gnc_gconf_get_bool(GCONF_GENERAL_REGISTER,
+                                            KEY_SHOW_LEAF_ACCOUNT_NAMES, NULL);
 
-  if (show_leaf_accounts)
-    return gnc_account_lookup_by_name (base_account, name);
-  else
-    return gnc_account_lookup_by_full_name (base_account, name);
+    if (show_leaf_accounts)
+        return gnc_account_lookup_by_name (base_account, name);
+    else
+        return gnc_account_lookup_by_full_name (base_account, name);
 }
 
 
@@ -287,24 +287,24 @@
  */
 gnc_numeric
 gnc_ui_account_get_balance_full (xaccGetBalanceInCurrencyFn fn,
-				 const Account *account,
-				 gboolean recurse,
-				 gboolean *negative,
-				 const gnc_commodity *commodity)
+                                 const Account *account,
+                                 gboolean recurse,
+                                 gboolean *negative,
+                                 const gnc_commodity *commodity)
 {
-  gnc_numeric balance;
+    gnc_numeric balance;
 
-  balance = fn(account, commodity, recurse);
+    balance = fn(account, commodity, recurse);
 
-  /* reverse sign if needed */
-  if (gnc_reverse_balance (account))
-    balance = gnc_numeric_neg (balance);
+    /* reverse sign if needed */
+    if (gnc_reverse_balance (account))
+        balance = gnc_numeric_neg (balance);
 
-  /* Record whether the balance is negative. */
-  if (negative)
-    *negative = gnc_numeric_negative_p(balance);
+    /* Record whether the balance is negative. */
+    if (negative)
+        *negative = gnc_numeric_negative_p(balance);
 
-  return balance;
+    return balance;
 }
 
 /*
@@ -314,8 +314,8 @@
 gnc_numeric
 gnc_ui_account_get_balance (const Account *account, gboolean recurse)
 {
-  return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
-					  account, recurse, NULL, NULL);
+    return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
+                                            account, recurse, NULL, NULL);
 }
 
 /*
@@ -325,11 +325,11 @@
  */
 gnc_numeric
 gnc_ui_account_get_balance_in_currency (const Account *account,
-					const gnc_commodity *currency,
-					gboolean recurse)
+                                        const gnc_commodity *currency,
+                                        gboolean recurse)
 {
-  return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
-					  account, recurse, NULL, currency);
+    return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
+                                            account, recurse, NULL, currency);
 }
 
 /*
@@ -340,8 +340,8 @@
 gnc_ui_account_get_reconciled_balance (const Account *account,
                                        gboolean recurse)
 {
-  return gnc_ui_account_get_balance_full (xaccAccountGetReconciledBalanceInCurrency,
-					  account, recurse, NULL, NULL);
+    return gnc_ui_account_get_balance_full (xaccAccountGetReconciledBalanceInCurrency,
+                                            account, recurse, NULL, NULL);
 }
 
 
@@ -361,17 +361,17 @@
  */
 gchar *
 gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn,
-				  const Account *account,
-				  gboolean recurse,
-				  gboolean *negative)
+                                  const Account *account,
+                                  gboolean recurse,
+                                  gboolean *negative)
 {
-  GNCPrintAmountInfo print_info;
-  gnc_numeric balance;
+    GNCPrintAmountInfo print_info;
+    gnc_numeric balance;
 
-  balance = gnc_ui_account_get_balance_full(fn, account, recurse,
-					    negative, NULL);
-  print_info = gnc_account_print_info(account, TRUE);
-  return g_strdup(xaccPrintAmount(balance, print_info));
+    balance = gnc_ui_account_get_balance_full(fn, account, recurse,
+              negative, NULL);
+    print_info = gnc_account_print_info(account, TRUE);
+    return g_strdup(xaccPrintAmount(balance, print_info));
 }
 
 
@@ -391,247 +391,247 @@
  */
 gchar *
 gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
-					 const Account *account,
-					 gboolean recurse,
-					 gboolean *negative)
+        const Account *account,
+        gboolean recurse,
+        gboolean *negative)
 {
-  GNCPrintAmountInfo print_info;
-  gnc_numeric balance;
-  gnc_commodity *report_commodity;
+    GNCPrintAmountInfo print_info;
+    gnc_numeric balance;
+    gnc_commodity *report_commodity;
 
-  report_commodity = gnc_default_report_currency();
-  balance = gnc_ui_account_get_balance_full(fn, account, recurse,
-					    negative, report_commodity);
-  print_info = gnc_commodity_print_info(report_commodity, TRUE);
-  return g_strdup(xaccPrintAmount(balance, print_info));
+    report_commodity = gnc_default_report_currency();
+    balance = gnc_ui_account_get_balance_full(fn, account, recurse,
+              negative, report_commodity);
+    print_info = gnc_commodity_print_info(report_commodity, TRUE);
+    return g_strdup(xaccPrintAmount(balance, print_info));
 }
 
 
 gnc_numeric
 gnc_ui_account_get_balance_as_of_date (Account *account,
-				       time_t date,
+                                       time_t date,
                                        gboolean include_children)
 {
-  gnc_numeric balance;
-  gnc_commodity *currency;
+    gnc_numeric balance;
+    gnc_commodity *currency;
 
-  if (account == NULL)
-    return gnc_numeric_zero ();
+    if (account == NULL)
+        return gnc_numeric_zero ();
 
-  currency = xaccAccountGetCommodity (account);
-  balance = xaccAccountGetBalanceAsOfDate (account, date);
+    currency = xaccAccountGetCommodity (account);
+    balance = xaccAccountGetBalanceAsOfDate (account, date);
 
-  if (include_children)
-  {
-    GList *children, *node;
+    if (include_children)
+    {
+        GList *children, *node;
 
-    children = gnc_account_get_descendants(account);
+        children = gnc_account_get_descendants(account);
 
-    for (node = children; node; node = node->next)
-    {
-      Account *child;
-      gnc_commodity *child_currency;
-      gnc_numeric child_balance;
+        for (node = children; node; node = node->next)
+        {
+            Account *child;
+            gnc_commodity *child_currency;
+            gnc_numeric child_balance;
 
-      child = node->data;
-      child_currency = xaccAccountGetCommodity (child);
-      child_balance = xaccAccountGetBalanceAsOfDate (child, date);
-      child_balance = xaccAccountConvertBalanceToCurrency (child,
-        child_balance, child_currency, currency);
-      balance = gnc_numeric_add_fixed (balance, child_balance);
+            child = node->data;
+            child_currency = xaccAccountGetCommodity (child);
+            child_balance = xaccAccountGetBalanceAsOfDate (child, date);
+            child_balance = xaccAccountConvertBalanceToCurrency (child,
+                            child_balance, child_currency, currency);
+            balance = gnc_numeric_add_fixed (balance, child_balance);
+        }
+
+        g_list_free(children);
     }
 
-    g_list_free(children);
-  }
+    /* reverse sign if needed */
+    if (gnc_reverse_balance (account))
+        balance = gnc_numeric_neg (balance);
 
-  /* reverse sign if needed */
-  if (gnc_reverse_balance (account))
-    balance = gnc_numeric_neg (balance);
-
-  return balance;
+    return balance;
 }
 
 /* Caller is responsible for g_free'ing returned memory */
 char *
 gnc_ui_account_get_tax_info_string (const Account *account)
 {
-  static SCM get_form = SCM_UNDEFINED;
-  static SCM get_desc = SCM_UNDEFINED;
+    static SCM get_form = SCM_UNDEFINED;
+    static SCM get_desc = SCM_UNDEFINED;
 
-  gboolean tax_related = FALSE;
-  const char *code;
-  QofBook *this_book;
-  KvpFrame *book_frame;
-  const gchar *tax_type;
-  GNCAccountType atype;
-  SCM category;
-  SCM code_scm;
-  SCM tax_entity_type;
-  const gchar *form, *desc, *copy_txt;
-  gint64 copy_number;
-  SCM scm;
+    gboolean tax_related = FALSE;
+    const char *code;
+    QofBook *this_book;
+    KvpFrame *book_frame;
+    const gchar *tax_type;
+    GNCAccountType atype;
+    SCM category;
+    SCM code_scm;
+    SCM tax_entity_type;
+    const gchar *form, *desc, *copy_txt;
+    gint64 copy_number;
+    SCM scm;
 
-  if (!account)
-    return NULL;
+    if (!account)
+        return NULL;
 
-  tax_related = xaccAccountGetTaxRelated (account);
-  code = xaccAccountGetTaxUSCode (account);
+    tax_related = xaccAccountGetTaxRelated (account);
+    code = xaccAccountGetTaxUSCode (account);
 
-  if (!code)
-  {
-    if (!tax_related)
-      return NULL;
-    else /* tax_related && !code */
-      return g_strdup (_("Tax-related but has no tax code"));
-  }
-  else  /* with tax code */
-  {
-    tax_type = gnc_get_current_book_tax_type ();
-    if (tax_type == NULL || (safe_strcmp (tax_type, "") == 0))
-      return g_strdup (_("Tax entity type not specified"));
-    atype = xaccAccountGetType (account);
-/*    tax_entity_type = scm_from_locale_string (tax_type); <- requires guile 1.8*/
-    tax_entity_type = scm_makfrom0str (tax_type); /* <-guile 1.6  */
+    if (!code)
+    {
+        if (!tax_related)
+            return NULL;
+        else /* tax_related && !code */
+            return g_strdup (_("Tax-related but has no tax code"));
+    }
+    else  /* with tax code */
+    {
+        tax_type = gnc_get_current_book_tax_type ();
+        if (tax_type == NULL || (safe_strcmp (tax_type, "") == 0))
+            return g_strdup (_("Tax entity type not specified"));
+        atype = xaccAccountGetType (account);
+        /*    tax_entity_type = scm_from_locale_string (tax_type); <- requires guile 1.8*/
+        tax_entity_type = scm_makfrom0str (tax_type); /* <-guile 1.6  */
 
-    if (get_form == SCM_UNDEFINED)
-    {
-      GNCModule module;
-      const gchar *tax_module;
-    /* load the tax info */
+        if (get_form == SCM_UNDEFINED)
+        {
+            GNCModule module;
+            const gchar *tax_module;
+            /* load the tax info */
 #ifdef LOCALE_SPECIFIC_TAX
-    /* This is a very simple hack that loads the (new, special) German
-       tax definition file in a German locale, or (default) loads the
-       previous US tax file. */
+            /* This is a very simple hack that loads the (new, special) German
+               tax definition file in a German locale, or (default) loads the
+               previous US tax file. */
 # ifdef G_OS_WIN32
-      gchar *thislocale = g_win32_getlocale();
-      gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
-      g_free(thislocale);
+            gchar *thislocale = g_win32_getlocale();
+            gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
+            g_free(thislocale);
 # else /* !G_OS_WIN32 */
-      const char *thislocale = setlocale(LC_ALL, NULL);
-      gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
+            const char *thislocale = setlocale(LC_ALL, NULL);
+            gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
 # endif /* G_OS_WIN32 */
 #else /* LOCALE_SPECIFIC_TAX */
-      gboolean is_de_DE = FALSE;
+            gboolean is_de_DE = FALSE;
 #endif /* LOCALE_SPECIFIC_TAX */
-      tax_module = is_de_DE ? 
-          "gnucash/tax/de_DE" : 
-          "gnucash/tax/us";
+            tax_module = is_de_DE ?
+                         "gnucash/tax/de_DE" :
+                         "gnucash/tax/us";
 
-      module = gnc_module_load ((char *)tax_module, 0);
+            module = gnc_module_load ((char *)tax_module, 0);
 
-      g_return_val_if_fail (module, NULL);
+            g_return_val_if_fail (module, NULL);
 
-      get_form = scm_c_eval_string ("(false-if-exception gnc:txf-get-form)");
-      get_desc = scm_c_eval_string
-                              ("(false-if-exception gnc:txf-get-description)");
-    }
+            get_form = scm_c_eval_string ("(false-if-exception gnc:txf-get-form)");
+            get_desc = scm_c_eval_string
+                       ("(false-if-exception gnc:txf-get-description)");
+        }
 
-    g_return_val_if_fail (SCM_PROCEDUREP (get_form), NULL);
-    g_return_val_if_fail (SCM_PROCEDUREP (get_desc), NULL);
+        g_return_val_if_fail (SCM_PROCEDUREP (get_form), NULL);
+        g_return_val_if_fail (SCM_PROCEDUREP (get_desc), NULL);
 
-    category = scm_c_eval_string (atype == ACCT_TYPE_INCOME ?
-                                  "txf-income-categories" :
-                                  (atype == ACCT_TYPE_EXPENSE ?
-                                   "txf-expense-categories" :
-                                   (((atype == ACCT_TYPE_BANK)      || 
-                                     (atype == ACCT_TYPE_CASH)      ||
-                                     (atype == ACCT_TYPE_ASSET)     ||
-                                     (atype == ACCT_TYPE_STOCK)     ||
-                                     (atype == ACCT_TYPE_MUTUAL)    ||
-                                     (atype == ACCT_TYPE_RECEIVABLE)) ?
-                                      "txf-asset-categories" :
-                                     (((atype == ACCT_TYPE_CREDIT)    ||
-                                       (atype == ACCT_TYPE_LIABILITY) ||
-                                       (atype == ACCT_TYPE_EQUITY)    ||
-                                       (atype == ACCT_TYPE_PAYABLE)) ?
-                                        "txf-liab-eq-categories" : ""))));
+        category = scm_c_eval_string (atype == ACCT_TYPE_INCOME ?
+                                      "txf-income-categories" :
+                                      (atype == ACCT_TYPE_EXPENSE ?
+                                       "txf-expense-categories" :
+                                       (((atype == ACCT_TYPE_BANK)      ||
+                                         (atype == ACCT_TYPE_CASH)      ||
+                                         (atype == ACCT_TYPE_ASSET)     ||
+                                         (atype == ACCT_TYPE_STOCK)     ||
+                                         (atype == ACCT_TYPE_MUTUAL)    ||
+                                         (atype == ACCT_TYPE_RECEIVABLE)) ?
+                                        "txf-asset-categories" :
+                                        (((atype == ACCT_TYPE_CREDIT)    ||
+                                          (atype == ACCT_TYPE_LIABILITY) ||
+                                          (atype == ACCT_TYPE_EQUITY)    ||
+                                          (atype == ACCT_TYPE_PAYABLE)) ?
+                                         "txf-liab-eq-categories" : ""))));
 
-    if (category == SCM_UNDEFINED)
-    {
-      if (tax_related)
-        return g_strdup_printf
-           (_("Tax type %s: invalid code %s for account type"), tax_type, code);
-      else
-        return g_strdup_printf
-        (_("Not tax-related; tax type %s: invalid code %s for account type"),
-                                                                tax_type, code);
-    }
+        if (category == SCM_UNDEFINED)
+        {
+            if (tax_related)
+                return g_strdup_printf
+                       (_("Tax type %s: invalid code %s for account type"), tax_type, code);
+            else
+                return g_strdup_printf
+                       (_("Not tax-related; tax type %s: invalid code %s for account type"),
+                        tax_type, code);
+        }
 
-    code_scm = scm_str2symbol (code);
-    scm = scm_call_3 (get_form, category, code_scm, tax_entity_type);
-    if (!SCM_STRINGP (scm))
-    {
-      if (tax_related)
-        return g_strdup_printf
-                         (_("Invalid code %s for tax type %s"), code, tax_type);
-      else
-        return g_strdup_printf
-        (_("Not tax-related; invalid code %s for tax type %s"), code, tax_type);
-    }
+        code_scm = scm_str2symbol (code);
+        scm = scm_call_3 (get_form, category, code_scm, tax_entity_type);
+        if (!SCM_STRINGP (scm))
+        {
+            if (tax_related)
+                return g_strdup_printf
+                       (_("Invalid code %s for tax type %s"), code, tax_type);
+            else
+                return g_strdup_printf
+                       (_("Not tax-related; invalid code %s for tax type %s"), code, tax_type);
+        }
 
-    form = SCM_STRING_CHARS (scm);
-    if (!form)
-    {
-      if (tax_related)
-        return g_strdup_printf
-                           (_("No form: code %s, tax type %s"), code, tax_type);
-      else
-        return g_strdup_printf
-          (_("Not tax-related; no form: code %s, tax type %s"), code, tax_type);
-    }
+        form = SCM_STRING_CHARS (scm);
+        if (!form)
+        {
+            if (tax_related)
+                return g_strdup_printf
+                       (_("No form: code %s, tax type %s"), code, tax_type);
+            else
+                return g_strdup_printf
+                       (_("Not tax-related; no form: code %s, tax type %s"), code, tax_type);
+        }
 
-    scm = scm_call_3 (get_desc, category, code_scm, tax_entity_type);
-    if (!SCM_STRINGP (scm))
-    {
-      if (tax_related)
-        return g_strdup_printf
-        (_("No description: form %s, code %s, tax type %s"),
-                                                          form, code, tax_type);
-      else
-        return g_strdup_printf
-        (_("Not tax-related; no description: form %s, code %s, tax type %s"),
-                                                          form, code, tax_type);
-    }
+        scm = scm_call_3 (get_desc, category, code_scm, tax_entity_type);
+        if (!SCM_STRINGP (scm))
+        {
+            if (tax_related)
+                return g_strdup_printf
+                       (_("No description: form %s, code %s, tax type %s"),
+                        form, code, tax_type);
+            else
+                return g_strdup_printf
+                       (_("Not tax-related; no description: form %s, code %s, tax type %s"),
+                        form, code, tax_type);
+        }
 
-    desc = SCM_STRING_CHARS (scm);
-    if (!desc)
-    {
-      if (tax_related)
-        return g_strdup_printf
-        (_("No description: form %s, code %s, tax type %s"),
-                                                          form, code, tax_type);
-      else
-        return g_strdup_printf
-        (_("Not tax-related; no description: form %s, code %s, tax type %s"),
-                                                          form, code, tax_type);
-    }
+        desc = SCM_STRING_CHARS (scm);
+        if (!desc)
+        {
+            if (tax_related)
+                return g_strdup_printf
+                       (_("No description: form %s, code %s, tax type %s"),
+                        form, code, tax_type);
+            else
+                return g_strdup_printf
+                       (_("Not tax-related; no description: form %s, code %s, tax type %s"),
+                        form, code, tax_type);
+        }
 
-    copy_number = xaccAccountGetTaxUSCopyNumber (account);
-    copy_txt = (copy_number == 1) ? "" : g_strdup_printf ("(%d)",
-                                                            (gint) copy_number);
+        copy_number = xaccAccountGetTaxUSCopyNumber (account);
+        copy_txt = (copy_number == 1) ? "" : g_strdup_printf ("(%d)",
+                   (gint) copy_number);
 
-    if (tax_related)
-      return g_strdup_printf ("%s%s %s", form, copy_txt, desc);
-    else
-      return g_strdup_printf
-      (_("Not tax-related; %s%s %s (code %s, tax type %s)"),
-                                          form, copy_txt, desc, code, tax_type);
-  }
+        if (tax_related)
+            return g_strdup_printf ("%s%s %s", form, copy_txt, desc);
+        else
+            return g_strdup_printf
+                   (_("Not tax-related; %s%s %s (code %s, tax type %s)"),
+                    form, copy_txt, desc, code, tax_type);
+    }
 }
 
 
 static const char *
 string_after_colon (const char *msgstr)
 {
-  const char *string_at_colon;
-  g_assert(msgstr);
-  string_at_colon = strchr(msgstr, ':');
-  if (string_at_colon)
-    return string_at_colon + 1;
-  else
-    /* No colon found; we assume the translation contains only the
-       part after the colon, similar to the disambiguation prefixes */
-    return msgstr;
+    const char *string_at_colon;
+    g_assert(msgstr);
+    string_at_colon = strchr(msgstr, ':');
+    if (string_at_colon)
+        return string_at_colon + 1;
+    else
+        /* No colon found; we assume the translation contains only the
+           part after the colon, similar to the disambiguation prefixes */
+        return msgstr;
 }
 
 /********************************************************************\
@@ -644,24 +644,29 @@
 const char *
 gnc_get_reconcile_str (char reconciled_flag)
 {
-  switch (reconciled_flag)
-  {
-    /* Translators: For the following strings, the single letters
-       after the colon are abbreviations of the word before the
-       colon. You should only translate the letter *after* the colon. */
-    case NREC: return string_after_colon(_("not cleared:n"));
-      /* Translators: Please only translate the letter *after* the colon. */
-    case CREC: return string_after_colon(_("cleared:c"));
-      /* Translators: Please only translate the letter *after* the colon. */
-    case YREC: return string_after_colon(_("reconciled:y"));
-      /* Translators: Please only translate the letter *after* the colon. */
-    case FREC: return string_after_colon(_("frozen:f"));
-      /* Translators: Please only translate the letter *after* the colon. */
-    case VREC: return string_after_colon(_("void:v"));
+    switch (reconciled_flag)
+    {
+        /* Translators: For the following strings, the single letters
+           after the colon are abbreviations of the word before the
+           colon. You should only translate the letter *after* the colon. */
+    case NREC:
+        return string_after_colon(_("not cleared:n"));
+        /* Translators: Please only translate the letter *after* the colon. */
+    case CREC:
+        return string_after_colon(_("cleared:c"));
+        /* Translators: Please only translate the letter *after* the colon. */
+    case YREC:
+        return string_after_colon(_("reconciled:y"));
+        /* Translators: Please only translate the letter *after* the colon. */
+    case FREC:
+        return string_after_colon(_("frozen:f"));
+        /* Translators: Please only translate the letter *after* the colon. */
+    case VREC:
+        return string_after_colon(_("void:v"));
     default:
-      PERR("Bad reconciled flag\n");
-      return NULL;
-  }
+        PERR("Bad reconciled flag\n");
+        return NULL;
+    }
 }
 
 /********************************************************************\
@@ -673,8 +678,8 @@
 const char *
 gnc_get_reconcile_valid_flags (void)
 {
-  static const char flags[] = { NREC, CREC, YREC, FREC, VREC, 0 };
-  return flags;
+    static const char flags[] = { NREC, CREC, YREC, FREC, VREC, 0 };
+    return flags;
 }
 
 /********************************************************************\
@@ -687,25 +692,25 @@
 const char *
 gnc_get_reconcile_flag_order (void)
 {
-  static const char flags[] = { NREC, CREC, 0 };
-  return flags;
+    static const char flags[] = { NREC, CREC, 0 };
+    return flags;
 }
 
 
 static const char *
 equity_base_name (GNCEquityType equity_type)
 {
-  switch (equity_type)
-  {
+    switch (equity_type)
+    {
     case EQUITY_OPENING_BALANCE:
-      return N_("Opening Balances");
+        return N_("Opening Balances");
 
     case EQUITY_RETAINED_EARNINGS:
-      return N_("Retained Earnings");
+        return N_("Retained Earnings");
 
     default:
-      return NULL;
-  }
+        return NULL;
+    }
 }
 
 Account *
@@ -713,88 +718,88 @@
                                    GNCEquityType equity_type,
                                    gnc_commodity *currency)
 {
-  Account *parent;
-  Account *account;
-  gboolean name_exists;
-  gboolean base_name_exists;
-  const char *base_name;
-  char *name;
+    Account *parent;
+    Account *account;
+    gboolean name_exists;
+    gboolean base_name_exists;
+    const char *base_name;
+    char *name;
 
-  g_return_val_if_fail (equity_type >= 0, NULL);
-  g_return_val_if_fail (equity_type < NUM_EQUITY_TYPES, NULL);
-  g_return_val_if_fail (currency != NULL, NULL);
-  g_return_val_if_fail (root != NULL, NULL);
+    g_return_val_if_fail (equity_type >= 0, NULL);
+    g_return_val_if_fail (equity_type < NUM_EQUITY_TYPES, NULL);
+    g_return_val_if_fail (currency != NULL, NULL);
+    g_return_val_if_fail (root != NULL, NULL);
 
-  base_name = equity_base_name (equity_type);
+    base_name = equity_base_name (equity_type);
 
-  account = gnc_account_lookup_by_name(root, base_name);
-  if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
-    account = NULL;
-
-  if (!account)
-  {
-    base_name = base_name && *base_name ? _(base_name) : "";
-
     account = gnc_account_lookup_by_name(root, base_name);
     if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
-      account = NULL;
-  }
+        account = NULL;
 
-  base_name_exists = (account != NULL);
+    if (!account)
+    {
+        base_name = base_name && *base_name ? _(base_name) : "";
 
-  if (account &&
-      gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
-    return account;
+        account = gnc_account_lookup_by_name(root, base_name);
+        if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
+            account = NULL;
+    }
 
-  name = g_strconcat (base_name, " - ",
-                      gnc_commodity_get_mnemonic (currency), NULL);
-  account = gnc_account_lookup_by_name(root, name);
-  if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
-    account = NULL;
+    base_name_exists = (account != NULL);
 
-  name_exists = (account != NULL);
+    if (account &&
+            gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
+        return account;
 
-  if (account &&
-      gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
-    return account;
+    name = g_strconcat (base_name, " - ",
+                        gnc_commodity_get_mnemonic (currency), NULL);
+    account = gnc_account_lookup_by_name(root, name);
+    if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
+        account = NULL;
 
-  /* Couldn't find one, so create it */
-  if (name_exists && base_name_exists)
-  {
-    PWARN ("equity account with unexpected currency");
-    g_free (name);
-    return NULL;
-  }
+    name_exists = (account != NULL);
 
-  if (!base_name_exists &&
-      gnc_commodity_equiv (currency, gnc_default_currency ()))
-  {
-    g_free (name);
-    name = g_strdup (base_name);
-  }
+    if (account &&
+            gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
+        return account;
 
-  parent = gnc_account_lookup_by_name(root, _("Equity"));
-  if (!parent || xaccAccountGetType (parent) != ACCT_TYPE_EQUITY)
-    parent = root;
-  g_assert(parent);
+    /* Couldn't find one, so create it */
+    if (name_exists && base_name_exists)
+    {
+        PWARN ("equity account with unexpected currency");
+        g_free (name);
+        return NULL;
+    }
 
-  account = xaccMallocAccount (gnc_account_get_book(root));
+    if (!base_name_exists &&
+            gnc_commodity_equiv (currency, gnc_default_currency ()))
+    {
+        g_free (name);
+        name = g_strdup (base_name);
+    }
 
-  xaccAccountBeginEdit (account);
+    parent = gnc_account_lookup_by_name(root, _("Equity"));
+    if (!parent || xaccAccountGetType (parent) != ACCT_TYPE_EQUITY)
+        parent = root;
+    g_assert(parent);
 
-  xaccAccountSetName (account, name);
-  xaccAccountSetType (account, ACCT_TYPE_EQUITY);
-  xaccAccountSetCommodity (account, currency);
+    account = xaccMallocAccount (gnc_account_get_book(root));
 
-  xaccAccountBeginEdit (parent);
-  gnc_account_append_child (parent, account);
-  xaccAccountCommitEdit (parent);
+    xaccAccountBeginEdit (account);
 
-  xaccAccountCommitEdit (account);
+    xaccAccountSetName (account, name);
+    xaccAccountSetType (account, ACCT_TYPE_EQUITY);
+    xaccAccountSetCommodity (account, currency);
 
-  g_free (name);
+    xaccAccountBeginEdit (parent);
+    gnc_account_append_child (parent, account);
+    xaccAccountCommitEdit (parent);
 
-  return account;
+    xaccAccountCommitEdit (account);
+
+    g_free (name);
+
+    return account;
 }
 
 gboolean
@@ -803,282 +808,289 @@
                                     time_t date,
                                     QofBook *book)
 {
-  Account *equity_account;
-  Transaction *trans;
-  Split *split;
+    Account *equity_account;
+    Transaction *trans;
+    Split *split;
 
-  if (gnc_numeric_zero_p (balance))
-    return TRUE;
+    if (gnc_numeric_zero_p (balance))
+        return TRUE;
 
-  g_return_val_if_fail (account != NULL, FALSE);
+    g_return_val_if_fail (account != NULL, FALSE);
 
-  equity_account =
-    gnc_find_or_create_equity_account (gnc_account_get_root(account),
-                                       EQUITY_OPENING_BALANCE,
-                                       xaccAccountGetCommodity (account));
-  if (!equity_account)
-    return FALSE;
+    equity_account =
+        gnc_find_or_create_equity_account (gnc_account_get_root(account),
+                                           EQUITY_OPENING_BALANCE,
+                                           xaccAccountGetCommodity (account));
+    if (!equity_account)
+        return FALSE;
 
-  xaccAccountBeginEdit (account);
-  xaccAccountBeginEdit (equity_account);
+    xaccAccountBeginEdit (account);
+    xaccAccountBeginEdit (equity_account);
 
-  trans = xaccMallocTransaction (book);
+    trans = xaccMallocTransaction (book);
 
-  xaccTransBeginEdit (trans);
+    xaccTransBeginEdit (trans);
 
-  xaccTransSetCurrency (trans, xaccAccountGetCommodity (account));
-  xaccTransSetDateSecs (trans, date);
-  xaccTransSetDescription (trans, _("Opening Balance"));
+    xaccTransSetCurrency (trans, xaccAccountGetCommodity (account));
+    xaccTransSetDateSecs (trans, date);
+    xaccTransSetDescription (trans, _("Opening Balance"));
 
-  split = xaccMallocSplit (book);
+    split = xaccMallocSplit (book);
 
-  xaccTransAppendSplit (trans, split);
-  xaccAccountInsertSplit (account, split);
+    xaccTransAppendSplit (trans, split);
+    xaccAccountInsertSplit (account, split);
 
-  xaccSplitSetAmount (split, balance);
-  xaccSplitSetValue (split, balance);
+    xaccSplitSetAmount (split, balance);
+    xaccSplitSetValue (split, balance);
 
-  balance = gnc_numeric_neg (balance);
+    balance = gnc_numeric_neg (balance);
 
-  split = xaccMallocSplit (book);
+    split = xaccMallocSplit (book);
 
-  xaccTransAppendSplit (trans, split);
-  xaccAccountInsertSplit (equity_account, split);
+    xaccTransAppendSplit (trans, split);
+    xaccAccountInsertSplit (equity_account, split);
 
-  xaccSplitSetAmount (split, balance);
-  xaccSplitSetValue (split, balance);
+    xaccSplitSetAmount (split, balance);
+    xaccSplitSetValue (split, balance);
 
-  xaccTransCommitEdit (trans);
-  xaccAccountCommitEdit (equity_account);
-  xaccAccountCommitEdit (account);
+    xaccTransCommitEdit (trans);
+    xaccAccountCommitEdit (equity_account);
+    xaccAccountCommitEdit (account);
 
-  return TRUE;
+    return TRUE;
 }
 
 static void
 gnc_lconv_set_utf8 (char **p_value, char *default_value)
 {
-  char *value = *p_value;
-  *p_value = NULL;
+    char *value = *p_value;
+    *p_value = NULL;
 
-  if ((value == NULL) || (value[0] == 0))
-    value = default_value;
+    if ((value == NULL) || (value[0] == 0))
+        value = default_value;
 
 #ifdef G_OS_WIN32
-  {
-    /* get number of resulting wide characters */
-    size_t count = mbstowcs (NULL, value, 0);
-    if (count > 0) {
-      /* malloc and convert */
-      wchar_t *wvalue = g_malloc ((count+1) * sizeof(wchar_t));
-      count = mbstowcs (wvalue, value, count+1);
-      if (count > 0) {
-        *p_value = g_utf16_to_utf8 (wvalue, -1, NULL, NULL, NULL);
-      }
-      g_free (wvalue);
+    {
+        /* get number of resulting wide characters */
+        size_t count = mbstowcs (NULL, value, 0);
+        if (count > 0)
+        {
+            /* malloc and convert */
+            wchar_t *wvalue = g_malloc ((count + 1) * sizeof(wchar_t));
+            count = mbstowcs (wvalue, value, count + 1);
+            if (count > 0)
+            {
+                *p_value = g_utf16_to_utf8 (wvalue, -1, NULL, NULL, NULL);
+            }
+            g_free (wvalue);
+        }
     }
-  }
 #else /* !G_OS_WIN32 */
-  *p_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
+    *p_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
 #endif
-  
-  if (*p_value == NULL) {
-    // The g_locale_to_utf8 conversion failed. FIXME: Should we rather
-    // use an empty string instead of the default_value? Not sure.
-    *p_value = default_value;
-  }
+
+    if (*p_value == NULL)
+    {
+        // The g_locale_to_utf8 conversion failed. FIXME: Should we rather
+        // use an empty string instead of the default_value? Not sure.
+        *p_value = default_value;
+    }
 }
 
 static void
 gnc_lconv_set_char (char *p_value, char default_value)
 {
-  if ((p_value != NULL) && (*p_value == CHAR_MAX))
-    *p_value = default_value;
+    if ((p_value != NULL) && (*p_value == CHAR_MAX))
+        *p_value = default_value;
 }
 
 struct lconv *
 gnc_localeconv (void)
 {
-  static struct lconv lc;
-  static gboolean lc_set = FALSE;
+    static struct lconv lc;
+    static gboolean lc_set = FALSE;
 
-  if (lc_set)
-    return &lc;
+    if (lc_set)
+        return &lc;
 
-  lc = *localeconv();
+    lc = *localeconv();
 
-  gnc_lconv_set_utf8(&lc.decimal_point, ".");
-  gnc_lconv_set_utf8(&lc.thousands_sep, ",");
-  gnc_lconv_set_utf8(&lc.grouping, "\003");
-  gnc_lconv_set_utf8(&lc.int_curr_symbol, "USD ");
-  gnc_lconv_set_utf8(&lc.currency_symbol, "$");
-  gnc_lconv_set_utf8(&lc.mon_decimal_point, ".");
-  gnc_lconv_set_utf8(&lc.mon_thousands_sep, ",");
-  gnc_lconv_set_utf8(&lc.mon_grouping, "\003");
-  gnc_lconv_set_utf8(&lc.negative_sign, "-");
-  gnc_lconv_set_utf8(&lc.positive_sign, "");
+    gnc_lconv_set_utf8(&lc.decimal_point, ".");
+    gnc_lconv_set_utf8(&lc.thousands_sep, ",");
+    gnc_lconv_set_utf8(&lc.grouping, "\003");
+    gnc_lconv_set_utf8(&lc.int_curr_symbol, "USD ");
+    gnc_lconv_set_utf8(&lc.currency_symbol, "$");
+    gnc_lconv_set_utf8(&lc.mon_decimal_point, ".");
+    gnc_lconv_set_utf8(&lc.mon_thousands_sep, ",");
+    gnc_lconv_set_utf8(&lc.mon_grouping, "\003");
+    gnc_lconv_set_utf8(&lc.negative_sign, "-");
+    gnc_lconv_set_utf8(&lc.positive_sign, "");
 
-  gnc_lconv_set_char(&lc.frac_digits, 2);
-  gnc_lconv_set_char(&lc.int_frac_digits, 2);
-  gnc_lconv_set_char(&lc.p_cs_precedes, 1);
-  gnc_lconv_set_char(&lc.p_sep_by_space, 0);
-  gnc_lconv_set_char(&lc.n_cs_precedes, 1);
-  gnc_lconv_set_char(&lc.n_sep_by_space, 0);
-  gnc_lconv_set_char(&lc.p_sign_posn, 1);
-  gnc_lconv_set_char(&lc.n_sign_posn, 1);
+    gnc_lconv_set_char(&lc.frac_digits, 2);
+    gnc_lconv_set_char(&lc.int_frac_digits, 2);
+    gnc_lconv_set_char(&lc.p_cs_precedes, 1);
+    gnc_lconv_set_char(&lc.p_sep_by_space, 0);
+    gnc_lconv_set_char(&lc.n_cs_precedes, 1);
+    gnc_lconv_set_char(&lc.n_sep_by_space, 0);
+    gnc_lconv_set_char(&lc.p_sign_posn, 1);
+    gnc_lconv_set_char(&lc.n_sign_posn, 1);
 
-  lc_set = TRUE;
+    lc_set = TRUE;
 
-  return &lc;
+    return &lc;
 }
 
 const char *
 gnc_locale_default_iso_currency_code (void)
 {
-  static char *code = NULL;
-  struct lconv *lc;
+    static char *code = NULL;
+    struct lconv *lc;
 
-  if (code)
-    return code;
+    if (code)
+        return code;
 
-  lc = gnc_localeconv ();
+    lc = gnc_localeconv ();
 
-  code = g_strdup (lc->int_curr_symbol);
+    code = g_strdup (lc->int_curr_symbol);
 
-  /* The int_curr_symbol includes a space at the end! Note: you
-   * can't just change "USD " to "USD" in gnc_localeconv, because
-   * that is only used if int_curr_symbol was not defined in the
-   * current locale. If it was, it will have the space! */
-  g_strstrip (code);
+    /* The int_curr_symbol includes a space at the end! Note: you
+     * can't just change "USD " to "USD" in gnc_localeconv, because
+     * that is only used if int_curr_symbol was not defined in the
+     * current locale. If it was, it will have the space! */
+    g_strstrip (code);
 
-  return code;
+    return code;
 }
 
 gnc_commodity *
 gnc_locale_default_currency_nodefault (void)
 {
-  gnc_commodity * currency;
-  gnc_commodity_table *table;
-  const char *code;
+    gnc_commodity * currency;
+    gnc_commodity_table *table;
+    const char *code;
 
-  table = gnc_get_current_commodities ();
-  code = gnc_locale_default_iso_currency_code ();
+    table = gnc_get_current_commodities ();
+    code = gnc_locale_default_iso_currency_code ();
 
-  currency = gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_CURRENCY, code);
+    currency = gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_CURRENCY, code);
 
-  /* Some very old locales (notably on win32) still announce a euro
-     currency as default, although it has been replaced by EUR in
-     2001. We use EUR as default in that case, but the user can always
-     override from gconf. */
-  if (gnc_is_euro_currency (currency))
-    currency = gnc_get_euro();
+    /* Some very old locales (notably on win32) still announce a euro
+       currency as default, although it has been replaced by EUR in
+       2001. We use EUR as default in that case, but the user can always
+       override from gconf. */
+    if (gnc_is_euro_currency (currency))
+        currency = gnc_get_euro();
 
-  return (currency ? currency : NULL);
+    return (currency ? currency : NULL);
 }
 
 gnc_commodity *
 gnc_locale_default_currency (void)
 {
-  gnc_commodity * currency = gnc_locale_default_currency_nodefault ();
+    gnc_commodity * currency = gnc_locale_default_currency_nodefault ();
 
-  return (currency ? currency :
-	  gnc_commodity_table_lookup (gnc_get_current_commodities (), 
-				      GNC_COMMODITY_NS_CURRENCY, "USD"));
+    return (currency ? currency :
+            gnc_commodity_table_lookup (gnc_get_current_commodities (),
+                                        GNC_COMMODITY_NS_CURRENCY, "USD"));
 }
 
 
 gnc_commodity *
 gnc_default_currency (void)
 {
-  gnc_commodity *currency = NULL;
-  gchar *choice, *mnemonic;
+    gnc_commodity *currency = NULL;
+    gchar *choice, *mnemonic;
 
-  if (user_default_currency)
-    return gnc_commodity_table_lookup(gnc_get_current_commodities(),
-				      GNC_COMMODITY_NS_CURRENCY,
-				      user_default_currency);
+    if (user_default_currency)
+        return gnc_commodity_table_lookup(gnc_get_current_commodities(),
+                                          GNC_COMMODITY_NS_CURRENCY,
+                                          user_default_currency);
 
-  choice = gnc_gconf_get_string(GCONF_GENERAL, KEY_CURRENCY_CHOICE, NULL);
-  if (choice && strcmp(choice, "other") == 0) {
-    mnemonic = gnc_gconf_get_string(GCONF_GENERAL, KEY_CURRENCY_OTHER, NULL);
-    currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
-					  GNC_COMMODITY_NS_CURRENCY, mnemonic);
-    DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
-    g_free(mnemonic);
-  }
-  g_free(choice);
+    choice = gnc_gconf_get_string(GCONF_GENERAL, KEY_CURRENCY_CHOICE, NULL);
+    if (choice && strcmp(choice, "other") == 0)
+    {
+        mnemonic = gnc_gconf_get_string(GCONF_GENERAL, KEY_CURRENCY_OTHER, NULL);
+        currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
+                                              GNC_COMMODITY_NS_CURRENCY, mnemonic);
+        DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
+        g_free(mnemonic);
+    }
+    g_free(choice);
 
-  if (!currency)
-    currency = gnc_locale_default_currency ();
-  if (currency) {
-    mnemonic = user_default_currency;
-    user_default_currency = g_strdup(gnc_commodity_get_mnemonic(currency));
-    g_free(mnemonic);
-  }
-  return currency;
+    if (!currency)
+        currency = gnc_locale_default_currency ();
+    if (currency)
+    {
+        mnemonic = user_default_currency;
+        user_default_currency = g_strdup(gnc_commodity_get_mnemonic(currency));
+        g_free(mnemonic);
+    }
+    return currency;
 }
 
 gnc_commodity *
 gnc_default_report_currency (void)
 {
-  gnc_commodity *currency = NULL;
-  gchar *choice, *mnemonic;
+    gnc_commodity *currency = NULL;
+    gchar *choice, *mnemonic;
 
-  if (user_report_currency)
-    return gnc_commodity_table_lookup(gnc_get_current_commodities(),
-				      GNC_COMMODITY_NS_CURRENCY,
-				      user_report_currency);
-  choice = gnc_gconf_get_string(GCONF_GENERAL_REPORT,
-				KEY_CURRENCY_CHOICE, NULL);
-  if (choice && strcmp(choice, "other") == 0) {
-    mnemonic = gnc_gconf_get_string(GCONF_GENERAL_REPORT,
-				    KEY_CURRENCY_OTHER, NULL);
-    currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
-					  GNC_COMMODITY_NS_CURRENCY, mnemonic);
-    DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
-    g_free(mnemonic);
-  }
-  g_free(choice);
+    if (user_report_currency)
+        return gnc_commodity_table_lookup(gnc_get_current_commodities(),
+                                          GNC_COMMODITY_NS_CURRENCY,
+                                          user_report_currency);
+    choice = gnc_gconf_get_string(GCONF_GENERAL_REPORT,
+                                  KEY_CURRENCY_CHOICE, NULL);
+    if (choice && strcmp(choice, "other") == 0)
+    {
+        mnemonic = gnc_gconf_get_string(GCONF_GENERAL_REPORT,
+                                        KEY_CURRENCY_OTHER, NULL);
+        currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
+                                              GNC_COMMODITY_NS_CURRENCY, mnemonic);
+        DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
+        g_free(mnemonic);
+    }
+    g_free(choice);
 
-  if (!currency)
-    currency = gnc_locale_default_currency (); 
-  if (currency) {
-    mnemonic = user_report_currency;
-    user_report_currency = g_strdup(gnc_commodity_get_mnemonic(currency));
-    g_free(mnemonic);
-  }
-  return currency;
+    if (!currency)
+        currency = gnc_locale_default_currency ();
+    if (currency)
+    {
+        mnemonic = user_report_currency;
+        user_report_currency = g_strdup(gnc_commodity_get_mnemonic(currency));
+        g_free(mnemonic);
+    }
+    return currency;
 }
 
 
 static void
 gnc_currency_changed_cb (GConfEntry *entry, gpointer user_data)
 {
-  user_default_currency = NULL;
-  user_report_currency = NULL;
-  gnc_hook_run(HOOK_CURRENCY_CHANGED, NULL);
+    user_default_currency = NULL;
+    user_report_currency = NULL;
+    gnc_hook_run(HOOK_CURRENCY_CHANGED, NULL);
 }
 
 
 /* Return the number of decimal places for this locale. */
-int 
+int
 gnc_locale_decimal_places (void)
 {
-  static gboolean got_it = FALSE;
-  static int places;
-  struct lconv *lc;
+    static gboolean got_it = FALSE;
+    static int places;
+    struct lconv *lc;
 
-  if (got_it)
-    return places;
+    if (got_it)
+        return places;
 
-  lc = gnc_localeconv();
-  places = lc->frac_digits;
+    lc = gnc_localeconv();
+    places = lc->frac_digits;
 
-  /* frac_digits is already initialized by gnc_localeconv, hopefully
-   * to a reasonable default. */
-  got_it = TRUE;
+    /* frac_digits is already initialized by gnc_localeconv, hopefully
+     * to a reasonable default. */
+    got_it = TRUE;
 
-  return places;
+    return places;
 }
 
 
@@ -1087,119 +1099,119 @@
 void
 gnc_push_locale (const char *locale)
 {
-  char *saved_locale;
+    char *saved_locale;
 
-  g_return_if_fail (locale != NULL);
+    g_return_if_fail (locale != NULL);
 
-  saved_locale = g_strdup (setlocale (LC_ALL, NULL));
-  locale_stack = g_list_prepend (locale_stack, saved_locale);
-  setlocale (LC_ALL, locale);
+    saved_locale = g_strdup (setlocale (LC_ALL, NULL));
+    locale_stack = g_list_prepend (locale_stack, saved_locale);
+    setlocale (LC_ALL, locale);
 }
 
 void
 gnc_pop_locale (void)
 {
-  char *saved_locale;
-  GList *node;
+    char *saved_locale;
+    GList *node;
 
-  g_return_if_fail (locale_stack != NULL);
+    g_return_if_fail (locale_stack != NULL);
 
-  node = locale_stack;
-  saved_locale = node->data;
+    node = locale_stack;
+    saved_locale = node->data;
 
-  setlocale (LC_ALL, saved_locale);
+    setlocale (LC_ALL, saved_locale);
 
-  locale_stack = g_list_remove_link (locale_stack, node);
-  g_list_free_1 (node);
-  g_free (saved_locale);
+    locale_stack = g_list_remove_link (locale_stack, node);
+    g_list_free_1 (node);
+    g_free (saved_locale);
 }
 
 GNCPrintAmountInfo
 gnc_default_print_info (gboolean use_symbol)
 {
-  static GNCPrintAmountInfo info;
-  static gboolean got_it = FALSE;
-  struct lconv *lc;
+    static GNCPrintAmountInfo info;
+    static gboolean got_it = FALSE;
+    struct lconv *lc;
 
-  /* These must be updated each time. */
-  info.use_symbol = use_symbol ? 1 : 0;
-  info.commodity = gnc_default_currency ();
+    /* These must be updated each time. */
+    info.use_symbol = use_symbol ? 1 : 0;
+    info.commodity = gnc_default_currency ();
 
-  if (got_it)
-    return info;
+    if (got_it)
+        return info;
 
-  lc = gnc_localeconv ();
+    lc = gnc_localeconv ();
 
-  info.max_decimal_places = lc->frac_digits;
-  info.min_decimal_places = lc->frac_digits;
+    info.max_decimal_places = lc->frac_digits;
+    info.min_decimal_places = lc->frac_digits;
 
-  info.use_separators = 1;
-  info.use_locale = 1;
-  info.monetary = 1;
-  info.force_fit = 0;
-  info.round = 0;
+    info.use_separators = 1;
+    info.use_locale = 1;
+    info.monetary = 1;
+    info.force_fit = 0;
+    info.round = 0;
 
-  got_it = TRUE;
+    got_it = TRUE;
 
-  return info;
+    return info;
 }
 
 static gboolean
 is_decimal_fraction (int fraction, guint8 *max_decimal_places_p)
 {
-  guint8 max_decimal_places = 0;
+    guint8 max_decimal_places = 0;
 
-  if (fraction <= 0)
-    return FALSE;
+    if (fraction <= 0)
+        return FALSE;
 
-  while (fraction != 1)
-  {
-    if (fraction % 10 != 0)
-      return FALSE;
+    while (fraction != 1)
+    {
+        if (fraction % 10 != 0)
+            return FALSE;
 
-    fraction = fraction / 10;
-    max_decimal_places += 1;
-  }
+        fraction = fraction / 10;
+        max_decimal_places += 1;
+    }
 
-  if (max_decimal_places_p)
-    *max_decimal_places_p = max_decimal_places;
+    if (max_decimal_places_p)
+        *max_decimal_places_p = max_decimal_places;
 
-  return TRUE;
+    return TRUE;
 }
 
 GNCPrintAmountInfo
 gnc_commodity_print_info (const gnc_commodity *commodity,
                           gboolean use_symbol)
 {
-  GNCPrintAmountInfo info;
-  gboolean is_iso;
+    GNCPrintAmountInfo info;
+    gboolean is_iso;
 
-  if (commodity == NULL)
-    return gnc_default_print_info (use_symbol);
+    if (commodity == NULL)
+        return gnc_default_print_info (use_symbol);
 
-  info.commodity = commodity;
+    info.commodity = commodity;
 
-  is_iso = gnc_commodity_is_iso (commodity);
+    is_iso = gnc_commodity_is_iso (commodity);
 
-  if (is_decimal_fraction (gnc_commodity_get_fraction (commodity),
-                           &info.max_decimal_places))
-  {
-    if (is_iso)
-      info.min_decimal_places = info.max_decimal_places;
+    if (is_decimal_fraction (gnc_commodity_get_fraction (commodity),
+                             &info.max_decimal_places))
+    {
+        if (is_iso)
+            info.min_decimal_places = info.max_decimal_places;
+        else
+            info.min_decimal_places = 0;
+    }
     else
-      info.min_decimal_places = 0;
-  }
-  else
-    info.max_decimal_places = info.min_decimal_places = 0;
+        info.max_decimal_places = info.min_decimal_places = 0;
 
-  info.use_separators = 1;
-  info.use_symbol = use_symbol ? 1 : 0;
-  info.use_locale = is_iso ? 1 : 0;
-  info.monetary = 1;
-  info.force_fit = 0;
-  info.round = 0;
+    info.use_separators = 1;
+    info.use_symbol = use_symbol ? 1 : 0;
+    info.use_locale = is_iso ? 1 : 0;
+    info.monetary = 1;
+    info.force_fit = 0;
+    info.round = 0;
 
-  return info;
+    return info;
 }
 
 static GNCPrintAmountInfo
@@ -1207,37 +1219,37 @@
                               gnc_commodity * (*efffunc)(const Account *),
                               int (*scufunc)(const Account*))
 {
-  GNCPrintAmountInfo info;
-  gboolean is_iso;
-  int scu;
+    GNCPrintAmountInfo info;
+    gboolean is_iso;
+    int scu;
 
-  if (account == NULL)
-    return gnc_default_print_info (use_symbol);
+    if (account == NULL)
+        return gnc_default_print_info (use_symbol);
 
-  info.commodity = efffunc (account);
+    info.commodity = efffunc (account);
 
-  is_iso = gnc_commodity_is_iso (info.commodity);
+    is_iso = gnc_commodity_is_iso (info.commodity);
 
-  scu = scufunc (account);
+    scu = scufunc (account);
 
-  if (is_decimal_fraction (scu, &info.max_decimal_places))
-  {
-    if (is_iso)
-      info.min_decimal_places = info.max_decimal_places;
+    if (is_decimal_fraction (scu, &info.max_decimal_places))
+    {
+        if (is_iso)
+            info.min_decimal_places = info.max_decimal_places;
+        else
+            info.min_decimal_places = 0;
+    }
     else
-      info.min_decimal_places = 0;
-  }
-  else
-    info.max_decimal_places = info.min_decimal_places = 0;
+        info.max_decimal_places = info.min_decimal_places = 0;
 
-  info.use_separators = 1;
-  info.use_symbol = use_symbol ? 1 : 0;
-  info.use_locale = is_iso ? 1 : 0;
-  info.monetary = 1;
-  info.force_fit = 0;
-  info.round = 0;
+    info.use_separators = 1;
+    info.use_symbol = use_symbol ? 1 : 0;
+    info.use_locale = is_iso ? 1 : 0;
+    info.monetary = 1;
+    info.force_fit = 0;
+    info.round = 0;
 
-  return info;
+    return info;
 }
 
 GNCPrintAmountInfo
@@ -1251,14 +1263,14 @@
 GNCPrintAmountInfo
 gnc_split_amount_print_info (Split *split, gboolean use_symbol)
 {
-  if (!split)
-  {
-    GNCPrintAmountInfo info = gnc_default_share_print_info ();
-    info.use_symbol = use_symbol;
-    return info;
-  }
+    if (!split)
+    {
+        GNCPrintAmountInfo info = gnc_default_share_print_info ();
+        info.use_symbol = use_symbol;
+        return info;
+    }
 
-  return gnc_account_print_info (xaccSplitGetAccount (split), use_symbol);
+    return gnc_account_print_info (xaccSplitGetAccount (split), use_symbol);
 }
 
 static GNCPrintAmountInfo
@@ -1284,273 +1296,278 @@
 GNCPrintAmountInfo
 gnc_default_share_print_info (void)
 {
-  static GNCPrintAmountInfo info;
-  static gboolean got_it = FALSE;
+    static GNCPrintAmountInfo info;
+    static gboolean got_it = FALSE;
 
-  if (!got_it)
-  {
-      info = gnc_default_print_info_helper (5);
-      got_it = TRUE;
-  }
+    if (!got_it)
+    {
+        info = gnc_default_print_info_helper (5);
+        got_it = TRUE;
+    }
 
-  return info;
+    return info;
 }
 
 GNCPrintAmountInfo
 gnc_share_print_info_places (int decplaces)
 {
-  GNCPrintAmountInfo info;
+    GNCPrintAmountInfo info;
 
-  info = gnc_default_share_print_info ();
-  info.max_decimal_places = decplaces;
-  info.min_decimal_places = decplaces;
-  info.force_fit = 1;
-  info.round = 1;
-  return info;
+    info = gnc_default_share_print_info ();
+    info.max_decimal_places = decplaces;
+    info.min_decimal_places = decplaces;
+    info.force_fit = 1;
+    info.round = 1;
+    return info;
 }
 
 GNCPrintAmountInfo
 gnc_default_price_print_info (void)
 {
-  static GNCPrintAmountInfo info;
-  static gboolean got_it = FALSE;
+    static GNCPrintAmountInfo info;
+    static gboolean got_it = FALSE;
 
-  if (!got_it)
-  {
-    info = gnc_default_print_info_helper (6);
-    got_it = TRUE;
-  }
+    if (!got_it)
+    {
+        info = gnc_default_print_info_helper (6);
+        got_it = TRUE;
+    }
 
-  return info;
+    return info;
 }
 
 GNCPrintAmountInfo
 gnc_integral_print_info (void)
 {
-  static GNCPrintAmountInfo info;
-  static gboolean got_it = FALSE;
+    static GNCPrintAmountInfo info;
+    static gboolean got_it = FALSE;
 
-  if (!got_it)
-  {
-    info = gnc_default_print_info_helper (0);
-    got_it = TRUE;
-  }
+    if (!got_it)
+    {
+        info = gnc_default_print_info_helper (0);
+        got_it = TRUE;
+    }
 
-  return info;
+    return info;
 }
 
 /* Utility function for printing non-negative amounts */
 static int
 PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info)
 {
-  struct lconv *lc = gnc_localeconv();
-  int num_whole_digits;
-  char temp_buf[128];
-  gnc_numeric whole, rounding;
-  int min_dp, max_dp;
-  gboolean value_is_negative, value_is_decimal;
+    struct lconv *lc = gnc_localeconv();
+    int num_whole_digits;
+    char temp_buf[128];
+    gnc_numeric whole, rounding;
+    int min_dp, max_dp;
+    gboolean value_is_negative, value_is_decimal;
 
-  g_return_val_if_fail (info != NULL, 0);
+    g_return_val_if_fail (info != NULL, 0);
 
-  if (gnc_numeric_check (val))
-  {
-    PWARN ("Bad numeric.");
-    *buf = '\0';
-    return 0;
-  }
-
-  /* Print the absolute value, but remember negativity */
-  value_is_negative = gnc_numeric_negative_p (val);
-  val = gnc_numeric_abs (val);
-
-  /* Try to print as decimal. */
-  value_is_decimal = gnc_numeric_to_decimal(&val, NULL);
-
-  /* Force at least auto_decimal_places zeros */
-  if (auto_decimal_enabled) {
-    min_dp = MAX(auto_decimal_places, info->min_decimal_places);
-    max_dp = MAX(auto_decimal_places, info->max_decimal_places);
-  } else {
-    min_dp = info->min_decimal_places;
-    max_dp = info->max_decimal_places;
-  }
-
-  /* Don to limit the number of decimal places _UNLESS_ force_fit is
-   * true. */
-  if (!info->force_fit)
-    max_dp = 99;
-
-  /* rounding? -- can only ROUND if force_fit is also true */
-  if (value_is_decimal && info->round && info->force_fit) {
-    rounding.num = 5; /* Limit the denom to 10^13 ~= 2^44, leaving max at ~524288 */
-    rounding.denom = pow(10, max_dp + 1);
-    val = gnc_numeric_add(val, rounding, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-    /* Yes, rounding up can cause overflow.  Check for it. */
-    if (gnc_numeric_check(val)) {
-        PWARN("Bad numeric from rounding.");
+    if (gnc_numeric_check (val))
+    {
+        PWARN ("Bad numeric.");
         *buf = '\0';
         return 0;
     }
-  }
 
-  /* calculate the integer part and the remainder */
-  whole = gnc_numeric_convert(val, 1, GNC_HOW_RND_TRUNC);
-  val = gnc_numeric_sub (val, whole, GNC_DENOM_AUTO, GNC_HOW_RND_NEVER);
-  if (gnc_numeric_check (val))
-  {
-    PWARN ("Problem with remainder.");
-    *buf = '\0';
-    return 0;
-  }
+    /* Print the absolute value, but remember negativity */
+    value_is_negative = gnc_numeric_negative_p (val);
+    val = gnc_numeric_abs (val);
 
-  /* print the integer part without separators */
-  sprintf(temp_buf, "%" G_GINT64_FORMAT, whole.num);
-  num_whole_digits = strlen (temp_buf);
+    /* Try to print as decimal. */
+    value_is_decimal = gnc_numeric_to_decimal(&val, NULL);
 
-  if (!info->use_separators)
-    strcpy (buf, temp_buf);
-  else
-  {
-    int group_count;
-    char *separator;
-    char *temp_ptr;
-    char *buf_ptr;
-    char *group;
-    gchar *rev_buf;
-
-    if (info->monetary)
+    /* Force at least auto_decimal_places zeros */
+    if (auto_decimal_enabled)
     {
-      separator = lc->mon_thousands_sep;
-      group = lc->mon_grouping;
+        min_dp = MAX(auto_decimal_places, info->min_decimal_places);
+        max_dp = MAX(auto_decimal_places, info->max_decimal_places);
     }
     else
     {
-      separator = lc->thousands_sep;
-      group = lc->grouping;
+        min_dp = info->min_decimal_places;
+        max_dp = info->max_decimal_places;
     }
 
-    buf_ptr = buf;
-    temp_ptr = &temp_buf[num_whole_digits - 1];
-    group_count = 0;
+    /* Don to limit the number of decimal places _UNLESS_ force_fit is
+     * true. */
+    if (!info->force_fit)
+        max_dp = 99;
 
-    while (temp_ptr != temp_buf)
+    /* rounding? -- can only ROUND if force_fit is also true */
+    if (value_is_decimal && info->round && info->force_fit)
     {
-      *buf_ptr++ = *temp_ptr--;
+        rounding.num = 5; /* Limit the denom to 10^13 ~= 2^44, leaving max at ~524288 */
+        rounding.denom = pow(10, max_dp + 1);
+        val = gnc_numeric_add(val, rounding, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+        /* Yes, rounding up can cause overflow.  Check for it. */
+        if (gnc_numeric_check(val))
+        {
+            PWARN("Bad numeric from rounding.");
+            *buf = '\0';
+            return 0;
+        }
+    }
 
-      if (*group != CHAR_MAX)
-      {
-        group_count++;
+    /* calculate the integer part and the remainder */
+    whole = gnc_numeric_convert(val, 1, GNC_HOW_RND_TRUNC);
+    val = gnc_numeric_sub (val, whole, GNC_DENOM_AUTO, GNC_HOW_RND_NEVER);
+    if (gnc_numeric_check (val))
+    {
+        PWARN ("Problem with remainder.");
+        *buf = '\0';
+        return 0;
+    }
 
-        if (group_count == *group)
+    /* print the integer part without separators */
+    sprintf(temp_buf, "%" G_GINT64_FORMAT, whole.num);
+    num_whole_digits = strlen (temp_buf);
+
+    if (!info->use_separators)
+        strcpy (buf, temp_buf);
+    else
+    {
+        int group_count;
+        char *separator;
+        char *temp_ptr;
+        char *buf_ptr;
+        char *group;
+        gchar *rev_buf;
+
+        if (info->monetary)
         {
-	  g_utf8_strncpy(buf_ptr, separator, 1);
-	  buf_ptr = g_utf8_find_next_char(buf_ptr, NULL);
-          group_count = 0;
+            separator = lc->mon_thousands_sep;
+            group = lc->mon_grouping;
+        }
+        else
+        {
+            separator = lc->thousands_sep;
+            group = lc->grouping;
+        }
 
-          /* Peek ahead at the next group code */
-          switch (group[1])
-          {
-            /* A null char means repeat the last group indefinitely */
-            case '\0':
-              break;
-            /* CHAR_MAX means no more grouping allowed */
-            case CHAR_MAX:
-              /* fall through */
-            /* Anything else means another group size */
-            default:
-              group++;
-              break;
-          }
+        buf_ptr = buf;
+        temp_ptr = &temp_buf[num_whole_digits - 1];
+        group_count = 0;
+
+        while (temp_ptr != temp_buf)
+        {
+            *buf_ptr++ = *temp_ptr--;
+
+            if (*group != CHAR_MAX)
+            {
+                group_count++;
+
+                if (group_count == *group)
+                {
+                    g_utf8_strncpy(buf_ptr, separator, 1);
+                    buf_ptr = g_utf8_find_next_char(buf_ptr, NULL);
+                    group_count = 0;
+
+                    /* Peek ahead at the next group code */
+                    switch (group[1])
+                    {
+                        /* A null char means repeat the last group indefinitely */
+                    case '\0':
+                        break;
+                        /* CHAR_MAX means no more grouping allowed */
+                    case CHAR_MAX:
+                        /* fall through */
+                        /* Anything else means another group size */
+                    default:
+                        group++;
+                        break;
+                    }
+                }
+            }
         }
-      }
-    }
 
-    /* We built the string backwards, now reverse */
-    *buf_ptr++ = *temp_ptr;
-    *buf_ptr = '\0';
-    rev_buf = g_utf8_strreverse(buf, -1);
-    strcpy (buf, rev_buf);
-    g_free(rev_buf);
-  } /* endif */
+        /* We built the string backwards, now reverse */
+        *buf_ptr++ = *temp_ptr;
+        *buf_ptr = '\0';
+        rev_buf = g_utf8_strreverse(buf, -1);
+        strcpy (buf, rev_buf);
+        g_free(rev_buf);
+    } /* endif */
 
-  /* at this point, buf contains the whole part of the number */
+    /* at this point, buf contains the whole part of the number */
 
-  /* If it's not decimal, print the fraction as an expression. */
-  if (!value_is_decimal)
-  {
-    val = gnc_numeric_reduce (val);
+    /* If it's not decimal, print the fraction as an expression. */
+    if (!value_is_decimal)
+    {
+        val = gnc_numeric_reduce (val);
 
-    if (val.denom > 0)
-        sprintf (temp_buf, "%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
-                 val.num, val.denom);
-    else
-        sprintf (temp_buf, "%" G_GINT64_FORMAT " * %" G_GINT64_FORMAT,
-                 val.num, -val.denom);
+        if (val.denom > 0)
+            sprintf (temp_buf, "%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
+                     val.num, val.denom);
+        else
+            sprintf (temp_buf, "%" G_GINT64_FORMAT " * %" G_GINT64_FORMAT,
+                     val.num, -val.denom);
 
-    if (whole.num == 0)
-      *buf = '\0';
-    else if (value_is_negative)
-      strcat(buf, " - ");
+        if (whole.num == 0)
+            *buf = '\0';
+        else if (value_is_negative)
+            strcat(buf, " - ");
+        else
+            strcat(buf, " + ");
+
+        strcat (buf, temp_buf);
+    }
     else
-      strcat(buf, " + ");
+    {
+        char *decimal_point;
+        guint8 num_decimal_places = 0;
+        char *temp_ptr = temp_buf;
 
-    strcat (buf, temp_buf);
-  }
-  else
-  {
-    char *decimal_point;
-    guint8 num_decimal_places = 0;
-    char *temp_ptr = temp_buf;
+        decimal_point = info->monetary
+                        ? lc->mon_decimal_point
+                        : lc->decimal_point;
+        g_utf8_strncpy(temp_ptr, decimal_point, 1);
+        temp_ptr = g_utf8_find_next_char(temp_ptr, NULL);
 
-    decimal_point = info->monetary
-        ? lc->mon_decimal_point
-        : lc->decimal_point;
-    g_utf8_strncpy(temp_ptr, decimal_point, 1);
-    temp_ptr = g_utf8_find_next_char(temp_ptr, NULL);
+        while (!gnc_numeric_zero_p (val)
+                && (val.denom != 1)
+                && (num_decimal_places < max_dp))
+        {
+            gint64 digit;
 
-    while (!gnc_numeric_zero_p (val)
-           && (val.denom != 1)
-           && (num_decimal_places < max_dp))
-    {
-      gint64 digit;
+            val.denom = val.denom / 10;
 
-      val.denom = val.denom / 10;
+            digit = val.num / val.denom;
 
-      digit = val.num / val.denom;
+            *temp_ptr++ = digit + '0';
+            num_decimal_places++;
 
-      *temp_ptr++ = digit + '0';
-      num_decimal_places++;
+            val.num = val.num - (digit * val.denom);
+        }
 
-      val.num = val.num - (digit * val.denom);
-    }
+        while (num_decimal_places < min_dp)
+        {
+            *temp_ptr++ = '0';
+            num_decimal_places++;
+        }
 
-    while (num_decimal_places < min_dp)
-    {
-      *temp_ptr++ = '0';
-      num_decimal_places++;
-    }
+        /* cap the end and move to the last character */
+        *temp_ptr-- = '\0';
 
-    /* cap the end and move to the last character */
-    *temp_ptr-- = '\0';
+        /* Here we strip off trailing decimal zeros per the argument. */
+        while (*temp_ptr == '0' && num_decimal_places > min_dp)
+        {
+            *temp_ptr-- = '\0';
+            num_decimal_places--;
+        }
 
-    /* Here we strip off trailing decimal zeros per the argument. */
-    while (*temp_ptr == '0' && num_decimal_places > min_dp)
-    {
-      *temp_ptr-- = '\0';
-      num_decimal_places--;
-    }
+        if (num_decimal_places > max_dp)
+        {
+            PWARN ("max_decimal_places too small; limit %d, value %s%s",
+                   info->max_decimal_places, buf, temp_buf);
+        }
 
-    if (num_decimal_places > max_dp)
-    {
-      PWARN ("max_decimal_places too small; limit %d, value %s%s",
-	     info->max_decimal_places, buf, temp_buf);
+        if (num_decimal_places > 0)
+            strcat (buf, temp_buf);
     }
 
-    if (num_decimal_places > 0)
-      strcat (buf, temp_buf);
-  }
-
-  return strlen(buf);
+    return strlen(buf);
 }
 
 /**
@@ -1559,158 +1576,158 @@
 int
 xaccSPrintAmount (char * bufp, gnc_numeric val, GNCPrintAmountInfo info)
 {
-   struct lconv *lc;
+    struct lconv *lc;
 
-   char *orig_bufp = bufp;
-   const char *currency_symbol;
-   const char *sign;
+    char *orig_bufp = bufp;
+    const char *currency_symbol;
+    const char *sign;
 
-   char cs_precedes;
-   char sep_by_space;
-   char sign_posn;
+    char cs_precedes;
+    char sep_by_space;
+    char sign_posn;
 
-   gboolean print_sign = TRUE;
-   gboolean is_shares = FALSE;
-   gboolean print_absolute = FALSE;
+    gboolean print_sign = TRUE;
+    gboolean is_shares = FALSE;
+    gboolean print_absolute = FALSE;
 
-   if (!bufp)
-     return 0;
+    if (!bufp)
+        return 0;
 
-   lc = gnc_localeconv();
+    lc = gnc_localeconv();
 
-   if (info.use_symbol)
-   {
-     /* There was a bug here: don't use gnc_locale_default_currency */
-     if (gnc_commodity_equiv (info.commodity, 
-			      gnc_locale_default_currency_nodefault ()))
-     {
-       currency_symbol = lc->currency_symbol;
-     }
-     else
-     {
-       if (info.commodity && !gnc_commodity_is_iso (info.commodity))
-         is_shares = TRUE;
+    if (info.use_symbol)
+    {
+        /* There was a bug here: don't use gnc_locale_default_currency */
+        if (gnc_commodity_equiv (info.commodity,
+                                 gnc_locale_default_currency_nodefault ()))
+        {
+            currency_symbol = lc->currency_symbol;
+        }
+        else
+        {
+            if (info.commodity && !gnc_commodity_is_iso (info.commodity))
+                is_shares = TRUE;
 
-       currency_symbol = gnc_commodity_get_mnemonic (info.commodity);
-       info.use_locale = 0;
-     }
+            currency_symbol = gnc_commodity_get_mnemonic (info.commodity);
+            info.use_locale = 0;
+        }
 
-     if (currency_symbol == NULL)
-       currency_symbol = "";
-   }
-   else
-     currency_symbol = NULL;
+        if (currency_symbol == NULL)
+            currency_symbol = "";
+    }
+    else
+        currency_symbol = NULL;
 
-   if (!info.use_locale)
-   {
-     cs_precedes = is_shares ? 0 : 1;
-     sep_by_space = 1;
-   }
-   else
-   {
-     if (gnc_numeric_negative_p (val))
-     {
-       cs_precedes  = lc->n_cs_precedes;
-       sep_by_space = lc->n_sep_by_space;
-     }
-     else
-     {
-       cs_precedes  = lc->p_cs_precedes;
-       sep_by_space = lc->p_sep_by_space;
-     }
-   }
+    if (!info.use_locale)
+    {
+        cs_precedes = is_shares ? 0 : 1;
+        sep_by_space = 1;
+    }
+    else
+    {
+        if (gnc_numeric_negative_p (val))
+        {
+            cs_precedes  = lc->n_cs_precedes;
+            sep_by_space = lc->n_sep_by_space;
+        }
+        else
+        {
+            cs_precedes  = lc->p_cs_precedes;
+            sep_by_space = lc->p_sep_by_space;
+        }
+    }
 
-   if (gnc_numeric_negative_p (val))
-   {
-     sign = lc->negative_sign;
-     sign_posn = lc->n_sign_posn;
-   }
-   else
-   {
-     sign = lc->positive_sign;
-     sign_posn = lc->p_sign_posn;
-   }
+    if (gnc_numeric_negative_p (val))
+    {
+        sign = lc->negative_sign;
+        sign_posn = lc->n_sign_posn;
+    }
+    else
+    {
+        sign = lc->positive_sign;
+        sign_posn = lc->p_sign_posn;
+    }
 
-   if (gnc_numeric_zero_p (val) || (sign == NULL) || (sign[0] == 0))
-     print_sign = FALSE;
+    if (gnc_numeric_zero_p (val) || (sign == NULL) || (sign[0] == 0))
+        print_sign = FALSE;
 
-   /* See if we print sign now */
-   if (print_sign && (sign_posn == 1))
-     bufp = g_stpcpy(bufp, sign);
+    /* See if we print sign now */
+    if (print_sign && (sign_posn == 1))
+        bufp = g_stpcpy(bufp, sign);
 
-   /* Now see if we print currency */
-   if (cs_precedes)
-   {
-     /* See if we print sign now */
-     if (print_sign && (sign_posn == 3))
-       bufp = g_stpcpy(bufp, sign);
+    /* Now see if we print currency */
+    if (cs_precedes)
+    {
+        /* See if we print sign now */
+        if (print_sign && (sign_posn == 3))
+            bufp = g_stpcpy(bufp, sign);
 
-     if (info.use_symbol)
-     {
-       bufp = g_stpcpy(bufp, currency_symbol);
-       if (sep_by_space)
-         bufp = g_stpcpy(bufp, " ");
-     }
+        if (info.use_symbol)
+        {
+            bufp = g_stpcpy(bufp, currency_symbol);
+            if (sep_by_space)
+                bufp = g_stpcpy(bufp, " ");
+        }
 
-     /* See if we print sign now */
-     if (print_sign && (sign_posn == 4))
-       bufp = g_stpcpy(bufp, sign);
-   }
+        /* See if we print sign now */
+        if (print_sign && (sign_posn == 4))
+            bufp = g_stpcpy(bufp, sign);
+    }
 
-   /* Now see if we print parentheses */
-   if (print_sign && (sign_posn == 0))
-   {
-     bufp = g_stpcpy(bufp, "(");
-     print_absolute = TRUE;
-   }
+    /* Now see if we print parentheses */
+    if (print_sign && (sign_posn == 0))
+    {
+        bufp = g_stpcpy(bufp, "(");
+        print_absolute = TRUE;
+    }
 
-   /* Now print the value */
-   bufp += PrintAmountInternal(bufp,
-                               print_absolute? gnc_numeric_abs(val) : val,
-                               &info);
+    /* Now print the value */
+    bufp += PrintAmountInternal(bufp,
+                                print_absolute ? gnc_numeric_abs(val) : val,
+                                &info);
 
-   /* Now see if we print parentheses */
-   if (print_sign && (sign_posn == 0))
-     bufp = g_stpcpy(bufp, ")");
+    /* Now see if we print parentheses */
+    if (print_sign && (sign_posn == 0))
+        bufp = g_stpcpy(bufp, ")");
 
-   /* Now see if we print currency */
-   if (!cs_precedes)
-   {
-     /* See if we print sign now */
-     if (print_sign && (sign_posn == 3))
-       bufp = g_stpcpy(bufp, sign);
+    /* Now see if we print currency */
+    if (!cs_precedes)
+    {
+        /* See if we print sign now */
+        if (print_sign && (sign_posn == 3))
+            bufp = g_stpcpy(bufp, sign);
 
-     if (info.use_symbol)
-     {
-       if (sep_by_space)
-         bufp = g_stpcpy(bufp, " ");
-       bufp = g_stpcpy(bufp, currency_symbol);
-     }
+        if (info.use_symbol)
+        {
+            if (sep_by_space)
+                bufp = g_stpcpy(bufp, " ");
+            bufp = g_stpcpy(bufp, currency_symbol);
+        }
 
-     /* See if we print sign now */
-     if (print_sign && (sign_posn == 4))
-       bufp = g_stpcpy(bufp, sign);
-   }
+        /* See if we print sign now */
+        if (print_sign && (sign_posn == 4))
+            bufp = g_stpcpy(bufp, sign);
+    }
 
-   /* See if we print sign now */
-   if (print_sign && (sign_posn == 2))
-     bufp = g_stpcpy(bufp, sign);
+    /* See if we print sign now */
+    if (print_sign && (sign_posn == 2))
+        bufp = g_stpcpy(bufp, sign);
 
-   /* return length of printed string */
-   return (bufp - orig_bufp);
+    /* return length of printed string */
+    return (bufp - orig_bufp);
 }
 
 const char *
 xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info)
 {
-  /* hack alert -- this is not thread safe ... */
-  static char buf[1024];
+    /* hack alert -- this is not thread safe ... */
+    static char buf[1024];
 
-  if (!xaccSPrintAmount (buf, val, info))
-      buf[0] = '\0';
+    if (!xaccSPrintAmount (buf, val, info))
+        buf[0] = '\0';
 
-  /* its OK to return buf, since we declared it static */
-  return buf;
+    /* its OK to return buf, since we declared it static */
+    return buf;
 }
 
 
@@ -1727,141 +1744,151 @@
    wrong. For this reason, we don't even start to pretend a
    word-by-word translation would be of any use, so we don't mark any
    of these strings for translation. cstim, 2007-04-15. */
-static gchar *small_numbers[] = {
-  /* Translators: This section is for generating the "amount, in
-     words" field when printing a check. This function gets the
-     wording right for English, but unfortunately not for most other
-     languages. Decide for yourself whether the check printing is
-     actually needed in your language; if not, you can safely skip the
-     translation of all of these strings.  */
-  "Zero", "One", "Two", "Three", "Four",
-  "Five", "Six", "Seven", "Eight", "Nine",
-  "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
-  "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen",
-  "Twenty"};
-static gchar *medium_numbers[] = {
-  "Zero", "Ten", "Twenty", "Thirty", "Forty",
-  "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
-static gchar *big_numbers[] = {
-  /* Translators: This is the word for the number 10^2 */
-  "Hundred",
-  /* Translators: This is the word for the number 10^3 */
-  "Thousand",
-  /* Translators: This is the word for the number 10^6, one thousand
-     thousands. */
-  "Million",
-  /* Translators: This is the word for the number 10^9, one thousand
-     millions. WATCH OUT: In British english and many other languages
-     this word is used for 10^12 which is one million millions! In
-     contrast to this, here in GnuCash this is used in the American
-     english meaning of 10^9.  */
-  "Billion",
-  /* Translators: This is the word for the number 10^12, one million
-     millions. */
-  "Trillion",
-  /* Translators: This is the word for the number 10^15 */
-  "Quadrillion",
-  /* Translators: This is the word for the number 10^18 */
-  "Quintillion"};
+static gchar *small_numbers[] =
+{
+    /* Translators: This section is for generating the "amount, in
+       words" field when printing a check. This function gets the
+       wording right for English, but unfortunately not for most other
+       languages. Decide for yourself whether the check printing is
+       actually needed in your language; if not, you can safely skip the
+       translation of all of these strings.  */
+    "Zero", "One", "Two", "Three", "Four",
+    "Five", "Six", "Seven", "Eight", "Nine",
+    "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
+    "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen",
+    "Twenty"
+};
+static gchar *medium_numbers[] =
+{
+    "Zero", "Ten", "Twenty", "Thirty", "Forty",
+    "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"
+};
+static gchar *big_numbers[] =
+{
+    /* Translators: This is the word for the number 10^2 */
+    "Hundred",
+    /* Translators: This is the word for the number 10^3 */
+    "Thousand",
+    /* Translators: This is the word for the number 10^6, one thousand
+       thousands. */
+    "Million",
+    /* Translators: This is the word for the number 10^9, one thousand
+       millions. WATCH OUT: In British english and many other languages
+       this word is used for 10^12 which is one million millions! In
+       contrast to this, here in GnuCash this is used in the American
+       english meaning of 10^9.  */
+    "Billion",
+    /* Translators: This is the word for the number 10^12, one million
+       millions. */
+    "Trillion",
+    /* Translators: This is the word for the number 10^15 */
+    "Quadrillion",
+    /* Translators: This is the word for the number 10^18 */
+    "Quintillion"
+};
 
 static gchar *
 integer_to_words(gint64 val)
 {
-  gint64 log_val, pow_val, this_part;
-  GString *result;
-  gchar *tmp;
+    gint64 log_val, pow_val, this_part;
+    GString *result;
+    gchar *tmp;
 
-  if (val == 0)
-    return g_strdup("zero");
-  if (val < 0)
-    val = -val;
+    if (val == 0)
+        return g_strdup("zero");
+    if (val < 0)
+        val = -val;
 
-  result = g_string_sized_new(100);
+    result = g_string_sized_new(100);
 
-  while (val >= 1000) {
-    log_val = log10(val) / 3 + FUDGE;
-    pow_val = exp(log_val * 3 * G_LN10) + FUDGE;
-    this_part = val / pow_val;
-    val -= this_part * pow_val;
-    tmp = integer_to_words(this_part);
-    g_string_append_printf(result, "%s %s ", tmp,
-                           gettext(big_numbers[log_val]));
-    g_free(tmp);
-  }
+    while (val >= 1000)
+    {
+        log_val = log10(val) / 3 + FUDGE;
+        pow_val = exp(log_val * 3 * G_LN10) + FUDGE;
+        this_part = val / pow_val;
+        val -= this_part * pow_val;
+        tmp = integer_to_words(this_part);
+        g_string_append_printf(result, "%s %s ", tmp,
+                               gettext(big_numbers[log_val]));
+        g_free(tmp);
+    }
 
-  if (val >= 100) {
-    this_part = val / 100;
-    val -= this_part * 100;
-    g_string_append_printf(result, "%s %s ",
-                           gettext(small_numbers[this_part]),
-                           gettext(big_numbers[0]));
-  }
+    if (val >= 100)
+    {
+        this_part = val / 100;
+        val -= this_part * 100;
+        g_string_append_printf(result, "%s %s ",
+                               gettext(small_numbers[this_part]),
+                               gettext(big_numbers[0]));
+    }
 
-  if (val > 20) {
-    this_part = val / 10;
-    val -= this_part * 10;
-    g_string_append(result, gettext(medium_numbers[this_part]));
-    g_string_append_c(result, ' ');
-  }
+    if (val > 20)
+    {
+        this_part = val / 10;
+        val -= this_part * 10;
+        g_string_append(result, gettext(medium_numbers[this_part]));
+        g_string_append_c(result, ' ');
+    }
 
-  if (val > 0) {
-    this_part = val;
-    val -= this_part;
-    g_string_append(result, gettext(small_numbers[this_part]));
-    g_string_append_c(result, ' ');
-  }
+    if (val > 0)
+    {
+        this_part = val;
+        val -= this_part;
+        g_string_append(result, gettext(small_numbers[this_part]));
+        g_string_append_c(result, ' ');
+    }
 
-  result = g_string_truncate(result, result->len - 1);
-  return g_string_free(result, FALSE);
+    result = g_string_truncate(result, result->len - 1);
+    return g_string_free(result, FALSE);
 }
 
 gchar *
 number_to_words(gdouble val, gint64 denom)
 {
-  gint64 int_part, frac_part;
-  gchar *int_string, *nomin_string, *denom_string, *full_string;
+    gint64 int_part, frac_part;
+    gchar *int_string, *nomin_string, *denom_string, *full_string;
 
-  if (val < 0) val = -val;
-  if (denom < 0) denom = -denom;
+    if (val < 0) val = -val;
+    if (denom < 0) denom = -denom;
 
-  int_part = trunc(val);
-  frac_part = round((val - int_part) * denom);
+    int_part = trunc(val);
+    frac_part = round((val - int_part) * denom);
 
-  int_string = integer_to_words(int_part);
-  /* Inside of the gettext macro _(...) we must not use any macros but
-     only plain string literals. For this reason, convert the strings
-     separately. */
-  nomin_string = g_strdup_printf("%" G_GINT64_FORMAT, frac_part);
-  denom_string = g_strdup_printf("%" G_GINT64_FORMAT, denom);
-  full_string =
-    /* Translators: This is for the "amount, in words" field in check
-       printing. The first %s is the integer amount of dollars (or
-       whatever currency), the second and third %s the cent amount as
-       a fraction, e.g. 47/100.  */
-    g_strdup_printf("%s and %s/%s",
-		    int_string, nomin_string, denom_string);
-  g_free(int_string);
-  g_free(nomin_string);
-  g_free(denom_string);
-  return full_string;
+    int_string = integer_to_words(int_part);
+    /* Inside of the gettext macro _(...) we must not use any macros but
+       only plain string literals. For this reason, convert the strings
+       separately. */
+    nomin_string = g_strdup_printf("%" G_GINT64_FORMAT, frac_part);
+    denom_string = g_strdup_printf("%" G_GINT64_FORMAT, denom);
+    full_string =
+        /* Translators: This is for the "amount, in words" field in check
+           printing. The first %s is the integer amount of dollars (or
+           whatever currency), the second and third %s the cent amount as
+           a fraction, e.g. 47/100.  */
+        g_strdup_printf("%s and %s/%s",
+                        int_string, nomin_string, denom_string);
+    g_free(int_string);
+    g_free(nomin_string);
+    g_free(denom_string);
+    return full_string;
 }
 
 gchar *
 numeric_to_words(gnc_numeric val)
 {
-  return number_to_words(gnc_numeric_to_double(val),
-                         gnc_numeric_denom(val));
+    return number_to_words(gnc_numeric_to_double(val),
+                           gnc_numeric_denom(val));
 }
 
 const gchar *
 printable_value (gdouble val, gint denom)
 {
-  GNCPrintAmountInfo info;
-  gnc_numeric num;
+    GNCPrintAmountInfo info;
+    gnc_numeric num;
 
-  num = gnc_numeric_create(round(val * denom), denom);
-  info = gnc_share_print_info_places(log10(denom));
-  return xaccPrintAmount (num, info);
+    num = gnc_numeric_create(round(val * denom), denom);
+    info = gnc_share_print_info_places(log10(denom));
+    return xaccPrintAmount (num, info);
 }
 
 
@@ -1880,14 +1907,14 @@
 /* Parsing state machine states */
 typedef enum
 {
-  START_ST,       /* Parsing initial whitespace */
-  NEG_ST,         /* Parsed a negative sign or a left paren */
-  PRE_GROUP_ST,   /* Parsing digits before grouping and decimal characters */
-  START_GROUP_ST, /* Start of a digit group encountered (possibly) */
-  IN_GROUP_ST,    /* Within a digit group */
-  FRAC_ST,        /* Parsing the fractional portion of a number */
-  DONE_ST,        /* Finished, number is correct module grouping constraints */
-  NO_NUM_ST       /* Finished, number was malformed */
+    START_ST,       /* Parsing initial whitespace */
+    NEG_ST,         /* Parsed a negative sign or a left paren */
+    PRE_GROUP_ST,   /* Parsing digits before grouping and decimal characters */
+    START_GROUP_ST, /* Start of a digit group encountered (possibly) */
+    IN_GROUP_ST,    /* Within a digit group */
+    FRAC_ST,        /* Parsing the fractional portion of a number */
+    DONE_ST,        /* Finished, number is correct module grouping constraints */
+    NO_NUM_ST       /* Finished, number was malformed */
 } ParseState;
 
 #define done_state(state) (((state) == DONE_ST) || ((state) == NO_NUM_ST))
@@ -1897,541 +1924,543 @@
 long long int
 multiplier (int num_decimals)
 {
-  switch (num_decimals)
-  {
+    switch (num_decimals)
+    {
     case 8:
-      return 100000000;
+        return 100000000;
     case 7:
-      return 10000000;
+        return 10000000;
     case 6:
-      return 1000000;
+        return 1000000;
     case 5:
-      return 100000;
+        return 100000;
     case 4:
-      return 10000;
+        return 10000;
     case 3:
-      return 1000;
+        return 1000;
     case 2:
-      return 100;
+        return 100;
     case 1:
-      return 10;
+        return 10;
     default:
-      PERR("bad fraction length");
-      g_assert_not_reached();
-      break;
-  }
+        PERR("bad fraction length");
+        g_assert_not_reached();
+        break;
+    }
 
-  return 1;
+    return 1;
 }
 
 gboolean
 xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result,
                  char **endstr)
 {
-  struct lconv *lc = gnc_localeconv();
+    struct lconv *lc = gnc_localeconv();
 
-  gunichar negative_sign;
-  gunichar decimal_point;
-  gunichar group_separator;
-  char *group;
+    gunichar negative_sign;
+    gunichar decimal_point;
+    gunichar group_separator;
+    char *group;
 
-  negative_sign = g_utf8_get_char(lc->negative_sign);
-  if (monetary)
-  {
-    group_separator = g_utf8_get_char(lc->mon_thousands_sep);
-    decimal_point = g_utf8_get_char(lc->mon_decimal_point);
-    group = lc->mon_grouping;
-  }
-  else
-  {
-    group_separator = g_utf8_get_char(lc->thousands_sep);
-    decimal_point = g_utf8_get_char(lc->decimal_point);
-    group = lc->grouping;
-  }
+    negative_sign = g_utf8_get_char(lc->negative_sign);
+    if (monetary)
+    {
+        group_separator = g_utf8_get_char(lc->mon_thousands_sep);
+        decimal_point = g_utf8_get_char(lc->mon_decimal_point);
+        group = lc->mon_grouping;
+    }
+    else
+    {
+        group_separator = g_utf8_get_char(lc->thousands_sep);
+        decimal_point = g_utf8_get_char(lc->decimal_point);
+        group = lc->grouping;
+    }
 
-  return xaccParseAmountExtended(in_str, monetary, negative_sign, decimal_point,
-				 group_separator, group, NULL, result, endstr);
+    return xaccParseAmountExtended(in_str, monetary, negative_sign, decimal_point,
+                                   group_separator, group, NULL, result, endstr);
 }
 
-/* Note: xaccParseAmountExtended causes test-print-parse-amount 
+/* Note: xaccParseAmountExtended causes test-print-parse-amount
 to fail if QOF_SCANF_LLD is simply replaced by G_GINT64_FORMAT. Why?
 A: Because scanf and printf use different symbols for 64-bit numbers.
 */
 gboolean
 xaccParseAmountExtended (const char * in_str, gboolean monetary,
-			 gunichar negative_sign, gunichar decimal_point,
-			 gunichar group_separator, char *group, char *ignore_list,
-			 gnc_numeric *result, char **endstr)
+                         gunichar negative_sign, gunichar decimal_point,
+                         gunichar group_separator, char *group, char *ignore_list,
+                         gnc_numeric *result, char **endstr)
 {
-  gboolean is_negative;
-  gboolean got_decimal;
-  gboolean need_paren;
-  GList * group_data;
-  long long int numer;
-  long long int denom;
-  int count, group_count;
+    gboolean is_negative;
+    gboolean got_decimal;
+    gboolean need_paren;
+    GList * group_data;
+    long long int numer;
+    long long int denom;
+    int count, group_count;
 
-  ParseState state;
+    ParseState state;
 
-  const gchar *in;
-  gunichar uc;
-  gchar *out_str;
-  gchar *out;
+    const gchar *in;
+    gunichar uc;
+    gchar *out_str;
+    gchar *out;
 
-  /* Initialize *endstr to in_str */
-  if (endstr != NULL)
-    *endstr = (char *) in_str;
+    /* Initialize *endstr to in_str */
+    if (endstr != NULL)
+        *endstr = (char *) in_str;
 
-  if (in_str == NULL)
-    return FALSE;
+    if (in_str == NULL)
+        return FALSE;
 
-  if (!g_utf8_validate(in_str, -1, &in)) {
-    printf("Invalid utf8 string '%s'. Bad character at position %ld.\n",
-	   in_str, g_utf8_pointer_to_offset (in_str, in));
-    return FALSE;
-  }
+    if (!g_utf8_validate(in_str, -1, &in))
+    {
+        printf("Invalid utf8 string '%s'. Bad character at position %ld.\n",
+               in_str, g_utf8_pointer_to_offset (in_str, in));
+        return FALSE;
+    }
 
-  /* 'out_str' will be used to store digits for numeric conversion.
-   * 'out' will be used to traverse out_str. */
-  out = out_str = g_new(gchar, strlen(in_str) + 128);
+    /* 'out_str' will be used to store digits for numeric conversion.
+     * 'out' will be used to traverse out_str. */
+    out = out_str = g_new(gchar, strlen(in_str) + 128);
 
-  /* 'in' is used to traverse 'in_str'. */
-  in = in_str;
+    /* 'in' is used to traverse 'in_str'. */
+    in = in_str;
 
-  is_negative = FALSE;
-  got_decimal = FALSE;
-  need_paren = FALSE;
-  group_data = NULL;
-  group_count = 0;
-  numer = 0;
-  denom = 1;
+    is_negative = FALSE;
+    got_decimal = FALSE;
+    need_paren = FALSE;
+    group_data = NULL;
+    group_count = 0;
+    numer = 0;
+    denom = 1;
 
-  /* Initialize the state machine */
-  state = START_ST;
+    /* Initialize the state machine */
+    state = START_ST;
 
-  /* This while loop implements a state machine for parsing numbers. */
-  while (TRUE)
-  {
-    ParseState next_state = state;
+    /* This while loop implements a state machine for parsing numbers. */
+    while (TRUE)
+    {
+        ParseState next_state = state;
 
-    uc = g_utf8_get_char(in);
+        uc = g_utf8_get_char(in);
 
-    /* Ignore anything in the 'ignore list' */
-      if (ignore_list && uc && g_utf8_strchr(ignore_list, -1, uc) != NULL) {
-      in = g_utf8_next_char(in);
-      continue;
-    }
+        /* Ignore anything in the 'ignore list' */
+        if (ignore_list && uc && g_utf8_strchr(ignore_list, -1, uc) != NULL)
+        {
+            in = g_utf8_next_char(in);
+            continue;
+        }
 
-    /* Note we never need to check for the end of 'in_str' explicitly.
-     * The 'else' clauses on all the state transitions will handle that. */
-    switch (state)
-    {
-      /* START_ST means we have parsed 0 or more whitespace characters */
-      case START_ST:
-        if (g_unichar_isdigit(uc))
+        /* Note we never need to check for the end of 'in_str' explicitly.
+         * The 'else' clauses on all the state transitions will handle that. */
+        switch (state)
         {
-          count = g_unichar_to_utf8(uc, out);
-	  out += count; /* we record the digits themselves in out_str
+            /* START_ST means we have parsed 0 or more whitespace characters */
+        case START_ST:
+            if (g_unichar_isdigit(uc))
+            {
+                count = g_unichar_to_utf8(uc, out);
+                out += count; /* we record the digits themselves in out_str
                          * for later conversion by libc routines */
-          next_state = PRE_GROUP_ST;
-        }
-        else if (uc == decimal_point)
-        {
-          next_state = FRAC_ST;
-        }
-        else if (g_unichar_isspace(uc))
-        {
-        }
-        else if (uc == negative_sign)
-        {
-          is_negative = TRUE;
-          next_state = NEG_ST;
-        }
-        else if (uc == '(')
-        {
-          is_negative = TRUE;
-          need_paren = TRUE;
-          next_state = NEG_ST;
-        }
-        else
-        {
-          next_state = NO_NUM_ST;
-        }
+                next_state = PRE_GROUP_ST;
+            }
+            else if (uc == decimal_point)
+            {
+                next_state = FRAC_ST;
+            }
+            else if (g_unichar_isspace(uc))
+            {
+            }
+            else if (uc == negative_sign)
+            {
+                is_negative = TRUE;
+                next_state = NEG_ST;
+            }
+            else if (uc == '(')
+            {
+                is_negative = TRUE;
+                need_paren = TRUE;
+                next_state = NEG_ST;
+            }
+            else
+            {
+                next_state = NO_NUM_ST;
+            }
 
-        break;
+            break;
 
-      /* NEG_ST means we have just parsed a negative sign. For now,
-       * we only recognize formats where the negative sign comes first. */
-      case NEG_ST:
-        if (g_unichar_isdigit(uc))
-        {
-          count = g_unichar_to_utf8(uc, out);
-	  out += count;
-          next_state = PRE_GROUP_ST;
-        }
-        else if (uc == decimal_point)
-        {
-          next_state = FRAC_ST;
-        }
-        else if (g_unichar_isspace(uc))
-        {
-        }
-        else
-        {
-          next_state = NO_NUM_ST;
-        }
+            /* NEG_ST means we have just parsed a negative sign. For now,
+             * we only recognize formats where the negative sign comes first. */
+        case NEG_ST:
+            if (g_unichar_isdigit(uc))
+            {
+                count = g_unichar_to_utf8(uc, out);
+                out += count;
+                next_state = PRE_GROUP_ST;
+            }
+            else if (uc == decimal_point)
+            {
+                next_state = FRAC_ST;
+            }
+            else if (g_unichar_isspace(uc))
+            {
+            }
+            else
+            {
+                next_state = NO_NUM_ST;
+            }
 
-        break;
+            break;
 
-      /* PRE_GROUP_ST means we have started parsing the number, but
-       * have not encountered a decimal point or a grouping character. */
-      case PRE_GROUP_ST:
-        if (g_unichar_isdigit(uc))
-        {
-          count = g_unichar_to_utf8(uc, out);
-	  out += count;
-        }
-        else if (uc == decimal_point)
-        {
-          next_state = FRAC_ST;
-        }
-        else if (uc == group_separator)
-        {
-          next_state = START_GROUP_ST;
-        }
-        else if (uc == ')' && need_paren)
-        {
-          next_state = DONE_ST;
-          need_paren = FALSE;
-        }
-        else
-        {
-          next_state = DONE_ST;
-        }
+            /* PRE_GROUP_ST means we have started parsing the number, but
+             * have not encountered a decimal point or a grouping character. */
+        case PRE_GROUP_ST:
+            if (g_unichar_isdigit(uc))
+            {
+                count = g_unichar_to_utf8(uc, out);
+                out += count;
+            }
+            else if (uc == decimal_point)
+            {
+                next_state = FRAC_ST;
+            }
+            else if (uc == group_separator)
+            {
+                next_state = START_GROUP_ST;
+            }
+            else if (uc == ')' && need_paren)
+            {
+                next_state = DONE_ST;
+                need_paren = FALSE;
+            }
+            else
+            {
+                next_state = DONE_ST;
+            }
 
-        break;
+            break;
 
-      /* START_GROUP_ST means we have just parsed a group character.
-       * Note that group characters might be whitespace!!! In general,
-       * if a decimal point or a group character is whitespace, we
-       * try to interpret it in the fashion that will allow parsing
-       * of the current number to continue. */
-      case START_GROUP_ST:
-        if (g_unichar_isdigit(uc))
-        {
-          count = g_unichar_to_utf8(uc, out);
-	  out += count;
-          group_count++; /* We record the number of digits
+            /* START_GROUP_ST means we have just parsed a group character.
+             * Note that group characters might be whitespace!!! In general,
+             * if a decimal point or a group character is whitespace, we
+             * try to interpret it in the fashion that will allow parsing
+             * of the current number to continue. */
+        case START_GROUP_ST:
+            if (g_unichar_isdigit(uc))
+            {
+                count = g_unichar_to_utf8(uc, out);
+                out += count;
+                group_count++; /* We record the number of digits
                           * in the group for later checking. */
-          next_state = IN_GROUP_ST;
-        }
-        else if (uc == decimal_point)
-        {
-          /* If we now get a decimal point, and both the decimal
-           * and the group separator are also whitespace, assume
-           * the last group separator was actually whitespace and
-           * stop parsing. Otherwise, there's a problem. */
-          if (g_unichar_isspace(group_separator) &&
-	      g_unichar_isspace(decimal_point))
-            next_state = DONE_ST;
-          else
-            next_state = NO_NUM_ST;
-        }
-        else if (uc == ')' && need_paren)
-        {
-          if (g_unichar_isspace(group_separator))
-          {
-            next_state = DONE_ST;
-            need_paren = FALSE;
-          }
-          else
-            next_state = NO_NUM_ST;
-        }
-        else
-        {
-          /* If the last group separator is also whitespace,
-           * assume it was intended as such and stop parsing.
-           * Otherwise, there is a problem. */
-          if (g_unichar_isspace(group_separator))
-            next_state = DONE_ST;
-          else
-            next_state = NO_NUM_ST;
-        }
-        break;
+                next_state = IN_GROUP_ST;
+            }
+            else if (uc == decimal_point)
+            {
+                /* If we now get a decimal point, and both the decimal
+                 * and the group separator are also whitespace, assume
+                 * the last group separator was actually whitespace and
+                 * stop parsing. Otherwise, there's a problem. */
+                if (g_unichar_isspace(group_separator) &&
+                        g_unichar_isspace(decimal_point))
+                    next_state = DONE_ST;
+                else
+                    next_state = NO_NUM_ST;
+            }
+            else if (uc == ')' && need_paren)
+            {
+                if (g_unichar_isspace(group_separator))
+                {
+                    next_state = DONE_ST;
+                    need_paren = FALSE;
+                }
+                else
+                    next_state = NO_NUM_ST;
+            }
+            else
+            {
+                /* If the last group separator is also whitespace,
+                 * assume it was intended as such and stop parsing.
+                 * Otherwise, there is a problem. */
+                if (g_unichar_isspace(group_separator))
+                    next_state = DONE_ST;
+                else
+                    next_state = NO_NUM_ST;
+            }
+            break;
 
-      /* IN_GROUP_ST means we are in the middle of parsing
-       * a group of digits. */
-      case IN_GROUP_ST:
-        if (g_unichar_isdigit(uc))
-        {
-          count = g_unichar_to_utf8(uc, out);
-	  out += count;
-          group_count++; /* We record the number of digits
+            /* IN_GROUP_ST means we are in the middle of parsing
+             * a group of digits. */
+        case IN_GROUP_ST:
+            if (g_unichar_isdigit(uc))
+            {
+                count = g_unichar_to_utf8(uc, out);
+                out += count;
+                group_count++; /* We record the number of digits
                           * in the group for later checking. */
+            }
+            else if (uc == decimal_point)
+            {
+                next_state = FRAC_ST;
+            }
+            else if (uc == group_separator)
+            {
+                next_state = START_GROUP_ST;
+            }
+            else if (uc == ')' && need_paren)
+            {
+                next_state = DONE_ST;
+                need_paren = FALSE;
+            }
+            else
+            {
+                next_state = DONE_ST;
+            }
+
+            break;
+
+            /* FRAC_ST means we are now parsing fractional digits. */
+        case FRAC_ST:
+            if (g_unichar_isdigit(uc))
+            {
+                count = g_unichar_to_utf8(uc, out);
+                out += count;
+            }
+            else if (uc == decimal_point)
+            {
+                /* If a subsequent decimal point is also whitespace,
+                 * assume it was intended as such and stop parsing.
+                 * Otherwise, there is a problem. */
+                if (g_unichar_isspace(decimal_point))
+                    next_state = DONE_ST;
+                else
+                    next_state = NO_NUM_ST;
+            }
+            else if (uc == group_separator)
+            {
+                /* If a subsequent group separator is also whitespace,
+                 * assume it was intended as such and stop parsing.
+                 * Otherwise, there is a problem. */
+                if (g_unichar_isspace(group_separator))
+                    next_state = DONE_ST;
+                else
+                    next_state = NO_NUM_ST;
+            }
+            else if (uc == ')' && need_paren)
+            {
+                next_state = DONE_ST;
+                need_paren = FALSE;
+            }
+            else
+            {
+                next_state = DONE_ST;
+            }
+
+            break;
+
+        default:
+            PERR("bad state");
+            g_assert_not_reached();
+            break;
         }
-        else if (uc == decimal_point)
+
+        /* If we're moving out of the IN_GROUP_ST, record data for the group */
+        if ((state == IN_GROUP_ST) && (next_state != IN_GROUP_ST))
         {
-          next_state = FRAC_ST;
+            group_data = g_list_prepend(group_data, GINT_TO_POINTER(group_count));
+            group_count = 0;
         }
-        else if (uc == group_separator)
+
+        /* If we're moving into the FRAC_ST or out of the machine
+         * without going through FRAC_ST, record the integral value. */
+        if (((next_state == FRAC_ST) && (state != FRAC_ST)) ||
+                ((next_state == DONE_ST) && !got_decimal))
         {
-          next_state = START_GROUP_ST;
-        }
-        else if (uc == ')' && need_paren)
-        {
-          next_state = DONE_ST;
-          need_paren = FALSE;
-        }
-        else
-        {
-          next_state = DONE_ST;
-        }
+            *out = '\0';
 
-        break;
+            if (*out_str != '\0' && sscanf(out_str, QOF_SCANF_LLD, &numer) < 1)
+            {
+                next_state = NO_NUM_ST;
+            }
+            else if (next_state == FRAC_ST)
+            {
+                /* reset the out pointer to record the fraction */
+                out = out_str;
+                *out = '\0';
 
-      /* FRAC_ST means we are now parsing fractional digits. */
-      case FRAC_ST:
-        if (g_unichar_isdigit(uc))
-        {
-          count = g_unichar_to_utf8(uc, out);
-	  out += count;
+                got_decimal = TRUE;
+            }
         }
-        else if (uc == decimal_point)
-        {
-          /* If a subsequent decimal point is also whitespace,
-           * assume it was intended as such and stop parsing.
-           * Otherwise, there is a problem. */
-          if (g_unichar_isspace(decimal_point))
-            next_state = DONE_ST;
-          else
-            next_state = NO_NUM_ST;
-        }
-        else if (uc == group_separator)
-        {
-          /* If a subsequent group separator is also whitespace,
-           * assume it was intended as such and stop parsing.
-           * Otherwise, there is a problem. */
-          if (g_unichar_isspace(group_separator))
-            next_state = DONE_ST;
-          else
-            next_state = NO_NUM_ST;
-        }
-        else if (uc == ')' && need_paren)
-        {
-          next_state = DONE_ST;
-          need_paren = FALSE;
-        }
-        else
-        {
-          next_state = DONE_ST;
-        }
 
-        break;
+        state = next_state;
+        if (done_state (state))
+            break;
 
-      default:
-        PERR("bad state");
-        g_assert_not_reached();
-        break;
+        in = g_utf8_next_char(in);
     }
 
-    /* If we're moving out of the IN_GROUP_ST, record data for the group */
-    if ((state == IN_GROUP_ST) && (next_state != IN_GROUP_ST))
+    /* If there was an error, just quit */
+    if (need_paren || (state == NO_NUM_ST))
     {
-      group_data = g_list_prepend(group_data, GINT_TO_POINTER(group_count));
-      group_count = 0;
+        g_free(out_str);
+        g_list_free(group_data);
+        return FALSE;
     }
 
-    /* If we're moving into the FRAC_ST or out of the machine
-     * without going through FRAC_ST, record the integral value. */
-    if (((next_state == FRAC_ST) && (state != FRAC_ST)) ||
-        ((next_state == DONE_ST) && !got_decimal))
+    /* If there were groups, validate them */
+    if (group_data != NULL)
     {
-      *out = '\0';
+        gboolean good_grouping = TRUE;
+        GList *node;
 
-      if (*out_str != '\0' && sscanf(out_str, QOF_SCANF_LLD, &numer) < 1)
-      {
-        next_state = NO_NUM_ST;
-      }
-      else if (next_state == FRAC_ST)
-      {
-        /* reset the out pointer to record the fraction */
-        out = out_str;
-        *out = '\0';
+        /* The groups were built in reverse order. This
+         * is the easiest order to verify them in. */
+        for (node = group_data; group && node; node = node->next)
+        {
+            /* Verify group size */
+            if (*group != GPOINTER_TO_INT(node->data))
+            {
+                good_grouping = FALSE;
+                break;
+            }
 
-        got_decimal = TRUE;
-      }
-    }
+            /* Peek ahead at the next group code */
+            switch (group[1])
+            {
+                /* A null char means repeat the last group indefinitely */
+            case '\0':
+                break;
+                /* CHAR_MAX means no more grouping allowed */
+            case CHAR_MAX:
+                if (node->next != NULL)
+                    good_grouping = FALSE;
+                break;
+                /* Anything else means another group size */
+            default:
+                group++;
+                break;
+            }
 
-    state = next_state;
-    if (done_state (state))
-      break;
+            if (!good_grouping)
+                break;
+        }
 
-    in = g_utf8_next_char(in);
-  }
+        g_list_free(group_data);
 
-  /* If there was an error, just quit */
-  if (need_paren || (state == NO_NUM_ST))
-  {
-    g_free(out_str);
-    g_list_free(group_data);
-    return FALSE;
-  }
+        if (!good_grouping)
+        {
+            g_free(out_str);
+            return FALSE;
+        }
+    }
 
-  /* If there were groups, validate them */
-  if (group_data != NULL)
-  {
-    gboolean good_grouping = TRUE;
-    GList *node;
+    /* Cap the end of the fraction string, if any */
+    *out = '\0';
 
-    /* The groups were built in reverse order. This
-     * is the easiest order to verify them in. */
-    for (node = group_data; group && node; node = node->next)
+    /* Add in fractional value */
+    if (got_decimal && (*out_str != '\0'))
     {
-      /* Verify group size */
-      if (*group != GPOINTER_TO_INT(node->data))
-      {
-        good_grouping = FALSE;
-        break;
-      }
+        size_t len;
+        long long int fraction;
 
-      /* Peek ahead at the next group code */
-      switch (group[1])
-      {
-        /* A null char means repeat the last group indefinitely */
-        case '\0':
-          break;
-        /* CHAR_MAX means no more grouping allowed */
-        case CHAR_MAX:
-          if (node->next != NULL)
-            good_grouping = FALSE;
-          break;
-        /* Anything else means another group size */
-        default:
-          group++;
-          break;
-      }
+        len = strlen(out_str);
 
-      if (!good_grouping)
-        break;
-    }
+        if (len > 8)
+        {
+            out_str[8] = '\0';
+            len = 8;
+        }
 
-    g_list_free(group_data);
+        if (sscanf (out_str, QOF_SCANF_LLD, &fraction) < 1)
+        {
+            g_free(out_str);
+            return FALSE;
+        }
 
-    if (!good_grouping)
-    {
-      g_free(out_str);
-      return FALSE;
+        denom = multiplier(len);
+        numer *= denom;
+        numer += fraction;
     }
-  }
-
-  /* Cap the end of the fraction string, if any */
-  *out = '\0';
-
-  /* Add in fractional value */
-  if (got_decimal && (*out_str != '\0'))
-  {
-    size_t len;
-    long long int fraction;
-
-    len = strlen(out_str);
-
-    if (len > 8)
+    else if (monetary && auto_decimal_enabled && !got_decimal)
     {
-      out_str[8] = '\0';
-      len = 8;
-    }
+        if ((auto_decimal_places > 0) && (auto_decimal_places < 9))
+        {
+            denom = multiplier(auto_decimal_places);
 
-    if (sscanf (out_str, QOF_SCANF_LLD, &fraction) < 1)
-    {
-      g_free(out_str);
-      return FALSE;
+            /* No need to multiply numer by denom at this point,
+             * since by specifying the auto decimal places the
+             * user has effectively determined the scaling factor
+             * for the numerator they entered.
+             */
+        }
     }
 
-    denom = multiplier(len);
-    numer *= denom;
-    numer += fraction;
-  }
-  else if (monetary && auto_decimal_enabled && !got_decimal)
-  {
-    if ((auto_decimal_places > 0) && (auto_decimal_places < 9))
+    if (result != NULL)
     {
-      denom = multiplier(auto_decimal_places);
-
-      /* No need to multiply numer by denom at this point,
-       * since by specifying the auto decimal places the
-       * user has effectively determined the scaling factor
-       * for the numerator they entered.
-       */
+        *result = gnc_numeric_create (numer, denom);
+        if (is_negative)
+            *result = gnc_numeric_neg (*result);
     }
-  }
 
-  if (result != NULL)
-  {
-    *result = gnc_numeric_create (numer, denom);
-    if (is_negative)
-      *result = gnc_numeric_neg (*result);
-  }
+    if (endstr != NULL)
+        *endstr = (char *) in;
 
-  if (endstr != NULL)
-    *endstr = (char *) in;
+    g_free (out_str);
 
-  g_free (out_str);
-
-  return TRUE;
+    return TRUE;
 }
 
 /* enable/disable the auto_decimal_enabled option */
 static void
 gnc_set_auto_decimal_enabled (GConfEntry *entry, gpointer user_data)
 {
-  GConfValue *value;
+    GConfValue *value;
 
-  value = gconf_entry_get_value(entry);
-  auto_decimal_enabled = gconf_value_get_bool(value);
+    value = gconf_entry_get_value(entry);
+    auto_decimal_enabled = gconf_value_get_bool(value);
 }
 
 /* set the number of auto decimal places to use */
 static void
 gnc_set_auto_decimal_places  (GConfEntry *entry, gpointer user_data)
 {
-  GConfValue *value;
+    GConfValue *value;
 
-  value = gconf_entry_get_value(entry);
-  auto_decimal_places = gconf_value_get_float(value);
+    value = gconf_entry_get_value(entry);
+    auto_decimal_places = gconf_value_get_float(value);
 }
 
 static void
 gnc_auto_decimal_init (void)
 {
-  auto_decimal_enabled =
-    gnc_gconf_get_bool(GCONF_GENERAL, "auto_decimal_point", NULL);
-  auto_decimal_places =
-    gnc_gconf_get_float(GCONF_GENERAL, "auto_decimal_places", NULL);
+    auto_decimal_enabled =
+        gnc_gconf_get_bool(GCONF_GENERAL, "auto_decimal_point", NULL);
+    auto_decimal_places =
+        gnc_gconf_get_float(GCONF_GENERAL, "auto_decimal_places", NULL);
 }
 
 void
 gnc_ui_util_init (void)
 {
-  gnc_configure_account_separator ();
-  gnc_auto_decimal_init();
+    gnc_configure_account_separator ();
+    gnc_auto_decimal_init();
 
-  gnc_gconf_general_register_cb(KEY_ACCOUNT_SEPARATOR,
-				(GncGconfGeneralCb)gnc_configure_account_separator,
-				NULL);
-  gnc_gconf_general_register_cb(KEY_REVERSED_ACCOUNTS,
-				(GncGconfGeneralCb)gnc_configure_reverse_balance,
-				NULL);
-  gnc_gconf_general_register_cb(KEY_CURRENCY_CHOICE,
-				gnc_currency_changed_cb, NULL);
-  gnc_gconf_general_register_cb(KEY_CURRENCY_OTHER,
-				gnc_currency_changed_cb, NULL);
-  gnc_gconf_general_register_cb("auto_decimal_point",
-				gnc_set_auto_decimal_enabled,
-				NULL);
-  gnc_gconf_general_register_cb("auto_decimal_places",
-				gnc_set_auto_decimal_places,
-				NULL);
- 
+    gnc_gconf_general_register_cb(KEY_ACCOUNT_SEPARATOR,
+                                  (GncGconfGeneralCb)gnc_configure_account_separator,
+                                  NULL);
+    gnc_gconf_general_register_cb(KEY_REVERSED_ACCOUNTS,
+                                  (GncGconfGeneralCb)gnc_configure_reverse_balance,
+                                  NULL);
+    gnc_gconf_general_register_cb(KEY_CURRENCY_CHOICE,
+                                  gnc_currency_changed_cb, NULL);
+    gnc_gconf_general_register_cb(KEY_CURRENCY_OTHER,
+                                  gnc_currency_changed_cb, NULL);
+    gnc_gconf_general_register_cb("auto_decimal_point",
+                                  gnc_set_auto_decimal_enabled,
+                                  NULL);
+    gnc_gconf_general_register_cb("auto_decimal_places",
+                                  gnc_set_auto_decimal_places,
+                                  NULL);
+
 }
 
 /* These implementations are rather lame. */
@@ -2439,18 +2468,18 @@
 gint32
 towupper (gint32 wc)
 {
-  if (wc > 127)
-    return wc;
+    if (wc > 127)
+        return wc;
 
-  return toupper ((int) wc);
+    return toupper ((int) wc);
 }
 
 int
 iswlower (gint32 wc)
 {
-  if (wc > 127)
-    return 1;
+    if (wc > 127)
+        return 1;
 
-  return islower ((int) wc);
+    return islower ((int) wc);
 }
 #endif

Modified: gnucash/trunk/src/app-utils/gnc-ui-util.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -24,7 +24,7 @@
     @{ */
 /** @addtogroup GuiUtility Utility functions for the GnuCash GUI
  * @{ */
-/** @file gnc-ui-util.h 
+/** @file gnc-ui-util.h
     @brief  utility functions for the GnuCash UI
     @author Copyright (C) 2000 Dave Peticolas <dave at krondo.com>
 */
@@ -50,7 +50,7 @@
 
 gchar *gnc_get_default_directory (const gchar *gconf_section);
 void gnc_set_default_directory (const gchar *gconf_section,
-				const gchar *directory);
+                                const gchar *directory);
 
 /* Engine enhancements & i18n ***************************************/
 QofBook * gnc_get_current_book (void);
@@ -82,7 +82,7 @@
  * @return A pointer to the account, or NULL if the account was not found.
 */
 Account *gnc_account_lookup_for_register(const Account *base_account, const
-					 gchar *name);
+        gchar *name);
 
 /*
  * This is a wrapper routine around an xaccGetBalanceInCurrency
@@ -104,10 +104,10 @@
  */
 gnc_numeric
 gnc_ui_account_get_balance_full (xaccGetBalanceInCurrencyFn fn,
-				 const Account *account,
-				 gboolean recurse,
-				 gboolean *negative,
-				 const gnc_commodity *commodity);
+                                 const Account *account,
+                                 gboolean recurse,
+                                 gboolean *negative,
+                                 const gnc_commodity *commodity);
 
 /**
  * This routine retrives the total balance in an account, possibly
@@ -120,8 +120,8 @@
                                         gboolean include_children);
 
 gnc_numeric gnc_ui_account_get_balance_in_currency (const Account *account,
-						    const gnc_commodity *currency,
-						    gboolean recurse);
+        const gnc_commodity *currency,
+        gboolean recurse);
 /**
  * This routine retrives the reconciled balance in an account,
  * possibly including all sub-accounts under the specified account.
@@ -130,7 +130,7 @@
  * @param include_children  Include all sub-accounts of this account.
  */
 gnc_numeric gnc_ui_account_get_reconciled_balance(const Account *account,
-                                                  gboolean include_children);
+        gboolean include_children);
 
 /**
  * Wrapper around gnc_ui_account_get_balance_internal that converts
@@ -147,9 +147,9 @@
  */
 gchar *
 gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn,
-				  const Account *account,
-				  gboolean recurse,
-				  gboolean *negative);
+                                  const Account *account,
+                                  gboolean recurse,
+                                  gboolean *negative);
 
 /**
  * Wrapper around gnc_ui_account_get_balance_internal that converts
@@ -167,15 +167,15 @@
  */
 gchar *
 gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
-					 const Account *account,
-					 gboolean recurse,
-					 gboolean *negative);
+        const Account *account,
+        gboolean recurse,
+        gboolean *negative);
 
 char *gnc_ui_account_get_tax_info_string (const Account *account);
 
 gnc_numeric gnc_ui_account_get_balance_as_of_date (Account *account,
-                                                   time_t date,
-                                                   gboolean include_children);
+        time_t date,
+        gboolean include_children);
 
 const char * gnc_get_reconcile_str (char reconciled_flag);
 const char * gnc_get_reconcile_valid_flags (void);
@@ -183,18 +183,18 @@
 
 typedef enum
 {
-  EQUITY_OPENING_BALANCE,
-  EQUITY_RETAINED_EARNINGS,
-  NUM_EQUITY_TYPES
+    EQUITY_OPENING_BALANCE,
+    EQUITY_RETAINED_EARNINGS,
+    NUM_EQUITY_TYPES
 } GNCEquityType;
 
 Account * gnc_find_or_create_equity_account (Account *root,
-                                             GNCEquityType equity_type,
-                                             gnc_commodity *currency);
+        GNCEquityType equity_type,
+        gnc_commodity *currency);
 gboolean gnc_account_create_opening_balance (Account *account,
-                                             gnc_numeric balance,
-                                             time_t date,
-                                             QofBook *book);
+        gnc_numeric balance,
+        time_t date,
+        QofBook *book);
 
 /* Locale functions *************************************************/
 
@@ -260,30 +260,30 @@
 
 typedef struct _GNCPrintAmountInfo
 {
-  const gnc_commodity *commodity;  /* may be NULL */
+    const gnc_commodity *commodity;  /* may be NULL */
 
-  guint8 max_decimal_places;
-  guint8 min_decimal_places;
+    guint8 max_decimal_places;
+    guint8 min_decimal_places;
 
-  unsigned int use_separators : 1; /* Print thousands separators */
-  unsigned int use_symbol : 1;     /* Print currency symbol */
-  unsigned int use_locale : 1;     /* Use locale for some positioning */
-  unsigned int monetary : 1;       /* Is a monetary quantity */
-  unsigned int force_fit : 1;      /* Don't print more than max_dp places */
-  unsigned int round : 1;          /* Round at max_dp instead of truncating */
+    unsigned int use_separators : 1; /* Print thousands separators */
+    unsigned int use_symbol : 1;     /* Print currency symbol */
+    unsigned int use_locale : 1;     /* Use locale for some positioning */
+    unsigned int monetary : 1;       /* Is a monetary quantity */
+    unsigned int force_fit : 1;      /* Don't print more than max_dp places */
+    unsigned int round : 1;          /* Round at max_dp instead of truncating */
 } GNCPrintAmountInfo;
 
 
 GNCPrintAmountInfo gnc_default_print_info (gboolean use_symbol);
 
 GNCPrintAmountInfo gnc_commodity_print_info (const gnc_commodity *commodity,
-                                             gboolean use_symbol);
+        gboolean use_symbol);
 
 GNCPrintAmountInfo gnc_account_print_info (const Account *account,
-                                           gboolean use_symbol);
+        gboolean use_symbol);
 
 GNCPrintAmountInfo gnc_split_amount_print_info (Split *split,
-                                                gboolean use_symbol);
+        gboolean use_symbol);
 
 GNCPrintAmountInfo gnc_share_print_info_places (int decplaces);
 GNCPrintAmountInfo gnc_default_share_print_info (void);
@@ -326,9 +326,9 @@
  */
 gboolean
 xaccParseAmountExtended (const char * in_str, gboolean monetary,
-			 gunichar negative_sign, gunichar decimal_point,
-			 gunichar group_separator, char *group, char *ignore_list,
-			 gnc_numeric *result, char **endstr);
+                         gunichar negative_sign, gunichar decimal_point,
+                         gunichar group_separator, char *group, char *ignore_list,
+                         gnc_numeric *result, char **endstr);
 
 /* Initialization ***************************************************/
 

Modified: gnucash/trunk/src/app-utils/gncmod-app-utils.c
===================================================================
--- gnucash/trunk/src/app-utils/gncmod-app-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/gncmod-app-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -28,21 +28,23 @@
 
 
 char *
-libgncmod_app_utils_gnc_module_path(void) {
-  return g_strdup("gnucash/app-utils");
+libgncmod_app_utils_gnc_module_path(void)
+{
+    return g_strdup("gnucash/app-utils");
 }
 
 char *
-libgncmod_app_utils_gnc_module_description(void) {
-  return g_strdup("Utilities for building gnc applications");
+libgncmod_app_utils_gnc_module_description(void)
+{
+    return g_strdup("Utilities for building gnc applications");
 }
 
 static void
 lmod(char * mn)
 {
-  char * form = g_strdup_printf("(use-modules %s)\n", mn);
-  scm_c_eval_string(form);
-  g_free(form);
+    char * form = g_strdup_printf("(use-modules %s)\n", mn);
+    scm_c_eval_string(form);
+    g_free(form);
 }
 
 static void
@@ -58,36 +60,39 @@
 int
 libgncmod_app_utils_gnc_module_init(int refcount)
 {
-  /* load the engine (we depend on it) */
-  if(!gnc_module_load("gnucash/engine", 0)) {
-    return FALSE;
-  }
+    /* load the engine (we depend on it) */
+    if (!gnc_module_load("gnucash/engine", 0))
+    {
+        return FALSE;
+    }
 
-  /* load the calculation module (we depend on it) */
-  if(!gnc_module_load("gnucash/calculation", 0)) {
-    return FALSE;
-  }
+    /* load the calculation module (we depend on it) */
+    if (!gnc_module_load("gnucash/calculation", 0))
+    {
+        return FALSE;
+    }
 
-  scm_init_sw_app_utils_module();
-  /* publish swig bindings */
-  /* load the scheme code */
-  lmod("(sw_app_utils)");
-  lmod("(gnucash app-utils)");
+    scm_init_sw_app_utils_module();
+    /* publish swig bindings */
+    /* load the scheme code */
+    lmod("(sw_app_utils)");
+    lmod("(gnucash app-utils)");
 
-  if (refcount == 0) {
-    gnc_component_manager_init ();
-    gnc_hook_add_dangler(HOOK_STARTUP, (GFunc)gnc_exp_parser_init, NULL);
-    gnc_hook_add_dangler(HOOK_SHUTDOWN, (GFunc)app_utils_shutdown, NULL);
-  }
+    if (refcount == 0)
+    {
+        gnc_component_manager_init ();
+        gnc_hook_add_dangler(HOOK_STARTUP, (GFunc)gnc_exp_parser_init, NULL);
+        gnc_hook_add_dangler(HOOK_SHUTDOWN, (GFunc)app_utils_shutdown, NULL);
+    }
 
-  return TRUE;
+    return TRUE;
 }
 
 int
 libgncmod_app_utils_gnc_module_end(int refcount)
 {
-  if (refcount == 0)
-    gnc_component_manager_shutdown ();
+    if (refcount == 0)
+        gnc_component_manager_shutdown ();
 
-  return TRUE;
+    return TRUE;
 }

Modified: gnucash/trunk/src/app-utils/guile-util.c
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/guile-util.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -47,96 +47,96 @@
 
 struct _setters
 {
-  SCM split_scm_account_guid;
-  SCM split_scm_memo;
-  SCM split_scm_action;
-  SCM split_scm_reconcile_state;
-  SCM split_scm_amount;
-  SCM split_scm_value;
+    SCM split_scm_account_guid;
+    SCM split_scm_memo;
+    SCM split_scm_action;
+    SCM split_scm_reconcile_state;
+    SCM split_scm_amount;
+    SCM split_scm_value;
 
-  SCM trans_scm_date;
-  SCM trans_scm_num;
-  SCM trans_scm_description;
-  SCM trans_scm_notes;
-  SCM trans_scm_append_split_scm;
+    SCM trans_scm_date;
+    SCM trans_scm_num;
+    SCM trans_scm_description;
+    SCM trans_scm_notes;
+    SCM trans_scm_append_split_scm;
 } setters;
 
 struct _getters
 {
-  SCM split_scm_memo;
-  SCM split_scm_action;
-  SCM split_scm_amount;
-  SCM split_scm_value;
+    SCM split_scm_memo;
+    SCM split_scm_action;
+    SCM split_scm_amount;
+    SCM split_scm_value;
 
-  SCM trans_scm_split_scms;
-  SCM trans_scm_split_scm;
-  SCM trans_scm_other_split_scm;
+    SCM trans_scm_split_scms;
+    SCM trans_scm_split_scm;
+    SCM trans_scm_other_split_scm;
 
-  SCM debit_string;
-  SCM credit_string;
+    SCM debit_string;
+    SCM credit_string;
 } getters;
 
 struct _predicates
 {
-  SCM is_split_scm;
-  SCM is_trans_scm;
+    SCM is_split_scm;
+    SCM is_trans_scm;
 } predicates;
 
 struct _Process
 {
-  GPid pid;
-  gint fd_stdin;
-  gint fd_stdout;
-  gint fd_stderr;
-  gboolean dead;
-  gboolean detached;
+    GPid pid;
+    gint fd_stdin;
+    gint fd_stdout;
+    gint fd_stderr;
+    gboolean dead;
+    gboolean detached;
 };
 
 
 static void
 initialize_scm_functions()
 {
-  static gboolean scm_funcs_inited = FALSE;
+    static gboolean scm_funcs_inited = FALSE;
 
-  if (scm_funcs_inited)
-    return;
+    if (scm_funcs_inited)
+        return;
 
-  setters.split_scm_account_guid =
-    scm_c_eval_string("gnc:split-scm-set-account-guid");
-  setters.split_scm_memo = scm_c_eval_string("gnc:split-scm-set-memo");
-  setters.split_scm_action = scm_c_eval_string("gnc:split-scm-set-action");
-  setters.split_scm_reconcile_state =
-    scm_c_eval_string("gnc:split-scm-set-reconcile-state");
-  setters.split_scm_amount = scm_c_eval_string("gnc:split-scm-set-amount");
-  setters.split_scm_value = scm_c_eval_string("gnc:split-scm-set-value");
+    setters.split_scm_account_guid =
+        scm_c_eval_string("gnc:split-scm-set-account-guid");
+    setters.split_scm_memo = scm_c_eval_string("gnc:split-scm-set-memo");
+    setters.split_scm_action = scm_c_eval_string("gnc:split-scm-set-action");
+    setters.split_scm_reconcile_state =
+        scm_c_eval_string("gnc:split-scm-set-reconcile-state");
+    setters.split_scm_amount = scm_c_eval_string("gnc:split-scm-set-amount");
+    setters.split_scm_value = scm_c_eval_string("gnc:split-scm-set-value");
 
-  setters.trans_scm_date = scm_c_eval_string("gnc:transaction-scm-set-date-posted");
-  setters.trans_scm_num = scm_c_eval_string("gnc:transaction-scm-set-num");
-  setters.trans_scm_description =
-    scm_c_eval_string("gnc:transaction-scm-set-description");
-  setters.trans_scm_notes = scm_c_eval_string("gnc:transaction-scm-set-notes");
-  setters.trans_scm_append_split_scm =
-    scm_c_eval_string("gnc:transaction-scm-append-split-scm");
+    setters.trans_scm_date = scm_c_eval_string("gnc:transaction-scm-set-date-posted");
+    setters.trans_scm_num = scm_c_eval_string("gnc:transaction-scm-set-num");
+    setters.trans_scm_description =
+        scm_c_eval_string("gnc:transaction-scm-set-description");
+    setters.trans_scm_notes = scm_c_eval_string("gnc:transaction-scm-set-notes");
+    setters.trans_scm_append_split_scm =
+        scm_c_eval_string("gnc:transaction-scm-append-split-scm");
 
-  getters.split_scm_memo = scm_c_eval_string("gnc:split-scm-get-memo");
-  getters.split_scm_action = scm_c_eval_string("gnc:split-scm-get-action");
-  getters.split_scm_amount = scm_c_eval_string("gnc:split-scm-get-amount");
-  getters.split_scm_value = scm_c_eval_string("gnc:split-scm-get-value");
+    getters.split_scm_memo = scm_c_eval_string("gnc:split-scm-get-memo");
+    getters.split_scm_action = scm_c_eval_string("gnc:split-scm-get-action");
+    getters.split_scm_amount = scm_c_eval_string("gnc:split-scm-get-amount");
+    getters.split_scm_value = scm_c_eval_string("gnc:split-scm-get-value");
 
-  getters.trans_scm_split_scms =
-    scm_c_eval_string("gnc:transaction-scm-get-split-scms");
-  getters.trans_scm_split_scm =
-    scm_c_eval_string("gnc:transaction-scm-get-split-scm");
-  getters.trans_scm_other_split_scm =
-    scm_c_eval_string("gnc:transaction-scm-get-other-split-scm");
+    getters.trans_scm_split_scms =
+        scm_c_eval_string("gnc:transaction-scm-get-split-scms");
+    getters.trans_scm_split_scm =
+        scm_c_eval_string("gnc:transaction-scm-get-split-scm");
+    getters.trans_scm_other_split_scm =
+        scm_c_eval_string("gnc:transaction-scm-get-other-split-scm");
 
-  getters.debit_string = scm_c_eval_string("gnc:get-debit-string");
-  getters.credit_string = scm_c_eval_string("gnc:get-credit-string");
+    getters.debit_string = scm_c_eval_string("gnc:get-debit-string");
+    getters.credit_string = scm_c_eval_string("gnc:get-credit-string");
 
-  predicates.is_split_scm = scm_c_eval_string("gnc:split-scm?");
-  predicates.is_trans_scm = scm_c_eval_string("gnc:transaction-scm?");
+    predicates.is_split_scm = scm_c_eval_string("gnc:split-scm?");
+    predicates.is_trans_scm = scm_c_eval_string("gnc:transaction-scm?");
 
-  scm_funcs_inited = TRUE;
+    scm_funcs_inited = TRUE;
 }
 
 
@@ -152,25 +152,25 @@
 char *
 gnc_guile_call1_to_string(SCM func, SCM arg)
 {
-  SCM value;
+    SCM value;
 
-  if (SCM_PROCEDUREP(func))
-  {
-    value = scm_call_1(func, arg);
+    if (SCM_PROCEDUREP(func))
+    {
+        value = scm_call_1(func, arg);
 
-    if (SCM_STRINGP(value))
-      return g_strdup(SCM_STRING_CHARS(value));
+        if (SCM_STRINGP(value))
+            return g_strdup(SCM_STRING_CHARS(value));
+        else
+        {
+            PERR("bad value\n");
+        }
+    }
     else
     {
-      PERR("bad value\n");
+        PERR("not a procedure\n");
     }
-  }
-  else
-  {
-    PERR("not a procedure\n");
-  }
 
-  return NULL;
+    return NULL;
 }
 
 
@@ -187,25 +187,25 @@
 char *
 gnc_guile_call1_symbol_to_string(SCM func, SCM arg)
 {
-  SCM value;
+    SCM value;
 
-  if (SCM_PROCEDUREP(func))
-  {
-    value = scm_call_1(func, arg);
+    if (SCM_PROCEDUREP(func))
+    {
+        value = scm_call_1(func, arg);
 
-    if (SCM_SYMBOLP(value))
-      return g_strdup(SCM_SYMBOL_CHARS(value));
+        if (SCM_SYMBOLP(value))
+            return g_strdup(SCM_SYMBOL_CHARS(value));
+        else
+        {
+            PERR("bad value\n");
+        }
+    }
     else
     {
-      PERR("bad value\n");
+        PERR("not a procedure\n");
     }
-  }
-  else
-  {
-    PERR("not a procedure\n");
-  }
 
-  return NULL;
+    return NULL;
 }
 
 
@@ -221,25 +221,25 @@
 SCM
 gnc_guile_call1_to_procedure(SCM func, SCM arg)
 {
-  SCM value;
+    SCM value;
 
-  if (SCM_PROCEDUREP(func))
-  {
-    value = scm_call_1(func, arg);
+    if (SCM_PROCEDUREP(func))
+    {
+        value = scm_call_1(func, arg);
 
-    if (SCM_PROCEDUREP(value))
-      return value;
+        if (SCM_PROCEDUREP(value))
+            return value;
+        else
+        {
+            PERR("bad value\n");
+        }
+    }
     else
     {
-      PERR("bad value\n");
+        PERR("not a procedure\n");
     }
-  }
-  else
-  {
-    PERR("not a procedure\n");
-  }
 
-  return SCM_UNDEFINED;
+    return SCM_UNDEFINED;
 }
 
 
@@ -255,25 +255,25 @@
 SCM
 gnc_guile_call1_to_list(SCM func, SCM arg)
 {
-  SCM value;
+    SCM value;
 
-  if (SCM_PROCEDUREP(func))
-  {
-    value = scm_call_1(func, arg);
+    if (SCM_PROCEDUREP(func))
+    {
+        value = scm_call_1(func, arg);
 
-    if (SCM_LISTP(value))
-      return value;
+        if (SCM_LISTP(value))
+            return value;
+        else
+        {
+            PERR("bad value\n");
+        }
+    }
     else
     {
-      PERR("bad value\n");
+        PERR("not a procedure\n");
     }
-  }
-  else
-  {
-    PERR("not a procedure\n");
-  }
 
-  return SCM_UNDEFINED;
+    return SCM_UNDEFINED;
 }
 
 
@@ -289,30 +289,30 @@
 SCM
 gnc_guile_call1_to_vector(SCM func, SCM arg)
 {
-  SCM value;
+    SCM value;
 
-  if (SCM_PROCEDUREP(func))
-  {
-    value = scm_call_1(func, arg);
+    if (SCM_PROCEDUREP(func))
+    {
+        value = scm_call_1(func, arg);
 
-    if (SCM_VECTORP(value))
-      return value;
+        if (SCM_VECTORP(value))
+            return value;
+        else
+        {
+            PERR("bad value\n");
+        }
+    }
     else
     {
-      PERR("bad value\n");
+        PERR("not a procedure\n");
     }
-  }
-  else
-  {
-    PERR("not a procedure\n");
-  }
 
-  return SCM_UNDEFINED;
+    return SCM_UNDEFINED;
 }
 
 
 /********************************************************************\
-  gnc_scm_lookup                    
+  gnc_scm_lookup
 
     returns the SCM binding associated with the given symbol function,
     or SCM_UNDEFINED if it couldn't be retrieved.
@@ -321,7 +321,7 @@
     to a given module unless the C code you're writing is considered
     part of that module.
 
-  Args: 
+  Args:
 
     module - where to lookup the symbol, something like "ice-9 debug"
     symbol - what to look up.
@@ -331,43 +331,43 @@
 
 #if 0
 
-  ************ NOT TESTED YET **************
+************ NOT TESTED YET **************
 
 SCM
 gnc_scm_lookup(const char *module, const char *symbol)
 {
 #if defined(SCM_GUILE_MAJOR_VERSION) && \
     (SCM_GUILE_MAJOR_VERSION > 0) && (SCM_GUILE_MINOR_VERSION > 4)
-  
-  SCM scm_module = scm_c_resolve_module(module);
-  SCM value = scm_c_module_lookup(scm_module, symbol);
-  return value;
+
+    SCM scm_module = scm_c_resolve_module(module);
+    SCM value = scm_c_module_lookup(scm_module, symbol);
+    return value;
 #else
-  
-  gchar *in_guard_str;
-  gchar *thunk_str;
-  SCM in_guard;
-  SCM thunk;
-  SCM out_guard;
-  SCM result;
 
-  in_guard_str =
-    g_strdup_printf("(lambda () (set-current-module (resolve-module (%s))))",
-                    module);
+    gchar *in_guard_str;
+    gchar *thunk_str;
+    SCM in_guard;
+    SCM thunk;
+    SCM out_guard;
+    SCM result;
 
-  thunk_str = g_strdup_printf("(lambda () (eval '%s))", symbol);
+    in_guard_str =
+        g_strdup_printf("(lambda () (set-current-module (resolve-module (%s))))",
+                        module);
 
-  in_guard = scm_c_eval_string(in_guard_str);
-  thunk = scm_c_eval_string(thunk_str);
-  out_guard = scm_c_eval_string("(let ((cm (current-module)))"
-                          "  (lambda () (set-current-module cm)))");
+    thunk_str = g_strdup_printf("(lambda () (eval '%s))", symbol);
 
-  result = scm_dynamic_wind(in_guard, thunk, out_guard);
+    in_guard = scm_c_eval_string(in_guard_str);
+    thunk = scm_c_eval_string(thunk_str);
+    out_guard = scm_c_eval_string("(let ((cm (current-module)))"
+                                  "  (lambda () (set-current-module cm)))");
 
-  g_free(in_guard_str);
-  g_free(thunk_str);
+    result = scm_dynamic_wind(in_guard, thunk, out_guard);
 
-  return result;
+    g_free(in_guard_str);
+    g_free(thunk_str);
+
+    return result;
 #endif
 }
 
@@ -385,23 +385,23 @@
 SCM
 gnc_copy_split(Split *split, gboolean use_cut_semantics)
 {
-  static swig_type_info *split_type = NULL;
-  SCM func;
-  SCM arg;
+    static swig_type_info *split_type = NULL;
+    SCM func;
+    SCM arg;
 
-  if (split == NULL)
-    return SCM_UNDEFINED;
+    if (split == NULL)
+        return SCM_UNDEFINED;
 
-  func = scm_c_eval_string("gnc:split->split-scm");
-  if (!SCM_PROCEDUREP(func))
-    return SCM_UNDEFINED;
+    func = scm_c_eval_string("gnc:split->split-scm");
+    if (!SCM_PROCEDUREP(func))
+        return SCM_UNDEFINED;
 
-  if (!split_type)
-      split_type = SWIG_TypeQuery("_p_Split");
+    if (!split_type)
+        split_type = SWIG_TypeQuery("_p_Split");
 
-  arg = SWIG_NewPointerObj(split, split_type, 0);
+    arg = SWIG_NewPointerObj(split, split_type, 0);
 
-  return scm_call_2(func, arg, SCM_BOOL(use_cut_semantics));
+    return scm_call_2(func, arg, SCM_BOOL(use_cut_semantics));
 }
 
 
@@ -417,37 +417,37 @@
 gnc_copy_split_scm_onto_split(SCM split_scm, Split *split,
                               QofBook * book)
 {
-  static swig_type_info *split_type = NULL;
-  SCM result;
-  SCM func;
-  SCM arg;
+    static swig_type_info *split_type = NULL;
+    SCM result;
+    SCM func;
+    SCM arg;
 
-  if (split_scm == SCM_UNDEFINED)
-    return;
+    if (split_scm == SCM_UNDEFINED)
+        return;
 
-  if (split == NULL)
-    return;
+    if (split == NULL)
+        return;
 
-  g_return_if_fail (book);
+    g_return_if_fail (book);
 
-  func = scm_c_eval_string("gnc:split-scm?");
-  if (!SCM_PROCEDUREP(func))
-    return;
+    func = scm_c_eval_string("gnc:split-scm?");
+    if (!SCM_PROCEDUREP(func))
+        return;
 
-  result = scm_call_1(func, split_scm);
-  if (!SCM_NFALSEP(result))
-    return;
+    result = scm_call_1(func, split_scm);
+    if (!SCM_NFALSEP(result))
+        return;
 
-  func = scm_c_eval_string("gnc:split-scm-onto-split");
-  if (!SCM_PROCEDUREP(func))
-    return;
+    func = scm_c_eval_string("gnc:split-scm-onto-split");
+    if (!SCM_PROCEDUREP(func))
+        return;
 
-  if (!split_type)
-      split_type = SWIG_TypeQuery("_p_Split");
+    if (!split_type)
+        split_type = SWIG_TypeQuery("_p_Split");
 
-  arg = SWIG_NewPointerObj(split, split_type, 0);
+    arg = SWIG_NewPointerObj(split, split_type, 0);
 
-  scm_call_3(func, split_scm, arg, gnc_book_to_scm (book));
+    scm_call_3(func, split_scm, arg, gnc_book_to_scm (book));
 }
 
 
@@ -461,9 +461,9 @@
 gboolean
 gnc_is_split_scm(SCM scm)
 {
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  return SCM_NFALSEP(scm_call_1(predicates.is_split_scm, scm));
+    return SCM_NFALSEP(scm_call_1(predicates.is_split_scm, scm));
 }
 
 
@@ -477,9 +477,9 @@
 gboolean
 gnc_is_trans_scm(SCM scm)
 {
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  return SCM_NFALSEP(scm_call_1(predicates.is_trans_scm, scm));
+    return SCM_NFALSEP(scm_call_1(predicates.is_trans_scm, scm));
 }
 
 
@@ -494,23 +494,23 @@
 void
 gnc_split_scm_set_account(SCM split_scm, Account *account)
 {
-  const char *guid_string;
-  SCM arg;
+    const char *guid_string;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_split_scm(split_scm))
-    return;
-  if (account == NULL)
-    return;
+    if (!gnc_is_split_scm(split_scm))
+        return;
+    if (account == NULL)
+        return;
 
-  guid_string = guid_to_string(xaccAccountGetGUID(account));
-  if (guid_string == NULL)
-    return;
+    guid_string = guid_to_string(xaccAccountGetGUID(account));
+    if (guid_string == NULL)
+        return;
 
-  arg = scm_makfrom0str(guid_string);
+    arg = scm_makfrom0str(guid_string);
 
-  scm_call_2(setters.split_scm_account_guid, split_scm, arg);
+    scm_call_2(setters.split_scm_account_guid, split_scm, arg);
 }
 
 
@@ -525,18 +525,18 @@
 void
 gnc_split_scm_set_memo(SCM split_scm, const char *memo)
 {
-  SCM arg;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_split_scm(split_scm))
-    return;
-  if (memo == NULL)
-    return;
+    if (!gnc_is_split_scm(split_scm))
+        return;
+    if (memo == NULL)
+        return;
 
-  arg = scm_makfrom0str(memo);
+    arg = scm_makfrom0str(memo);
 
-  scm_call_2(setters.split_scm_memo, split_scm, arg);
+    scm_call_2(setters.split_scm_memo, split_scm, arg);
 }
 
 
@@ -551,18 +551,18 @@
 void
 gnc_split_scm_set_action(SCM split_scm, const char *action)
 {
-  SCM arg;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_split_scm(split_scm))
-    return;
-  if (action == NULL)
-    return;
+    if (!gnc_is_split_scm(split_scm))
+        return;
+    if (action == NULL)
+        return;
 
-  arg = scm_makfrom0str(action);
+    arg = scm_makfrom0str(action);
 
-  scm_call_2(setters.split_scm_action, split_scm, arg);
+    scm_call_2(setters.split_scm_action, split_scm, arg);
 }
 
 
@@ -577,16 +577,16 @@
 void
 gnc_split_scm_set_reconcile_state(SCM split_scm, char reconcile_state)
 {
-  SCM arg;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_split_scm(split_scm))
-    return;
+    if (!gnc_is_split_scm(split_scm))
+        return;
 
-  arg = SCM_MAKE_CHAR(reconcile_state);
+    arg = SCM_MAKE_CHAR(reconcile_state);
 
-  scm_call_2(setters.split_scm_reconcile_state, split_scm, arg);
+    scm_call_2(setters.split_scm_reconcile_state, split_scm, arg);
 }
 
 
@@ -601,15 +601,15 @@
 void
 gnc_split_scm_set_amount(SCM split_scm, gnc_numeric amount)
 {
-  SCM arg;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_split_scm(split_scm))
-    return;
+    if (!gnc_is_split_scm(split_scm))
+        return;
 
-  arg = gnc_numeric_to_scm(amount);
-  scm_call_2(setters.split_scm_amount, split_scm, arg);
+    arg = gnc_numeric_to_scm(amount);
+    scm_call_2(setters.split_scm_amount, split_scm, arg);
 }
 
 
@@ -624,15 +624,15 @@
 void
 gnc_split_scm_set_value(SCM split_scm, gnc_numeric value)
 {
-  SCM arg;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_split_scm(split_scm))
-    return;
+    if (!gnc_is_split_scm(split_scm))
+        return;
 
-  arg = gnc_numeric_to_scm(value);
-  scm_call_2(setters.split_scm_value, split_scm, arg);
+    arg = gnc_numeric_to_scm(value);
+    scm_call_2(setters.split_scm_value, split_scm, arg);
 }
 
 
@@ -646,18 +646,18 @@
 char *
 gnc_split_scm_get_memo(SCM split_scm)
 {
-  SCM result;
+    SCM result;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_split_scm(split_scm))
-    return NULL;
+    if (!gnc_is_split_scm(split_scm))
+        return NULL;
 
-  result = scm_call_1(getters.split_scm_memo, split_scm);
-  if (!SCM_STRINGP(result))
-    return NULL;
+    result = scm_call_1(getters.split_scm_memo, split_scm);
+    if (!SCM_STRINGP(result))
+        return NULL;
 
-  return g_strdup(SCM_STRING_CHARS(result));
+    return g_strdup(SCM_STRING_CHARS(result));
 }
 
 
@@ -671,18 +671,18 @@
 char *
 gnc_split_scm_get_action(SCM split_scm)
 {
-  SCM result;
+    SCM result;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_split_scm(split_scm))
-    return NULL;
+    if (!gnc_is_split_scm(split_scm))
+        return NULL;
 
-  result = scm_call_1(getters.split_scm_action, split_scm);
-  if (!SCM_STRINGP(result))
-    return NULL;
+    result = scm_call_1(getters.split_scm_action, split_scm);
+    if (!SCM_STRINGP(result))
+        return NULL;
 
-  return g_strdup(SCM_STRING_CHARS(result));
+    return g_strdup(SCM_STRING_CHARS(result));
 }
 
 
@@ -696,18 +696,18 @@
 gnc_numeric
 gnc_split_scm_get_amount(SCM split_scm)
 {
-  SCM result;
+    SCM result;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_split_scm(split_scm))
-    return gnc_numeric_zero ();
+    if (!gnc_is_split_scm(split_scm))
+        return gnc_numeric_zero ();
 
-  result = scm_call_1(getters.split_scm_amount, split_scm);
-  if (!gnc_numeric_p(result))
-    return gnc_numeric_zero ();
+    result = scm_call_1(getters.split_scm_amount, split_scm);
+    if (!gnc_numeric_p(result))
+        return gnc_numeric_zero ();
 
-  return gnc_scm_to_numeric(result);
+    return gnc_scm_to_numeric(result);
 }
 
 
@@ -721,18 +721,18 @@
 gnc_numeric
 gnc_split_scm_get_value(SCM split_scm)
 {
-  SCM result;
+    SCM result;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_split_scm(split_scm))
-    return gnc_numeric_zero ();
+    if (!gnc_is_split_scm(split_scm))
+        return gnc_numeric_zero ();
 
-  result = scm_call_1(getters.split_scm_value, split_scm);
-  if (!gnc_numeric_p(result))
-    return gnc_numeric_zero ();
+    result = scm_call_1(getters.split_scm_value, split_scm);
+    if (!gnc_numeric_p(result))
+        return gnc_numeric_zero ();
 
-  return gnc_scm_to_numeric(result);
+    return gnc_scm_to_numeric(result);
 }
 
 
@@ -748,23 +748,23 @@
 SCM
 gnc_copy_trans(Transaction *trans, gboolean use_cut_semantics)
 {
-  static swig_type_info *trans_type = NULL;
-  SCM func;
-  SCM arg;
+    static swig_type_info *trans_type = NULL;
+    SCM func;
+    SCM arg;
 
-  if (trans == NULL)
-    return SCM_UNDEFINED;
+    if (trans == NULL)
+        return SCM_UNDEFINED;
 
-  func = scm_c_eval_string("gnc:transaction->transaction-scm");
-  if (!SCM_PROCEDUREP(func))
-    return SCM_UNDEFINED;
+    func = scm_c_eval_string("gnc:transaction->transaction-scm");
+    if (!SCM_PROCEDUREP(func))
+        return SCM_UNDEFINED;
 
-  if (!trans_type)
-      trans_type = SWIG_TypeQuery("_p_Transaction");
+    if (!trans_type)
+        trans_type = SWIG_TypeQuery("_p_Transaction");
 
-  arg = SWIG_NewPointerObj(trans, trans_type, 0);
+    arg = SWIG_NewPointerObj(trans, trans_type, 0);
 
-  return scm_call_2(func, arg, SCM_BOOL(use_cut_semantics));
+    return scm_call_2(func, arg, SCM_BOOL(use_cut_semantics));
 }
 
 
@@ -781,8 +781,8 @@
 gnc_copy_trans_scm_onto_trans(SCM trans_scm, Transaction *trans,
                               gboolean do_commit, QofBook *book)
 {
-  gnc_copy_trans_scm_onto_trans_swap_accounts(trans_scm, trans, NULL, NULL,
-                                              do_commit, book);
+    gnc_copy_trans_scm_onto_trans_swap_accounts(trans_scm, trans, NULL, NULL,
+            do_commit, book);
 }
 
 
@@ -801,82 +801,82 @@
 \********************************************************************/
 void
 gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm,
-                                            Transaction *trans,
-                                            const GUID *guid_1,
-                                            const GUID *guid_2,
-                                            gboolean do_commit,
-                                            QofBook *book)
+        Transaction *trans,
+        const GUID *guid_1,
+        const GUID *guid_2,
+        gboolean do_commit,
+        QofBook *book)
 {
-  static swig_type_info *trans_type = NULL;
-  SCM result;
-  SCM func;
-  SCM arg;
+    static swig_type_info *trans_type = NULL;
+    SCM result;
+    SCM func;
+    SCM arg;
 
-  if (trans_scm == SCM_UNDEFINED)
-    return;
+    if (trans_scm == SCM_UNDEFINED)
+        return;
 
-  if (trans == NULL)
-    return;
+    if (trans == NULL)
+        return;
 
-  g_return_if_fail (book);
+    g_return_if_fail (book);
 
-  func = scm_c_eval_string("gnc:transaction-scm?");
-  if (!SCM_PROCEDUREP(func))
-    return;
+    func = scm_c_eval_string("gnc:transaction-scm?");
+    if (!SCM_PROCEDUREP(func))
+        return;
 
-  result = scm_call_1(func, trans_scm);
-  if (!SCM_NFALSEP(result))
-    return;
+    result = scm_call_1(func, trans_scm);
+    if (!SCM_NFALSEP(result))
+        return;
 
-  func = scm_c_eval_string("gnc:transaction-scm-onto-transaction");
-  if (!SCM_PROCEDUREP(func))
-    return;
+    func = scm_c_eval_string("gnc:transaction-scm-onto-transaction");
+    if (!SCM_PROCEDUREP(func))
+        return;
 
-  if (!trans_type)
-      trans_type = SWIG_TypeQuery("_p_Transaction");
+    if (!trans_type)
+        trans_type = SWIG_TypeQuery("_p_Transaction");
 
-  arg = SWIG_NewPointerObj(trans, trans_type, 0);
+    arg = SWIG_NewPointerObj(trans, trans_type, 0);
 
-  if ((guid_1 == NULL) || (guid_2 == NULL))
-  {
-    SCM args = SCM_EOL;
-    SCM commit;
+    if ((guid_1 == NULL) || (guid_2 == NULL))
+    {
+        SCM args = SCM_EOL;
+        SCM commit;
 
-    commit = SCM_BOOL(do_commit);
+        commit = SCM_BOOL(do_commit);
 
-    args = scm_cons(gnc_book_to_scm (book), args);
-    args = scm_cons(commit, args);
-    args = scm_cons(SCM_EOL, args);
-    args = scm_cons(arg, args);
-    args = scm_cons(trans_scm, args);
+        args = scm_cons(gnc_book_to_scm (book), args);
+        args = scm_cons(commit, args);
+        args = scm_cons(SCM_EOL, args);
+        args = scm_cons(arg, args);
+        args = scm_cons(trans_scm, args);
 
-    scm_apply(func, args, SCM_EOL);
-  }
-  else
-  {
-    SCM from, to;
-    SCM map = SCM_EOL;
-    SCM args = SCM_EOL;
-    SCM commit;
+        scm_apply(func, args, SCM_EOL);
+    }
+    else
+    {
+        SCM from, to;
+        SCM map = SCM_EOL;
+        SCM args = SCM_EOL;
+        SCM commit;
 
-    args = scm_cons(gnc_book_to_scm (book), args);
+        args = scm_cons(gnc_book_to_scm (book), args);
 
-    commit = SCM_BOOL(do_commit);
+        commit = SCM_BOOL(do_commit);
 
-    args = scm_cons(commit, args);
+        args = scm_cons(commit, args);
 
-    from = scm_makfrom0str(guid_to_string(guid_1));
-    to = scm_makfrom0str(guid_to_string(guid_2));
+        from = scm_makfrom0str(guid_to_string(guid_1));
+        to = scm_makfrom0str(guid_to_string(guid_2));
 
-    map = scm_cons(scm_cons(from, to), map);
-    map = scm_cons(scm_cons(to, from), map);
+        map = scm_cons(scm_cons(from, to), map);
+        map = scm_cons(scm_cons(to, from), map);
 
-    args = scm_cons(map, args);
-    args = scm_cons(arg, args);
-    args = scm_cons(trans_scm, args);
+        args = scm_cons(map, args);
+        args = scm_cons(arg, args);
+        args = scm_cons(trans_scm, args);
 
-    scm_apply(func, args, SCM_EOL);
-  }
+        scm_apply(func, args, SCM_EOL);
+    }
 }
 
 /********************************************************************\
@@ -890,18 +890,18 @@
 void
 gnc_trans_scm_set_date(SCM trans_scm, Timespec *ts)
 {
-  SCM arg;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_trans_scm(trans_scm))
-    return;
-  if (ts == NULL)
-    return;
+    if (!gnc_is_trans_scm(trans_scm))
+        return;
+    if (ts == NULL)
+        return;
 
-  arg = gnc_timespec2timepair(*ts);
+    arg = gnc_timespec2timepair(*ts);
 
-  scm_call_2(setters.trans_scm_date, trans_scm, arg);
+    scm_call_2(setters.trans_scm_date, trans_scm, arg);
 }
 
 
@@ -916,18 +916,18 @@
 void
 gnc_trans_scm_set_num(SCM trans_scm, const char *num)
 {
-  SCM arg;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_trans_scm(trans_scm))
-    return;
-  if (num == NULL)
-    return;
+    if (!gnc_is_trans_scm(trans_scm))
+        return;
+    if (num == NULL)
+        return;
 
-  arg = scm_makfrom0str(num);
+    arg = scm_makfrom0str(num);
 
-  scm_call_2(setters.trans_scm_num, trans_scm, arg);
+    scm_call_2(setters.trans_scm_num, trans_scm, arg);
 }
 
 
@@ -942,18 +942,18 @@
 void
 gnc_trans_scm_set_description(SCM trans_scm, const char *description)
 {
-  SCM arg;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_trans_scm(trans_scm))
-    return;
-  if (description == NULL)
-    return;
+    if (!gnc_is_trans_scm(trans_scm))
+        return;
+    if (description == NULL)
+        return;
 
-  arg = scm_makfrom0str(description);
+    arg = scm_makfrom0str(description);
 
-  scm_call_2(setters.trans_scm_description, trans_scm, arg);
+    scm_call_2(setters.trans_scm_description, trans_scm, arg);
 }
 
 
@@ -968,18 +968,18 @@
 void
 gnc_trans_scm_set_notes(SCM trans_scm, const char *notes)
 {
-  SCM arg;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_trans_scm(trans_scm))
-    return;
-  if (notes == NULL)
-    return;
+    if (!gnc_is_trans_scm(trans_scm))
+        return;
+    if (notes == NULL)
+        return;
 
-  arg = scm_makfrom0str(notes);
+    arg = scm_makfrom0str(notes);
 
-  scm_call_2(setters.trans_scm_notes, trans_scm, arg);
+    scm_call_2(setters.trans_scm_notes, trans_scm, arg);
 }
 
 
@@ -994,14 +994,14 @@
 void
 gnc_trans_scm_append_split_scm(SCM trans_scm, SCM split_scm)
 {
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_trans_scm(trans_scm))
-    return;
-  if (!gnc_is_split_scm(split_scm))
-    return;
+    if (!gnc_is_trans_scm(trans_scm))
+        return;
+    if (!gnc_is_split_scm(split_scm))
+        return;
 
-  scm_call_2(setters.trans_scm_append_split_scm, trans_scm, split_scm);
+    scm_call_2(setters.trans_scm_append_split_scm, trans_scm, split_scm);
 }
 
 
@@ -1016,16 +1016,16 @@
 SCM
 gnc_trans_scm_get_split_scm(SCM trans_scm, int index)
 {
-  SCM arg;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_trans_scm(trans_scm))
-    return SCM_UNDEFINED;
+    if (!gnc_is_trans_scm(trans_scm))
+        return SCM_UNDEFINED;
 
-  arg = scm_int2num(index);
+    arg = scm_int2num(index);
 
-  return scm_call_2(getters.trans_scm_split_scm, trans_scm, arg);
+    return scm_call_2(getters.trans_scm_split_scm, trans_scm, arg);
 }
 
 
@@ -1040,21 +1040,21 @@
 SCM
 gnc_trans_scm_get_other_split_scm(SCM trans_scm, SCM split_scm)
 {
-  SCM result;
+    SCM result;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_trans_scm(trans_scm))
-    return SCM_UNDEFINED;
-  if (!gnc_is_split_scm(split_scm))
-    return SCM_UNDEFINED;
+    if (!gnc_is_trans_scm(trans_scm))
+        return SCM_UNDEFINED;
+    if (!gnc_is_split_scm(split_scm))
+        return SCM_UNDEFINED;
 
-  result = scm_call_2(getters.trans_scm_other_split_scm, trans_scm, split_scm);
+    result = scm_call_2(getters.trans_scm_other_split_scm, trans_scm, split_scm);
 
-  if (!gnc_is_split_scm(result))
-    return SCM_UNDEFINED;
+    if (!gnc_is_split_scm(result))
+        return SCM_UNDEFINED;
 
-  return result;
+    return result;
 }
 
 
@@ -1068,19 +1068,19 @@
 int
 gnc_trans_scm_get_num_splits(SCM trans_scm)
 {
-  SCM result;
+    SCM result;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (!gnc_is_trans_scm(trans_scm))
-    return 0;
+    if (!gnc_is_trans_scm(trans_scm))
+        return 0;
 
-  result = scm_call_1(getters.trans_scm_split_scms, trans_scm);
+    result = scm_call_1(getters.trans_scm_split_scms, trans_scm);
 
-  if (!SCM_LISTP(result))
-    return 0;
+    if (!SCM_LISTP(result))
+        return 0;
 
-  return SCM_LENGTH(result);
+    return SCM_LENGTH(result);
 }
 
 
@@ -1094,28 +1094,28 @@
 char *
 gnc_get_debit_string(GNCAccountType account_type)
 {
-  const gchar *string;
-  SCM result;
-  SCM arg;
+    const gchar *string;
+    SCM result;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (gnc_gconf_get_bool(GCONF_GENERAL, KEY_ACCOUNTING_LABELS, NULL))
-    return g_strdup(_("Debit"));
+    if (gnc_gconf_get_bool(GCONF_GENERAL, KEY_ACCOUNTING_LABELS, NULL))
+        return g_strdup(_("Debit"));
 
-  if ((account_type < ACCT_TYPE_NONE) || (account_type >= NUM_ACCOUNT_TYPES))
-    account_type = ACCT_TYPE_NONE;
+    if ((account_type < ACCT_TYPE_NONE) || (account_type >= NUM_ACCOUNT_TYPES))
+        account_type = ACCT_TYPE_NONE;
 
-  arg = scm_long2num(account_type);
+    arg = scm_long2num(account_type);
 
-  result = scm_call_1(getters.debit_string, arg);
-  if (!SCM_STRINGP(result))
+    result = scm_call_1(getters.debit_string, arg);
+    if (!SCM_STRINGP(result))
+        return NULL;
+
+    string = SCM_STRING_CHARS(result);
+    if (string)
+        return g_strdup(string);
     return NULL;
-
-  string = SCM_STRING_CHARS(result);
-  if (string)
-    return g_strdup(string);
-  return NULL;
 }
 
 
@@ -1129,28 +1129,28 @@
 char *
 gnc_get_credit_string(GNCAccountType account_type)
 {
-  const gchar *string;
-  SCM result;
-  SCM arg;
+    const gchar *string;
+    SCM result;
+    SCM arg;
 
-  initialize_scm_functions();
+    initialize_scm_functions();
 
-  if (gnc_gconf_get_bool(GCONF_GENERAL, KEY_ACCOUNTING_LABELS, NULL))
-    return g_strdup(_("Credit"));
+    if (gnc_gconf_get_bool(GCONF_GENERAL, KEY_ACCOUNTING_LABELS, NULL))
+        return g_strdup(_("Credit"));
 
-  if ((account_type < ACCT_TYPE_NONE) || (account_type >= NUM_ACCOUNT_TYPES))
-    account_type = ACCT_TYPE_NONE;
+    if ((account_type < ACCT_TYPE_NONE) || (account_type >= NUM_ACCOUNT_TYPES))
+        account_type = ACCT_TYPE_NONE;
 
-  arg = scm_long2num(account_type);
+    arg = scm_long2num(account_type);
 
-  result = scm_call_1(getters.credit_string, arg);
-  if (!SCM_STRINGP(result))
+    result = scm_call_1(getters.credit_string, arg);
+    if (!SCM_STRINGP(result))
+        return NULL;
+
+    string = SCM_STRING_CHARS(result);
+    if (string)
+        return g_strdup(string);
     return NULL;
-
-  string = SCM_STRING_CHARS(result);
-  if (string)
-    return g_strdup(string);
-  return NULL;
 }
 
 
@@ -1159,153 +1159,163 @@
  *  lines, and removes all leading/trailing white space. */
 gchar *gnc_guile_strip_comments (const gchar *raw_text)
 {
-  gchar *text, **splits;
-  gint i, j;
+    gchar *text, **splits;
+    gint i, j;
 
-  splits = g_strsplit(raw_text, "\n", -1);
-  for (i = j = 0; splits[i]; i++) {
-    if ((splits[i][0] == ';') || (splits[i][0] == '\0')) {
-      g_free(splits[i]);
-      continue;
+    splits = g_strsplit(raw_text, "\n", -1);
+    for (i = j = 0; splits[i]; i++)
+    {
+        if ((splits[i][0] == ';') || (splits[i][0] == '\0'))
+        {
+            g_free(splits[i]);
+            continue;
+        }
+        splits[j++] = g_strstrip(splits[i]);
     }
-    splits[j++] = g_strstrip(splits[i]);
-  }
-  splits[j] = NULL;
+    splits[j] = NULL;
 
-  text = g_strjoinv(" ", splits);
-  g_strfreev(splits);
-  return text;
+    text = g_strjoinv(" ", splits);
+    g_strfreev(splits);
+    return text;
 }
 
 
 static void
 on_child_exit (GPid pid, gint status, gpointer data)
 {
-  Process *proc = data;
-  g_return_if_fail (proc && proc->pid == pid);
+    Process *proc = data;
+    g_return_if_fail (proc && proc->pid == pid);
 
-  g_spawn_close_pid (proc->pid);
+    g_spawn_close_pid (proc->pid);
 
-  /* free if the process is both dead and detached */
-  if (!proc->detached)
-    proc->dead = TRUE;
-  else
-    g_free (proc);
+    /* free if the process is both dead and detached */
+    if (!proc->detached)
+        proc->dead = TRUE;
+    else
+        g_free (proc);
 }
 
 Process *
 gnc_spawn_process_async (GList *argl, const gboolean search_path)
 {
-  gboolean retval;
-  Process *proc;
-  GList *l_iter;
-  guint argc;
-  gchar **argv, **v_iter;
-  GSpawnFlags flags;
-  GError *error = NULL;
+    gboolean retval;
+    Process *proc;
+    GList *l_iter;
+    guint argc;
+    gchar **argv, **v_iter;
+    GSpawnFlags flags;
+    GError *error = NULL;
 
-  proc = g_new0 (Process, 1);
+    proc = g_new0 (Process, 1);
 
-  argc = g_list_length (argl);
-  argv = g_malloc ((argc+1) * sizeof(gchar*));
+    argc = g_list_length (argl);
+    argv = g_malloc ((argc + 1) * sizeof(gchar*));
 
-  for (l_iter=argl, v_iter=argv; l_iter; l_iter=l_iter->next, v_iter++) {
-    *v_iter = (gchar*) l_iter->data;
-  }
-  *v_iter = NULL;
-  g_list_free (argl);
+    for (l_iter = argl, v_iter = argv; l_iter; l_iter = l_iter->next, v_iter++)
+    {
+        *v_iter = (gchar*) l_iter->data;
+    }
+    *v_iter = NULL;
+    g_list_free (argl);
 
-  flags = G_SPAWN_DO_NOT_REAP_CHILD;
-  if (search_path)
-    flags |= G_SPAWN_SEARCH_PATH;
+    flags = G_SPAWN_DO_NOT_REAP_CHILD;
+    if (search_path)
+        flags |= G_SPAWN_SEARCH_PATH;
 
-  retval = g_spawn_async_with_pipes (
-    NULL, argv, NULL, flags, NULL, NULL, &proc->pid,
-    &proc->fd_stdin, &proc->fd_stdout, &proc->fd_stderr, &error);
+    retval = g_spawn_async_with_pipes (
+                 NULL, argv, NULL, flags, NULL, NULL, &proc->pid,
+                 &proc->fd_stdin, &proc->fd_stdout, &proc->fd_stderr, &error);
 
-  if (retval) {
-    g_child_watch_add (proc->pid, on_child_exit, proc);
-  } else {
-    g_warning ("Could not spawn %s: %s", *argv ? *argv : "(null)",
-               error->message ? error->message : "(null)");
-    g_free (proc);
-    proc = NULL;
-  }
-  g_strfreev (argv);
+    if (retval)
+    {
+        g_child_watch_add (proc->pid, on_child_exit, proc);
+    }
+    else
+    {
+        g_warning ("Could not spawn %s: %s", *argv ? *argv : "(null)",
+                   error->message ? error->message : "(null)");
+        g_free (proc);
+        proc = NULL;
+    }
+    g_strfreev (argv);
 
-  return proc;
+    return proc;
 }
 
 gint
 gnc_process_get_fd (const Process *proc, const gint std_fd)
 {
-  const gint *retptr = NULL;
-  g_return_val_if_fail (proc, -1);
+    const gint *retptr = NULL;
+    g_return_val_if_fail (proc, -1);
 
-  if (std_fd == 0)
-    retptr = &proc->fd_stdin;
-  else if (std_fd == 1)
-    retptr = &proc->fd_stdout;
-  else if (std_fd == 2)
-    retptr = &proc->fd_stderr;
-  else
-    g_return_val_if_reached (-1);
+    if (std_fd == 0)
+        retptr = &proc->fd_stdin;
+    else if (std_fd == 1)
+        retptr = &proc->fd_stdout;
+    else if (std_fd == 2)
+        retptr = &proc->fd_stderr;
+    else
+        g_return_val_if_reached (-1);
 
-  if (*retptr == -1)
-    g_warning ("Pipe to childs file descriptor %d is -1", std_fd);
-  return *retptr;
+    if (*retptr == -1)
+        g_warning ("Pipe to childs file descriptor %d is -1", std_fd);
+    return *retptr;
 }
 
 void
 gnc_detach_process (Process *proc, const gboolean kill_it)
 {
-  g_return_if_fail (proc && proc->pid);
+    g_return_if_fail (proc && proc->pid);
 
-  errno = 0;
-  close (proc->fd_stdin);
-  if (errno) {
-    g_message ("Close of childs stdin (%d) failed: %s", proc->fd_stdin,
-	       g_strerror (errno));
     errno = 0;
-  }
-  close (proc->fd_stdout);
-  if (errno) {
-    g_message ("Close of childs stdout (%d) failed: %s", proc->fd_stdout,
-	       g_strerror(errno));
-    errno = 0;
-  }
-  close (proc->fd_stderr);
-  if (errno) {
-    g_message ("Close of childs stderr (%d) failed: %s", proc->fd_stderr,
-	       g_strerror(errno));
-    errno = 0;
-  }
+    close (proc->fd_stdin);
+    if (errno)
+    {
+        g_message ("Close of childs stdin (%d) failed: %s", proc->fd_stdin,
+                   g_strerror (errno));
+        errno = 0;
+    }
+    close (proc->fd_stdout);
+    if (errno)
+    {
+        g_message ("Close of childs stdout (%d) failed: %s", proc->fd_stdout,
+                   g_strerror(errno));
+        errno = 0;
+    }
+    close (proc->fd_stderr);
+    if (errno)
+    {
+        g_message ("Close of childs stderr (%d) failed: %s", proc->fd_stderr,
+                   g_strerror(errno));
+        errno = 0;
+    }
 
-  if (kill_it && !proc->dead) {
-    /* give it a chance to die */
-    while (g_main_context_iteration (NULL, FALSE) && !proc->dead)
-      ;
+    if (kill_it && !proc->dead)
+    {
+        /* give it a chance to die */
+        while (g_main_context_iteration (NULL, FALSE) && !proc->dead)
+            ;
+        if (!proc->dead)
+            gnc_gpid_kill (proc->pid);
+    }
+
+    /* free if the process is both dead and detached */
     if (!proc->dead)
-      gnc_gpid_kill (proc->pid);
-  }
-
-  /* free if the process is both dead and detached */
-  if (!proc->dead)
-    proc->detached = TRUE;
-  else
-    g_free (proc);
+        proc->detached = TRUE;
+    else
+        g_free (proc);
 }
 
 
 time_t
 gnc_parse_time_to_timet(const gchar *s, const gchar *format)
 {
-  struct tm tm;
+    struct tm tm;
 
-  g_return_val_if_fail(s && format, -1);
+    g_return_val_if_fail(s && format, -1);
 
-  if (!strptime(s, format, &tm))
-    return -1;
+    if (!strptime(s, format, &tm))
+        return -1;
 
-  return mktime(&tm);
+    return mktime(&tm);
 }

Modified: gnucash/trunk/src/app-utils/guile-util.h
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/guile-util.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -72,11 +72,11 @@
 void   gnc_copy_trans_scm_onto_trans(SCM trans_scm, Transaction *trans,
                                      gboolean do_commit, QofBook *book);
 void   gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm,
-                                                   Transaction *trans,
-                                                   const GUID *guid_1,
-                                                   const GUID *guid_2,
-                                                   gboolean do_commit,
-                                                   QofBook *book);
+        Transaction *trans,
+        const GUID *guid_1,
+        const GUID *guid_2,
+        gboolean do_commit,
+        QofBook *book);
 
 void   gnc_trans_scm_set_date(SCM trans_scm, Timespec *ts);
 void   gnc_trans_scm_set_num(SCM trans_scm, const char *num);

Modified: gnucash/trunk/src/app-utils/option-util.c
===================================================================
--- gnucash/trunk/src/app-utils/option-util.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/option-util.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -36,7 +36,7 @@
 
 #include "swig-runtime.h"
 
-/* TODO: 
+/* TODO:
 
   - for make-date-option, there seems to be only support for getting,
     not for setting.
@@ -47,72 +47,73 @@
 
 struct gnc_option
 {
-  /* Handle to the scheme-side option */
-  SCM guile_option;
+    /* Handle to the scheme-side option */
+    SCM guile_option;
 
-  /* Flag to indicate change by the UI */
-  gboolean changed;
+    /* Flag to indicate change by the UI */
+    gboolean changed;
 
-  /* The widget which is holding this option */
-  gncUIWidget widget;
+    /* The widget which is holding this option */
+    gncUIWidget widget;
 
-  /* The option db which holds this option */
-  GNCOptionDB *odb;
+    /* The option db which holds this option */
+    GNCOptionDB *odb;
 };
 
 struct gnc_option_section
 {
-  char * section_name;
+    char * section_name;
 
-  GSList * options;
+    GSList * options;
 };
 
 struct gnc_option_db
 {
-  SCM guile_options;
+    SCM guile_options;
 
-  GSList *option_sections;
+    GSList *option_sections;
 
-  gboolean options_dirty;
+    gboolean options_dirty;
 
-  GNCOptionDBHandle handle;
+    GNCOptionDBHandle handle;
 
-  GNCOptionGetUIValue get_ui_value;
-  GNCOptionSetUIValue set_ui_value;
-  GNCOptionSetSelectable set_selectable;
+    GNCOptionGetUIValue get_ui_value;
+    GNCOptionSetUIValue set_ui_value;
+    GNCOptionSetSelectable set_selectable;
 };
 
 typedef struct _Getters Getters;
 struct _Getters
 {
-  SCM section;
-  SCM name;
-  SCM type;
-  SCM sort_tag;
-  SCM documentation;
-  SCM getter;
-  SCM setter;
-  SCM default_getter;
-  SCM value_validator;
-  SCM option_data;
-  SCM index_to_name;
-  SCM index_to_description;
-  SCM index_to_value;
-  SCM value_to_index;
-  SCM number_of_indices;
-  SCM option_widget_changed_cb;
-  SCM date_option_subtype;
-  SCM date_option_show_time;
-  SCM date_option_value_type;
-  SCM date_option_value_absolute;
-  SCM date_option_value_relative;
+    SCM section;
+    SCM name;
+    SCM type;
+    SCM sort_tag;
+    SCM documentation;
+    SCM getter;
+    SCM setter;
+    SCM default_getter;
+    SCM value_validator;
+    SCM option_data;
+    SCM index_to_name;
+    SCM index_to_description;
+    SCM index_to_value;
+    SCM value_to_index;
+    SCM number_of_indices;
+    SCM option_widget_changed_cb;
+    SCM date_option_subtype;
+    SCM date_option_show_time;
+    SCM date_option_value_type;
+    SCM date_option_value_absolute;
+    SCM date_option_value_relative;
 };
 
 
 /****** Globals ****************************************************/
 
 static Getters getters = {0, 0, 0, 0, 0, 0, 0, 0, 0,
-                          0, 0, 0, 0, 0, 0, 0, 0, 0};
+                          0, 0, 0, 0, 0, 0, 0, 0, 0
+                         };
 
 /* This static indicates the debugging module this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_GUI;
@@ -126,61 +127,61 @@
 gboolean
 gnc_option_get_changed (GNCOption *option)
 {
-  if (!option) return FALSE;
-  return option->changed;
+    if (!option) return FALSE;
+    return option->changed;
 }
 
 void
 gnc_option_set_changed (GNCOption *option, gboolean changed)
 {
-  g_return_if_fail (option != NULL);
-  option->changed = changed;
+    g_return_if_fail (option != NULL);
+    option->changed = changed;
 }
 
 gncUIWidget
 gnc_option_get_widget (GNCOption *option)
 {
-  if (!option) return NULL;
-  return option->widget;
+    if (!option) return NULL;
+    return option->widget;
 }
 
 void
 gnc_option_set_widget (GNCOption *option, gncUIWidget widget)
 {
-  g_return_if_fail (option != NULL);
-  option->widget = widget;
+    g_return_if_fail (option != NULL);
+    option->widget = widget;
 }
 
 SCM
 gnc_option_get_ui_value (GNCOption *option)
 {
-  g_return_val_if_fail (option != NULL, SCM_UNDEFINED);
-  g_return_val_if_fail (option->odb != NULL, SCM_UNDEFINED);
-  g_return_val_if_fail (option->odb->get_ui_value != NULL, SCM_UNDEFINED);
+    g_return_val_if_fail (option != NULL, SCM_UNDEFINED);
+    g_return_val_if_fail (option->odb != NULL, SCM_UNDEFINED);
+    g_return_val_if_fail (option->odb->get_ui_value != NULL, SCM_UNDEFINED);
 
-  return option->odb->get_ui_value (option);
+    return option->odb->get_ui_value (option);
 }
 
 void
 gnc_option_set_ui_value (GNCOption *option, gboolean use_default)
 {
-  g_return_if_fail (option != NULL);
-  g_return_if_fail (option->odb != NULL);
+    g_return_if_fail (option != NULL);
+    g_return_if_fail (option->odb != NULL);
 
-  if (!option->odb->set_ui_value)
-    return;
+    if (!option->odb->set_ui_value)
+        return;
 
-  option->odb->set_ui_value (option, use_default);
+    option->odb->set_ui_value (option, use_default);
 }
 
 void
 gnc_option_set_selectable (GNCOption *option, gboolean selectable)
 {
-  g_return_if_fail (option != NULL);
-  g_return_if_fail (option->odb != NULL);
-  g_return_if_fail (option->odb->set_selectable != NULL);
+    g_return_if_fail (option != NULL);
+    g_return_if_fail (option->odb != NULL);
+    g_return_if_fail (option->odb->set_selectable != NULL);
 
-  option->odb->set_selectable (option, selectable);
+    option->odb->set_selectable (option, selectable);
 }
 
 /********************************************************************\
@@ -193,9 +194,9 @@
 static void
 gnc_option_db_init(GNCOptionDB *odb)
 {
-  SCM func = scm_c_eval_string("gnc:send-options");
+    SCM func = scm_c_eval_string("gnc:send-options");
 
-  scm_call_2(func, scm_int2num(odb->handle), odb->guile_options);
+    scm_call_2(func, scm_int2num(odb->handle), odb->guile_options);
 }
 
 
@@ -209,132 +210,141 @@
 GNCOptionDB *
 gnc_option_db_new(SCM guile_options)
 {
-  GNCOptionDB *odb;
-  GNCOptionDB *lookup;
+    GNCOptionDB *odb;
+    GNCOptionDB *lookup;
 
-  odb = g_new0(GNCOptionDB, 1);
+    odb = g_new0(GNCOptionDB, 1);
 
-  odb->guile_options = guile_options;
-  scm_gc_protect_object(guile_options);
+    odb->guile_options = guile_options;
+    scm_gc_protect_object(guile_options);
 
-  odb->option_sections = NULL;
-  odb->options_dirty = FALSE;
+    odb->option_sections = NULL;
+    odb->options_dirty = FALSE;
 
-  if (option_dbs == NULL)
-    option_dbs = g_hash_table_new(g_int_hash, g_int_equal);
+    if (option_dbs == NULL)
+        option_dbs = g_hash_table_new(g_int_hash, g_int_equal);
 
-  do
-  {
-    odb->handle = last_db_handle++;
-    lookup = g_hash_table_lookup(option_dbs, &odb->handle);
-  } while (lookup != NULL);
+    do
+    {
+        odb->handle = last_db_handle++;
+        lookup = g_hash_table_lookup(option_dbs, &odb->handle);
+    }
+    while (lookup != NULL);
 
-  g_hash_table_insert(option_dbs, &odb->handle, odb);
+    g_hash_table_insert(option_dbs, &odb->handle, odb);
 
-  gnc_option_db_init(odb);
+    gnc_option_db_init(odb);
 
-  return odb;
+    return odb;
 }
 
 typedef struct
 {
-  GNCOptionDB *odb;
-  SCM guile_options;
+    GNCOptionDB *odb;
+    SCM guile_options;
 } ODBFindInfo;
 
 static void
 option_db_finder (gpointer key, gpointer value, gpointer data)
 {
-  ODBFindInfo *find_info = data;
-  GNCOptionDB *odb = value;
+    ODBFindInfo *find_info = data;
+    GNCOptionDB *odb = value;
 
-  if (odb && (odb->guile_options == find_info->guile_options))
-    find_info->odb = odb;
+    if (odb && (odb->guile_options == find_info->guile_options))
+        find_info->odb = odb;
 }
 
 static GNCOptionDB *
 gnc_option_db_find (SCM guile_options)
 {
-  ODBFindInfo find_info;
+    ODBFindInfo find_info;
 
-  find_info.odb = NULL;
-  find_info.guile_options = guile_options;
+    find_info.odb = NULL;
+    find_info.guile_options = guile_options;
 
-  g_hash_table_foreach (option_dbs, option_db_finder, &find_info);
+    g_hash_table_foreach (option_dbs, option_db_finder, &find_info);
 
-  return find_info.odb;
+    return find_info.odb;
 }
 
 /* Create an option DB for a particular data type */
 GNCOptionDB *
 gnc_option_db_new_for_type(QofIdType id_type)
 {
-  SCM options;
+    SCM options;
 
-  if (!id_type) return NULL;
-  options = gnc_make_kvp_options(id_type);
-  return gnc_option_db_new (options);
+    if (!id_type) return NULL;
+    options = gnc_make_kvp_options(id_type);
+    return gnc_option_db_new (options);
 }
 
 void
 gnc_option_db_load_from_kvp(GNCOptionDB* odb, kvp_frame *slots)
 {
-  static SCM kvp_to_scm = SCM_UNDEFINED;
-  static SCM kvp_option_path = SCM_UNDEFINED;
-  SCM scm_slots;
+    static SCM kvp_to_scm = SCM_UNDEFINED;
+    static SCM kvp_option_path = SCM_UNDEFINED;
+    SCM scm_slots;
 
-  if (!odb || !slots) return;
+    if (!odb || !slots) return;
 
-  if (kvp_to_scm == SCM_UNDEFINED) {
-    kvp_to_scm = scm_c_eval_string("gnc:options-kvp->scm");
-    if (!SCM_PROCEDUREP (kvp_to_scm)) {
-      PERR ("not a procedure\n");
-      kvp_to_scm = SCM_UNDEFINED;
-      return;
+    if (kvp_to_scm == SCM_UNDEFINED)
+    {
+        kvp_to_scm = scm_c_eval_string("gnc:options-kvp->scm");
+        if (!SCM_PROCEDUREP (kvp_to_scm))
+        {
+            PERR ("not a procedure\n");
+            kvp_to_scm = SCM_UNDEFINED;
+            return;
+        }
     }
-  }
 
-  if (kvp_option_path == SCM_UNDEFINED) {
-    kvp_option_path = scm_c_eval_string("gnc:*kvp-option-path*");
-    if (kvp_option_path == SCM_UNDEFINED) {
-      PERR ("can't find the option path"); 
-      return;
+    if (kvp_option_path == SCM_UNDEFINED)
+    {
+        kvp_option_path = scm_c_eval_string("gnc:*kvp-option-path*");
+        if (kvp_option_path == SCM_UNDEFINED)
+        {
+            PERR ("can't find the option path");
+            return;
+        }
     }
-  }
-  scm_slots = SWIG_NewPointerObj(slots, SWIG_TypeQuery("_p_KvpFrame"), 0);
+    scm_slots = SWIG_NewPointerObj(slots, SWIG_TypeQuery("_p_KvpFrame"), 0);
 
-  scm_call_3 (kvp_to_scm, odb->guile_options, scm_slots, kvp_option_path);
+    scm_call_3 (kvp_to_scm, odb->guile_options, scm_slots, kvp_option_path);
 }
 
 void
 gnc_option_db_save_to_kvp(GNCOptionDB* odb, kvp_frame *slots)
 {
-  static SCM scm_to_kvp = SCM_UNDEFINED;
-  static SCM kvp_option_path = SCM_UNDEFINED;
-  SCM scm_slots;
+    static SCM scm_to_kvp = SCM_UNDEFINED;
+    static SCM kvp_option_path = SCM_UNDEFINED;
+    SCM scm_slots;
 
-  if (!odb || !slots) return;
+    if (!odb || !slots) return;
 
-  if (scm_to_kvp == SCM_UNDEFINED) {
-    scm_to_kvp = scm_c_eval_string("gnc:options-scm->kvp");
-    if (!SCM_PROCEDUREP (scm_to_kvp)) {
-      PERR ("not a procedure\n");
-      scm_to_kvp = SCM_UNDEFINED;
-      return;
+    if (scm_to_kvp == SCM_UNDEFINED)
+    {
+        scm_to_kvp = scm_c_eval_string("gnc:options-scm->kvp");
+        if (!SCM_PROCEDUREP (scm_to_kvp))
+        {
+            PERR ("not a procedure\n");
+            scm_to_kvp = SCM_UNDEFINED;
+            return;
+        }
     }
-  }
 
-  if (kvp_option_path == SCM_UNDEFINED) {
-    kvp_option_path = scm_c_eval_string("gnc:*kvp-option-path*");
-    if (kvp_option_path == SCM_UNDEFINED) {
-      PERR ("can't find the option path"); 
-      return;
+    if (kvp_option_path == SCM_UNDEFINED)
+    {
+        kvp_option_path = scm_c_eval_string("gnc:*kvp-option-path*");
+        if (kvp_option_path == SCM_UNDEFINED)
+        {
+            PERR ("can't find the option path");
+            return;
+        }
     }
-  }
 
-  scm_slots = SWIG_NewPointerObj(slots, SWIG_TypeQuery("p_KvpFrame"), 0);
+    scm_slots = SWIG_NewPointerObj(slots, SWIG_TypeQuery("p_KvpFrame"), 0);
 
-  scm_call_3 (scm_to_kvp, odb->guile_options, scm_slots, kvp_option_path);
+    scm_call_3 (scm_to_kvp, odb->guile_options, scm_slots, kvp_option_path);
 }
 
 /********************************************************************\
@@ -349,52 +359,52 @@
 void
 gnc_option_db_destroy(GNCOptionDB *odb)
 {
-  GSList *snode;
+    GSList *snode;
 
-  if (odb == NULL)
-    return;
+    if (odb == NULL)
+        return;
 
-  for (snode = odb->option_sections; snode; snode = snode->next)
-  {
-    GNCOptionSection *section = snode->data;
-    GSList *onode;
-
-    for (onode = section->options; onode; onode = onode->next)
+    for (snode = odb->option_sections; snode; snode = snode->next)
     {
-      GNCOption *option = onode->data;
+        GNCOptionSection *section = snode->data;
+        GSList *onode;
 
-      scm_gc_unprotect_object(option->guile_option);
-      g_free (option);
-    }
+        for (onode = section->options; onode; onode = onode->next)
+        {
+            GNCOption *option = onode->data;
 
-    /* Free the option list */
-    g_slist_free(section->options);
-    section->options = NULL;
+            scm_gc_unprotect_object(option->guile_option);
+            g_free (option);
+        }
 
-    if (section->section_name != NULL)
-      free(section->section_name);
-    section->section_name = NULL;
+        /* Free the option list */
+        g_slist_free(section->options);
+        section->options = NULL;
 
-    g_free (section);
-  }
+        if (section->section_name != NULL)
+            free(section->section_name);
+        section->section_name = NULL;
 
-  g_slist_free(odb->option_sections);
+        g_free (section);
+    }
 
-  odb->option_sections = NULL;
-  odb->options_dirty = FALSE;
+    g_slist_free(odb->option_sections);
 
-  g_hash_table_remove(option_dbs, &odb->handle);
+    odb->option_sections = NULL;
+    odb->options_dirty = FALSE;
 
-  if (g_hash_table_size(option_dbs) == 0)
-  {
-    g_hash_table_destroy(option_dbs);
-    option_dbs = NULL;
-  }
+    g_hash_table_remove(option_dbs, &odb->handle);
 
-  scm_gc_unprotect_object(odb->guile_options);
-  odb->guile_options = SCM_UNDEFINED;
+    if (g_hash_table_size(option_dbs) == 0)
+    {
+        g_hash_table_destroy(option_dbs);
+        option_dbs = NULL;
+    }
 
-  g_free(odb);
+    scm_gc_unprotect_object(odb->guile_options);
+    odb->guile_options = SCM_UNDEFINED;
+
+    g_free(odb);
 }
 
 void
@@ -403,11 +413,11 @@
                                 GNCOptionSetUIValue set_ui_value,
                                 GNCOptionSetSelectable set_selectable)
 {
-  g_return_if_fail (odb != NULL);
+    g_return_if_fail (odb != NULL);
 
-  odb->get_ui_value = get_ui_value;
-  odb->set_ui_value = set_ui_value;
-  odb->set_selectable = set_selectable;
+    odb->get_ui_value = get_ui_value;
+    odb->set_ui_value = set_ui_value;
+    odb->set_selectable = set_selectable;
 }
 
 /********************************************************************\
@@ -431,60 +441,60 @@
                                        const char *section,
                                        const char *name)
 {
-  SCM register_proc;
-  SCM arg;
-  SCM args;
+    SCM register_proc;
+    SCM arg;
+    SCM args;
 
-  if (!odb || !callback)
-    return SCM_UNDEFINED;
+    if (!odb || !callback)
+        return SCM_UNDEFINED;
 
-  /* Get the register procedure */
-  register_proc = scm_c_eval_string("gnc:options-register-c-callback");
-  if (!SCM_PROCEDUREP(register_proc))
-  {
-    PERR("not a procedure\n");
-    return SCM_UNDEFINED;
-  }
+    /* Get the register procedure */
+    register_proc = scm_c_eval_string("gnc:options-register-c-callback");
+    if (!SCM_PROCEDUREP(register_proc))
+    {
+        PERR("not a procedure\n");
+        return SCM_UNDEFINED;
+    }
 
-  /* Now build the args list for apply */
-  args = SCM_EOL;
+    /* Now build the args list for apply */
+    args = SCM_EOL;
 
-  /* first the guile options database */
-  args = scm_cons(odb->guile_options, args);
+    /* first the guile options database */
+    args = scm_cons(odb->guile_options, args);
 
-  /* next the data */
-  arg = SWIG_NewPointerObj(data, SWIG_TypeQuery("_p_void"), 0);
-  args = scm_cons(arg, args);
+    /* next the data */
+    arg = SWIG_NewPointerObj(data, SWIG_TypeQuery("_p_void"), 0);
+    args = scm_cons(arg, args);
 
-  /* next the callback */
-  arg = SWIG_NewPointerObj(
-      callback, SWIG_TypeQuery("GNCOptionChangeCallback"), 0);
-  args = scm_cons(arg, args);
+    /* next the callback */
+    arg = SWIG_NewPointerObj(
+              callback, SWIG_TypeQuery("GNCOptionChangeCallback"), 0);
+    args = scm_cons(arg, args);
 
-  /* next the name */
-  if (name == NULL)
-  {
-    arg = SCM_BOOL_F;
-  }
-  else
-  {
-    arg = scm_makfrom0str(name);
-  }
-  args = scm_cons(arg, args);
+    /* next the name */
+    if (name == NULL)
+    {
+        arg = SCM_BOOL_F;
+    }
+    else
+    {
+        arg = scm_makfrom0str(name);
+    }
+    args = scm_cons(arg, args);
 
-  /* next the section */
-  if (section == NULL)
-  {
-    arg = SCM_BOOL_F;
-  }
-  else
-  {
-    arg = scm_makfrom0str(section);
-  }
-  args = scm_cons(arg, args);
+    /* next the section */
+    if (section == NULL)
+    {
+        arg = SCM_BOOL_F;
+    }
+    else
+    {
+        arg = scm_makfrom0str(section);
+    }
+    args = scm_cons(arg, args);
 
-  /* now apply the procedure */
-  return scm_apply(register_proc, args, SCM_EOL);
+    /* now apply the procedure */
+    return scm_apply(register_proc, args, SCM_EOL);
 }
 
 
@@ -499,81 +509,81 @@
 void
 gnc_option_db_unregister_change_callback_id(GNCOptionDB *odb, SCM callback_id)
 {
-  SCM proc;
+    SCM proc;
 
-  if (callback_id == SCM_UNDEFINED)
-    return;
+    if (callback_id == SCM_UNDEFINED)
+        return;
 
-  proc = scm_c_eval_string("gnc:options-unregister-callback-id");
-  if (!SCM_PROCEDUREP(proc))
-  {
-    PERR("not a procedure\n");
-    return;
-  }
+    proc = scm_c_eval_string("gnc:options-unregister-callback-id");
+    if (!SCM_PROCEDUREP(proc))
+    {
+        PERR("not a procedure\n");
+        return;
+    }
 
-  scm_call_2(proc, callback_id, odb->guile_options);
+    scm_call_2(proc, callback_id, odb->guile_options);
 }
 
 void
 gncp_option_invoke_callback (GNCOptionChangeCallback callback, void *data)
 {
-  callback (data);
+    callback (data);
 }
 
 static void
 gnc_call_option_change_callbacks(GNCOptionDB *odb)
 {
-  SCM proc;
+    SCM proc;
 
-  proc = scm_c_eval_string("gnc:options-run-callbacks");
-  if (!SCM_PROCEDUREP(proc))
-  {
-    PERR("not a procedure\n");
-    return;
-  }
+    proc = scm_c_eval_string("gnc:options-run-callbacks");
+    if (!SCM_PROCEDUREP(proc))
+    {
+        PERR("not a procedure\n");
+        return;
+    }
 
-  scm_call_1(proc, odb->guile_options);
+    scm_call_1(proc, odb->guile_options);
 }
 
 
 static void
 initialize_getters(void)
 {
-  static gboolean getters_initialized = FALSE;
+    static gboolean getters_initialized = FALSE;
 
-  if (getters_initialized)
-    return;
+    if (getters_initialized)
+        return;
 
-  getters.section = scm_c_eval_string("gnc:option-section");
-  getters.name = scm_c_eval_string("gnc:option-name");
-  getters.type = scm_c_eval_string("gnc:option-type");
-  getters.sort_tag = scm_c_eval_string("gnc:option-sort-tag");
-  getters.documentation =
-    scm_c_eval_string("gnc:option-documentation");
-  getters.getter = scm_c_eval_string("gnc:option-getter");
-  getters.setter = scm_c_eval_string("gnc:option-setter");
-  getters.default_getter =
-    scm_c_eval_string("gnc:option-default-getter");
-  getters.value_validator =
-    scm_c_eval_string("gnc:option-value-validator");
-  getters.option_data = scm_c_eval_string("gnc:option-data");
-  getters.index_to_name = scm_c_eval_string("gnc:option-index-get-name");
-  getters.index_to_description =
-    scm_c_eval_string("gnc:option-index-get-description");
-  getters.number_of_indices = scm_c_eval_string("gnc:option-number-of-indices");
-  getters.index_to_value = scm_c_eval_string("gnc:option-index-get-value");
-  getters.value_to_index = scm_c_eval_string("gnc:option-value-get-index");
-  getters.option_widget_changed_cb =
-    scm_c_eval_string("gnc:option-widget-changed-proc");
-  getters.date_option_subtype = scm_c_eval_string("gnc:date-option-get-subtype");
-  getters.date_option_show_time = scm_c_eval_string("gnc:date-option-show-time?");
-  getters.date_option_value_type = scm_c_eval_string ("gnc:date-option-value-type");
-  getters.date_option_value_absolute =
-    scm_c_eval_string("gnc:date-option-absolute-time");
-  getters.date_option_value_relative =
-    scm_c_eval_string("gnc:date-option-relative-time");
+    getters.section = scm_c_eval_string("gnc:option-section");
+    getters.name = scm_c_eval_string("gnc:option-name");
+    getters.type = scm_c_eval_string("gnc:option-type");
+    getters.sort_tag = scm_c_eval_string("gnc:option-sort-tag");
+    getters.documentation =
+        scm_c_eval_string("gnc:option-documentation");
+    getters.getter = scm_c_eval_string("gnc:option-getter");
+    getters.setter = scm_c_eval_string("gnc:option-setter");
+    getters.default_getter =
+        scm_c_eval_string("gnc:option-default-getter");
+    getters.value_validator =
+        scm_c_eval_string("gnc:option-value-validator");
+    getters.option_data = scm_c_eval_string("gnc:option-data");
+    getters.index_to_name = scm_c_eval_string("gnc:option-index-get-name");
+    getters.index_to_description =
+        scm_c_eval_string("gnc:option-index-get-description");
+    getters.number_of_indices = scm_c_eval_string("gnc:option-number-of-indices");
+    getters.index_to_value = scm_c_eval_string("gnc:option-index-get-value");
+    getters.value_to_index = scm_c_eval_string("gnc:option-value-get-index");
+    getters.option_widget_changed_cb =
+        scm_c_eval_string("gnc:option-widget-changed-proc");
+    getters.date_option_subtype = scm_c_eval_string("gnc:date-option-get-subtype");
+    getters.date_option_show_time = scm_c_eval_string("gnc:date-option-show-time?");
+    getters.date_option_value_type = scm_c_eval_string ("gnc:date-option-value-type");
+    getters.date_option_value_absolute =
+        scm_c_eval_string("gnc:date-option-absolute-time");
+    getters.date_option_value_relative =
+        scm_c_eval_string("gnc:date-option-relative-time");
 
-  getters_initialized = TRUE;
+    getters_initialized = TRUE;
 }
 
 
@@ -588,9 +598,9 @@
 char *
 gnc_option_section(GNCOption *option)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return gnc_guile_call1_to_string(getters.section, option->guile_option);
+    return gnc_guile_call1_to_string(getters.section, option->guile_option);
 }
 
 
@@ -605,9 +615,9 @@
 char *
 gnc_option_name(GNCOption *option)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return gnc_guile_call1_to_string(getters.name, option->guile_option);
+    return gnc_guile_call1_to_string(getters.name, option->guile_option);
 }
 
 
@@ -622,10 +632,10 @@
 char *
 gnc_option_type(GNCOption *option)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return gnc_guile_call1_symbol_to_string(getters.type,
-                                          option->guile_option);
+    return gnc_guile_call1_symbol_to_string(getters.type,
+                                            option->guile_option);
 }
 
 
@@ -640,9 +650,9 @@
 char *
 gnc_option_sort_tag(GNCOption *option)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return gnc_guile_call1_to_string(getters.sort_tag, option->guile_option);
+    return gnc_guile_call1_to_string(getters.sort_tag, option->guile_option);
 }
 
 
@@ -657,10 +667,10 @@
 char *
 gnc_option_documentation(GNCOption *option)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return gnc_guile_call1_to_string(getters.documentation,
-                                   option->guile_option);
+    return gnc_guile_call1_to_string(getters.documentation,
+                                     option->guile_option);
 }
 
 
@@ -675,10 +685,10 @@
 SCM
 gnc_option_getter(GNCOption *option)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return gnc_guile_call1_to_procedure(getters.getter,
-                                      option->guile_option);
+    return gnc_guile_call1_to_procedure(getters.getter,
+                                        option->guile_option);
 }
 
 
@@ -693,10 +703,10 @@
 SCM
 gnc_option_setter(GNCOption *option)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return gnc_guile_call1_to_procedure(getters.setter,
-                                      option->guile_option);
+    return gnc_guile_call1_to_procedure(getters.setter,
+                                        option->guile_option);
 }
 
 
@@ -711,10 +721,10 @@
 SCM
 gnc_option_default_getter(GNCOption *option)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return gnc_guile_call1_to_procedure(getters.default_getter,
-                                      option->guile_option);
+    return gnc_guile_call1_to_procedure(getters.default_getter,
+                                        option->guile_option);
 }
 
 
@@ -729,10 +739,10 @@
 SCM
 gnc_option_value_validator(GNCOption *option)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return gnc_guile_call1_to_procedure(getters.value_validator,
-                                      option->guile_option);
+    return gnc_guile_call1_to_procedure(getters.value_validator,
+                                        option->guile_option);
 }
 
 
@@ -750,27 +760,27 @@
 SCM
 gnc_option_widget_changed_proc_getter(GNCOption *option)
 {
-  SCM cb;
+    SCM cb;
 
-  initialize_getters();
+    initialize_getters();
 
-  if( SCM_PROCEDUREP( getters.option_widget_changed_cb ) )
-  {
-    /* call the callback function getter to get the actual callback function */
-    cb = scm_call_1(getters.option_widget_changed_cb, option->guile_option);
+    if ( SCM_PROCEDUREP( getters.option_widget_changed_cb ) )
+    {
+        /* call the callback function getter to get the actual callback function */
+        cb = scm_call_1(getters.option_widget_changed_cb, option->guile_option);
 
-    if( SCM_PROCEDUREP( cb ) )   /* a callback exists */
+        if ( SCM_PROCEDUREP( cb ) )  /* a callback exists */
+        {
+            return( cb );
+        }
+        /* else no callback exists -  this is a legal situation */
+    }
+    else  /* getters not set up correctly? */
     {
-      return( cb );
+        PERR("getters.option_widget_changed_cb is not a valid procedure\n");
     }
-    /* else no callback exists -  this is a legal situation */
-  }
-  else  /* getters not set up correctly? */
-  {
-    PERR("getters.option_widget_changed_cb is not a valid procedure\n");
-  }
 
-  return( SCM_UNDEFINED );
+    return( SCM_UNDEFINED );
 }
 
 
@@ -786,19 +796,19 @@
 void
 gnc_option_call_option_widget_changed_proc(GNCOption *option)
 {
-  SCM cb, value;
+    SCM cb, value;
 
-  cb = gnc_option_widget_changed_proc_getter(option);
+    cb = gnc_option_widget_changed_proc_getter(option);
 
-  if( cb != SCM_UNDEFINED )
-  {
-    value = gnc_option_get_ui_value(option);
+    if ( cb != SCM_UNDEFINED )
+    {
+        value = gnc_option_get_ui_value(option);
 
-    if( value != SCM_UNDEFINED )
-    {
-      scm_call_1(cb, value);
+        if ( value != SCM_UNDEFINED )
+        {
+            scm_call_1(cb, value);
+        }
     }
-  }
 }
 
 
@@ -813,20 +823,20 @@
 int
 gnc_option_num_permissible_values(GNCOption *option)
 {
-  SCM value;
+    SCM value;
 
-  initialize_getters();
+    initialize_getters();
 
-  value = scm_call_1(getters.number_of_indices, option->guile_option);
+    value = scm_call_1(getters.number_of_indices, option->guile_option);
 
-  if(SCM_EXACTP(value))
-  {
-    return scm_num2int(value, SCM_ARG1, G_STRFUNC);
-  }
-  else
-  {
-    return -1;
-  }
+    if (SCM_EXACTP(value))
+    {
+        return scm_num2int(value, SCM_ARG1, G_STRFUNC);
+    }
+    else
+    {
+        return -1;
+    }
 }
 
 
@@ -842,16 +852,16 @@
 int
 gnc_option_permissible_value_index(GNCOption *option, SCM search_value)
 {
-  SCM value;
-  value = scm_call_2(getters.value_to_index, option->guile_option, search_value);
-  if (value == SCM_BOOL_F)
-  {
-    return -1;
-  }
-  else
-  {
-    return scm_num2int(value, SCM_ARG1, G_STRFUNC);
-  }
+    SCM value;
+    value = scm_call_2(getters.value_to_index, option->guile_option, search_value);
+    if (value == SCM_BOOL_F)
+    {
+        return -1;
+    }
+    else
+    {
+        return scm_num2int(value, SCM_ARG1, G_STRFUNC);
+    }
 }
 
 
@@ -868,17 +878,17 @@
 SCM
 gnc_option_permissible_value(GNCOption *option, int index)
 {
-  SCM value;
+    SCM value;
 
-  if (index < 0)
-    return SCM_UNDEFINED;
+    if (index < 0)
+        return SCM_UNDEFINED;
 
-  initialize_getters();
+    initialize_getters();
 
-  value = scm_call_2(getters.index_to_value, option->guile_option,
-                     scm_int2num(index));
+    value = scm_call_2(getters.index_to_value, option->guile_option,
+                       scm_int2num(index));
 
-  return value;
+    return value;
 }
 
 
@@ -895,21 +905,21 @@
 char *
 gnc_option_permissible_value_name(GNCOption *option, int index)
 {
-  SCM name;
+    SCM name;
 
-  if (index < 0)
-    return NULL;
+    if (index < 0)
+        return NULL;
 
-  initialize_getters();
+    initialize_getters();
 
-  name = scm_call_2(getters.index_to_name, option->guile_option,
-                    scm_int2num(index));
-  if (name == SCM_UNDEFINED)
-    return NULL;
-  if (!SCM_STRINGP(name))
-    return NULL;
-  
-  return g_strdup(SCM_STRING_CHARS(name));
+    name = scm_call_2(getters.index_to_name, option->guile_option,
+                      scm_int2num(index));
+    if (name == SCM_UNDEFINED)
+        return NULL;
+    if (!SCM_STRINGP(name))
+        return NULL;
+
+    return g_strdup(SCM_STRING_CHARS(name));
 }
 
 
@@ -926,21 +936,21 @@
 char *
 gnc_option_permissible_value_description(GNCOption *option, int index)
 {
-  SCM help;
+    SCM help;
 
-  if (index < 0)
-    return NULL;
+    if (index < 0)
+        return NULL;
 
-  initialize_getters();
+    initialize_getters();
 
-  help = scm_call_2(getters.index_to_description, option->guile_option,
-                    scm_int2num(index));
-  if (help == SCM_UNDEFINED)
-    return NULL;
-  if (!SCM_STRINGP(help))
-    return NULL;
+    help = scm_call_2(getters.index_to_description, option->guile_option,
+                      scm_int2num(index));
+    if (help == SCM_UNDEFINED)
+        return NULL;
+    if (!SCM_STRINGP(help))
+        return NULL;
 
-  return g_strdup(SCM_STRING_CHARS(help));
+    return g_strdup(SCM_STRING_CHARS(help));
 }
 
 
@@ -955,13 +965,13 @@
 gboolean
 gnc_option_show_time(GNCOption *option)
 {
-  SCM value;
+    SCM value;
 
-  initialize_getters();
+    initialize_getters();
 
-  value = scm_call_1(getters.date_option_show_time, option->guile_option);
+    value = scm_call_1(getters.date_option_show_time, option->guile_option);
 
-  return SCM_NFALSEP(value);
+    return SCM_NFALSEP(value);
 }
 
 /********************************************************************\
@@ -974,9 +984,9 @@
 SCM
 gnc_option_get_option_data(GNCOption *option)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return scm_call_1(getters.option_data, option->guile_option);
+    return scm_call_1(getters.option_data, option->guile_option);
 }
 
 
@@ -991,13 +1001,13 @@
 gboolean
 gnc_option_multiple_selection(GNCOption *option)
 {
-  SCM pair;
+    SCM pair;
 
-  initialize_getters();
+    initialize_getters();
 
-  pair = scm_call_1(getters.option_data, option->guile_option);
+    pair = scm_call_1(getters.option_data, option->guile_option);
 
-  return !SCM_NFALSEP(scm_not(SCM_CAR(pair)));
+    return !SCM_NFALSEP(scm_not(SCM_CAR(pair)));
 }
 
 /********************************************************************\
@@ -1012,32 +1022,36 @@
 GList *
 gnc_option_get_account_type_list(GNCOption *option)
 {
-  SCM pair;
-  SCM lst;
-  GList *type_list = NULL;
+    SCM pair;
+    SCM lst;
+    GList *type_list = NULL;
 
-  initialize_getters();
+    initialize_getters();
 
-  pair = scm_call_1(getters.option_data, option->guile_option);
-  lst = SCM_CDR(pair);
+    pair = scm_call_1(getters.option_data, option->guile_option);
+    lst = SCM_CDR(pair);
 
-  while (!SCM_NULLP (lst)) {
-    GNCAccountType type;
-    SCM item;
+    while (!SCM_NULLP (lst))
+    {
+        GNCAccountType type;
+        SCM item;
 
-    /* Compute this item and the rest of the list */
-    item = SCM_CAR (lst);
-    lst = SCM_CDR (lst);
+        /* Compute this item and the rest of the list */
+        item = SCM_CAR (lst);
+        lst = SCM_CDR (lst);
 
-    if (SCM_FALSEP (scm_integer_p (item))) {
-      PERR ("Invalid type");
-    } else {
-      type = scm_num2long (item, SCM_ARG1, G_STRFUNC);
-      type_list = g_list_prepend (type_list, GINT_TO_POINTER (type));
+        if (SCM_FALSEP (scm_integer_p (item)))
+        {
+            PERR ("Invalid type");
+        }
+        else
+        {
+            type = scm_num2long (item, SCM_ARG1, G_STRFUNC);
+            type_list = g_list_prepend (type_list, GINT_TO_POINTER (type));
+        }
     }
-  }
 
-  return g_list_reverse (type_list);
+    return g_list_reverse (type_list);
 }
 
 
@@ -1056,71 +1070,72 @@
                                    int    *num_decimals,
                                    double *step_size)
 {
-  SCM list;
-  SCM value;
+    SCM list;
+    SCM value;
 
-  initialize_getters();
+    initialize_getters();
 
-  list = scm_call_1(getters.option_data, option->guile_option);
+    list = scm_call_1(getters.option_data, option->guile_option);
 
-  if (!SCM_LISTP(list) || SCM_NULLP(list))
-    return FALSE;
+    if (!SCM_LISTP(list) || SCM_NULLP(list))
+        return FALSE;
 
-  /* lower bound */
-  value = SCM_CAR(list);
-  list = SCM_CDR(list);
+    /* lower bound */
+    value = SCM_CAR(list);
+    list = SCM_CDR(list);
 
-  if (!SCM_NUMBERP(value))
-    return FALSE;
+    if (!SCM_NUMBERP(value))
+        return FALSE;
 
-  if (lower_bound != NULL)
-    *lower_bound = scm_num2dbl(value, G_STRFUNC);
+    if (lower_bound != NULL)
+        *lower_bound = scm_num2dbl(value, G_STRFUNC);
 
-  if (!SCM_LISTP(list) || SCM_NULLP(list))
-    return FALSE;
+    if (!SCM_LISTP(list) || SCM_NULLP(list))
+        return FALSE;
 
-  /* upper bound */
-  value = SCM_CAR(list);
-  list = SCM_CDR(list);
+    /* upper bound */
+    value = SCM_CAR(list);
+    list = SCM_CDR(list);
 
-  if (!SCM_NUMBERP(value))
-    return FALSE;
+    if (!SCM_NUMBERP(value))
+        return FALSE;
 
-  if (upper_bound != NULL)
-    *upper_bound = scm_num2dbl(value, G_STRFUNC);
+    if (upper_bound != NULL)
+        *upper_bound = scm_num2dbl(value, G_STRFUNC);
 
-  if (!SCM_LISTP(list) || SCM_NULLP(list))
-    return FALSE;
+    if (!SCM_LISTP(list) || SCM_NULLP(list))
+        return FALSE;
 
-  /* number of decimals */
-  value = SCM_CAR(list);
-  list = SCM_CDR(list);
+    /* number of decimals */
+    value = SCM_CAR(list);
+    list = SCM_CDR(list);
 
-  if (!SCM_NUMBERP(value))
-    return FALSE;
+    if (!SCM_NUMBERP(value))
+        return FALSE;
 
-  /* Guile-1.6 returns this as a double, so let's use that in all cases.
-   * This is still safe for earlier guiles, too -- tested with 1.3.4.
-   */
-  if (num_decimals != NULL) {
-    double decimals = scm_num2dbl(value, G_STRFUNC);
-    *num_decimals = (int)decimals;
-  }
+    /* Guile-1.6 returns this as a double, so let's use that in all cases.
+     * This is still safe for earlier guiles, too -- tested with 1.3.4.
+     */
+    if (num_decimals != NULL)
+    {
+        double decimals = scm_num2dbl(value, G_STRFUNC);
+        *num_decimals = (int)decimals;
+    }
 
-  if (!SCM_LISTP(list) || SCM_NULLP(list))
-    return FALSE;
+    if (!SCM_LISTP(list) || SCM_NULLP(list))
+        return FALSE;
 
-  /* step size */
-  value = SCM_CAR(list);
-  list = SCM_CDR(list);
+    /* step size */
+    value = SCM_CAR(list);
+    list = SCM_CDR(list);
 
-  if (!SCM_NUMBERP(value))
-    return FALSE;
+    if (!SCM_NUMBERP(value))
+        return FALSE;
 
-  if (step_size != NULL)
-    *step_size = scm_num2dbl(value, G_STRFUNC);
+    if (step_size != NULL)
+        *step_size = scm_num2dbl(value, G_STRFUNC);
 
-  return TRUE;
+    return TRUE;
 }
 
 
@@ -1135,20 +1150,20 @@
 gdouble
 gnc_option_color_range(GNCOption *option)
 {
-  SCM list;
-  SCM value;
+    SCM list;
+    SCM value;
 
-  initialize_getters();
+    initialize_getters();
 
-  list = scm_call_1(getters.option_data, option->guile_option);
-  if (!SCM_LISTP(list) || SCM_NULLP(list))
-    return 0.0;
+    list = scm_call_1(getters.option_data, option->guile_option);
+    if (!SCM_LISTP(list) || SCM_NULLP(list))
+        return 0.0;
 
-  value = SCM_CAR(list);
-  if (!SCM_NUMBERP(value))
-    return 0.0;
+    value = SCM_CAR(list);
+    if (!SCM_NUMBERP(value))
+        return 0.0;
 
-  return scm_num2dbl(value, G_STRFUNC);
+    return scm_num2dbl(value, G_STRFUNC);
 }
 
 
@@ -1163,24 +1178,24 @@
 gdouble
 gnc_option_use_alpha(GNCOption *option)
 {
-  SCM list;
-  SCM value;
+    SCM list;
+    SCM value;
 
-  initialize_getters();
+    initialize_getters();
 
-  list = scm_call_1(getters.option_data, option->guile_option);
-  if (!SCM_LISTP(list) || SCM_NULLP(list))
-    return FALSE;
+    list = scm_call_1(getters.option_data, option->guile_option);
+    if (!SCM_LISTP(list) || SCM_NULLP(list))
+        return FALSE;
 
-  list = SCM_CDR(list);
-  if (!SCM_LISTP(list) || SCM_NULLP(list))
-    return FALSE;
+    list = SCM_CDR(list);
+    if (!SCM_LISTP(list) || SCM_NULLP(list))
+        return FALSE;
 
-  value = SCM_CAR(list);
-  if (!SCM_BOOLP(value))
-    return FALSE;
+    value = SCM_CAR(list);
+    if (!SCM_BOOLP(value))
+        return FALSE;
 
-  return SCM_NFALSEP(value);
+    return SCM_NFALSEP(value);
 }
 
 
@@ -1194,24 +1209,24 @@
 guint32
 gnc_option_get_color_argb(GNCOption *option)
 {
-  gdouble red, green, blue, alpha;
-  guint32 color = 0;
+    gdouble red, green, blue, alpha;
+    guint32 color = 0;
 
-  if (!gnc_option_get_color_info(option, FALSE, &red, &green, &blue, &alpha))
-    return 0;
+    if (!gnc_option_get_color_info(option, FALSE, &red, &green, &blue, &alpha))
+        return 0;
 
-  color |= (guint32) (alpha * 255.0);
-  color <<= 8;
+    color |= (guint32) (alpha * 255.0);
+    color <<= 8;
 
-  color |= (guint32) (red * 255.0);
-  color <<= 8;
+    color |= (guint32) (red * 255.0);
+    color <<= 8;
 
-  color |= (guint32) (green * 255.0);
-  color <<= 8;
+    color |= (guint32) (green * 255.0);
+    color <<= 8;
 
-  color |= (guint32) (blue * 255.0);
+    color |= (guint32) (blue * 255.0);
 
-  return color;
+    return color;
 }
 
 
@@ -1236,60 +1251,60 @@
                           gdouble *blue,
                           gdouble *alpha)
 {
-  gdouble scale;
-  gdouble rgba;
-  SCM getter;
-  SCM value;
+    gdouble scale;
+    gdouble rgba;
+    SCM getter;
+    SCM value;
 
-  if (option == NULL)
-    return FALSE;
+    if (option == NULL)
+        return FALSE;
 
-  if (use_default)
-    getter = gnc_option_default_getter(option);
-  else
-    getter = gnc_option_getter(option);
-  if (getter == SCM_UNDEFINED)
-    return FALSE;
+    if (use_default)
+        getter = gnc_option_default_getter(option);
+    else
+        getter = gnc_option_getter(option);
+    if (getter == SCM_UNDEFINED)
+        return FALSE;
 
-  value = scm_call_0(getter);
-  if (!SCM_LISTP(value) || SCM_NULLP(value) || !SCM_NUMBERP(SCM_CAR(value)))
-    return FALSE;
+    value = scm_call_0(getter);
+    if (!SCM_LISTP(value) || SCM_NULLP(value) || !SCM_NUMBERP(SCM_CAR(value)))
+        return FALSE;
 
-  scale = gnc_option_color_range(option);
-  if (scale <= 0.0)
-    return FALSE;
+    scale = gnc_option_color_range(option);
+    if (scale <= 0.0)
+        return FALSE;
 
-  scale = 1.0 / scale;
+    scale = 1.0 / scale;
 
-  rgba = scm_num2dbl(SCM_CAR(value), G_STRFUNC);
-  if (red != NULL)
-    *red = MIN(1.0, rgba * scale);
+    rgba = scm_num2dbl(SCM_CAR(value), G_STRFUNC);
+    if (red != NULL)
+        *red = MIN(1.0, rgba * scale);
 
-  value = SCM_CDR(value);
-  if (!SCM_LISTP(value) || SCM_NULLP(value) || !SCM_NUMBERP(SCM_CAR(value)))
-    return FALSE;
+    value = SCM_CDR(value);
+    if (!SCM_LISTP(value) || SCM_NULLP(value) || !SCM_NUMBERP(SCM_CAR(value)))
+        return FALSE;
 
-  rgba = scm_num2dbl(SCM_CAR(value), G_STRFUNC);
-  if (green != NULL)
-    *green = MIN(1.0, rgba * scale);
+    rgba = scm_num2dbl(SCM_CAR(value), G_STRFUNC);
+    if (green != NULL)
+        *green = MIN(1.0, rgba * scale);
 
-  value = SCM_CDR(value);
-  if (!SCM_LISTP(value) || SCM_NULLP(value) || !SCM_NUMBERP(SCM_CAR(value)))
-    return FALSE;
+    value = SCM_CDR(value);
+    if (!SCM_LISTP(value) || SCM_NULLP(value) || !SCM_NUMBERP(SCM_CAR(value)))
+        return FALSE;
 
-  rgba = scm_num2dbl(SCM_CAR(value), G_STRFUNC);
-  if (blue != NULL)
-    *blue = MIN(1.0, rgba * scale);
+    rgba = scm_num2dbl(SCM_CAR(value), G_STRFUNC);
+    if (blue != NULL)
+        *blue = MIN(1.0, rgba * scale);
 
-  value = SCM_CDR(value);
-  if (!SCM_LISTP(value) || SCM_NULLP(value) || !SCM_NUMBERP(SCM_CAR(value)))
-    return FALSE;
+    value = SCM_CDR(value);
+    if (!SCM_LISTP(value) || SCM_NULLP(value) || !SCM_NUMBERP(SCM_CAR(value)))
+        return FALSE;
 
-  rgba = scm_num2dbl(SCM_CAR(value), G_STRFUNC);
-  if (alpha != NULL)
-    *alpha = MIN(1.0, rgba * scale);
+    rgba = scm_num2dbl(SCM_CAR(value), G_STRFUNC);
+    if (alpha != NULL)
+        *alpha = MIN(1.0, rgba * scale);
 
-  return TRUE;
+    return TRUE;
 }
 
 
@@ -1303,75 +1318,75 @@
 void
 gnc_option_set_default(GNCOption *option)
 {
-  SCM default_getter;
-  SCM setter;
-  SCM value;
+    SCM default_getter;
+    SCM setter;
+    SCM value;
 
-  if (option == NULL)
-    return;
+    if (option == NULL)
+        return;
 
-  default_getter = gnc_option_default_getter(option);
-  if (default_getter == SCM_UNDEFINED)
-    return;
+    default_getter = gnc_option_default_getter(option);
+    if (default_getter == SCM_UNDEFINED)
+        return;
 
-  value = scm_call_0(default_getter);
+    value = scm_call_0(default_getter);
 
-  setter = gnc_option_setter(option);
-  if (setter == SCM_UNDEFINED)
-    return;
+    setter = gnc_option_setter(option);
+    if (setter == SCM_UNDEFINED)
+        return;
 
-  scm_call_1(setter, value);
+    scm_call_1(setter, value);
 }
 
 
 static gint
 compare_sections(gconstpointer a, gconstpointer b)
 {
-  const GNCOptionSection *sa = a;
-  const GNCOptionSection *sb = b;
+    const GNCOptionSection *sa = a;
+    const GNCOptionSection *sb = b;
 
-  return safe_strcmp(sa->section_name, sb->section_name);
+    return safe_strcmp(sa->section_name, sb->section_name);
 }
 
 static gint
 compare_option_tags(gconstpointer a, gconstpointer b)
 {
-  GNCOption *oa = (GNCOption *) a;
-  GNCOption *ob = (GNCOption *) b;
-  char *tag_a = gnc_option_sort_tag(oa);
-  char *tag_b = gnc_option_sort_tag(ob);
-  gint result;
+    GNCOption *oa = (GNCOption *) a;
+    GNCOption *ob = (GNCOption *) b;
+    char *tag_a = gnc_option_sort_tag(oa);
+    char *tag_b = gnc_option_sort_tag(ob);
+    gint result;
 
-  result = safe_strcmp(tag_a, tag_b);
+    result = safe_strcmp(tag_a, tag_b);
 
-  if (tag_a != NULL)
-    free(tag_a);
+    if (tag_a != NULL)
+        free(tag_a);
 
-  if (tag_b != NULL)
-    free(tag_b);
+    if (tag_b != NULL)
+        free(tag_b);
 
-  return result;
+    return result;
 }
 
 #if 0
 static gint
 compare_option_names(gconstpointer a, gconstpointer b)
 {
-  GNCOption *oa = (GNCOption *) a;
-  GNCOption *ob = (GNCOption *) b;
-  char *name_a = gnc_option_name(oa);
-  char *name_b = gnc_option_name(ob);
-  gint result;
+    GNCOption *oa = (GNCOption *) a;
+    GNCOption *ob = (GNCOption *) b;
+    char *name_a = gnc_option_name(oa);
+    char *name_b = gnc_option_name(ob);
+    gint result;
 
-  result = safe_strcmp(name_a, name_b);
+    result = safe_strcmp(name_a, name_b);
 
-  if (name_a != NULL)
-    free(name_a);
+    if (name_a != NULL)
+        free(name_a);
 
-  if (name_b != NULL)
-    free(name_b);
+    if (name_b != NULL)
+        free(name_b);
 
-  return result;
+    return result;
 }
 #endif
 
@@ -1386,9 +1401,9 @@
 gboolean
 gnc_option_db_dirty(GNCOptionDB *odb)
 {
-  g_return_val_if_fail (odb, FALSE);
+    g_return_val_if_fail (odb, FALSE);
 
-  return odb->options_dirty;
+    return odb->options_dirty;
 }
 
 
@@ -1400,9 +1415,9 @@
 void
 gnc_option_db_clean(GNCOptionDB *odb)
 {
-  g_return_if_fail (odb);
+    g_return_if_fail (odb);
 
-  odb->options_dirty = FALSE;
+    odb->options_dirty = FALSE;
 }
 
 
@@ -1418,51 +1433,51 @@
 void
 gnc_option_db_register_option(GNCOptionDBHandle handle, SCM guile_option)
 {
-  GNCOptionDB *odb;
-  GNCOption *option;
-  GNCOptionSection *section;
+    GNCOptionDB *odb;
+    GNCOption *option;
+    GNCOptionSection *section;
 
-  odb = g_hash_table_lookup(option_dbs, &handle);
+    odb = g_hash_table_lookup(option_dbs, &handle);
 
-  g_return_if_fail (odb != NULL);
+    g_return_if_fail (odb != NULL);
 
-  odb->options_dirty = TRUE;
+    odb->options_dirty = TRUE;
 
-  /* Make the option structure */
-  option = g_new0(GNCOption, 1);
-  option->guile_option = guile_option;
-  option->changed = FALSE;
-  option->widget = NULL;
-  option->odb = odb;
+    /* Make the option structure */
+    option = g_new0(GNCOption, 1);
+    option->guile_option = guile_option;
+    option->changed = FALSE;
+    option->widget = NULL;
+    option->odb = odb;
 
-  /* Prevent guile from garbage collecting the option */
-  scm_gc_protect_object(guile_option);
+    /* Prevent guile from garbage collecting the option */
+    scm_gc_protect_object(guile_option);
 
-  /* Make the section structure */
-  section = g_new0(GNCOptionSection, 1);
-  section->section_name = gnc_option_section(option);
-  section->options = NULL;
+    /* Make the section structure */
+    section = g_new0(GNCOptionSection, 1);
+    section->section_name = gnc_option_section(option);
+    section->options = NULL;
 
-  /* See if the section is already there */
-  {
-    GSList *old;
+    /* See if the section is already there */
+    {
+        GSList *old;
 
-    old = g_slist_find_custom(odb->option_sections, section, compare_sections);
+        old = g_slist_find_custom(odb->option_sections, section, compare_sections);
 
-    if (old != NULL)
-    {
-      if (section->section_name != NULL)
-        free(section->section_name);
-      g_free(section);
-      section = old->data;
+        if (old != NULL)
+        {
+            if (section->section_name != NULL)
+                free(section->section_name);
+            g_free(section);
+            section = old->data;
+        }
+        else
+            odb->option_sections = g_slist_insert_sorted(odb->option_sections,
+                                   section, compare_sections);
     }
-    else
-      odb->option_sections = g_slist_insert_sorted(odb->option_sections,
-                                                   section, compare_sections);
-  }
 
-  section->options = g_slist_insert_sorted(section->options, option,
-                                           compare_option_tags);
+    section->options = g_slist_insert_sorted(section->options, option,
+                       compare_option_tags);
 }
 
 
@@ -1477,7 +1492,7 @@
 guint
 gnc_option_db_num_sections(GNCOptionDB *odb)
 {
-  return g_slist_length(odb->option_sections);
+    return g_slist_length(odb->option_sections);
 }
 
 
@@ -1492,7 +1507,7 @@
 GNCOptionSection *
 gnc_option_db_get_section(GNCOptionDB *odb, gint i)
 {
-  return g_slist_nth_data(odb->option_sections, i);
+    return g_slist_nth_data(odb->option_sections, i);
 }
 
 
@@ -1506,7 +1521,7 @@
 const char *
 gnc_option_section_name(GNCOptionSection *section)
 {
-  return section->section_name;
+    return section->section_name;
 }
 
 
@@ -1520,7 +1535,7 @@
 guint
 gnc_option_section_num_options(GNCOptionSection *section)
 {
-  return g_slist_length(section->options);
+    return g_slist_length(section->options);
 }
 
 
@@ -1535,7 +1550,7 @@
 GNCOption *
 gnc_get_option_section_option(GNCOptionSection *section, int i)
 {
-  return g_slist_nth_data(section->options, i);
+    return g_slist_nth_data(section->options, i);
 }
 
 
@@ -1552,43 +1567,43 @@
 gnc_option_db_get_option_by_name(GNCOptionDB *odb, const char *section_name,
                                  const char *name)
 {
-  GSList *section_node;
-  GSList *option_node;
-  GNCOptionSection section_key;
-  GNCOptionSection *section;
-  GNCOption *option;
-  gint result;
-  char *node_name;
+    GSList *section_node;
+    GSList *option_node;
+    GNCOptionSection section_key;
+    GNCOptionSection *section;
+    GNCOption *option;
+    gint result;
+    char *node_name;
 
-  if (odb == NULL)
-    return NULL;
+    if (odb == NULL)
+        return NULL;
 
-  section_key.section_name = (char *) section_name;
+    section_key.section_name = (char *) section_name;
 
-  section_node = g_slist_find_custom(odb->option_sections, &section_key,
-                                     compare_sections);
+    section_node = g_slist_find_custom(odb->option_sections, &section_key,
+                                       compare_sections);
 
-  if (section_node == NULL)
-    return NULL;
+    if (section_node == NULL)
+        return NULL;
 
-  section = section_node->data;
-  option_node = section->options;
+    section = section_node->data;
+    option_node = section->options;
 
-  while (option_node != NULL)
-  {
-    option = option_node->data;
+    while (option_node != NULL)
+    {
+        option = option_node->data;
 
-    node_name = gnc_option_name(option);
-    result = safe_strcmp(name, node_name);
-    free(node_name);
+        node_name = gnc_option_name(option);
+        result = safe_strcmp(name, node_name);
+        free(node_name);
 
-    if (result == 0)
-      return option;
+        if (result == 0)
+            return option;
 
-    option_node = option_node->next;
-  }
+        option_node = option_node->next;
+    }
 
-  return NULL;
+    return NULL;
 }
 
 
@@ -1603,129 +1618,129 @@
 GNCOption *
 gnc_option_db_get_option_by_SCM(GNCOptionDB *odb, SCM guile_option)
 {
-  GNCOption option_key;
-  GNCOption *option;
-  char *section_name;
-  char *name;
+    GNCOption option_key;
+    GNCOption *option;
+    char *section_name;
+    char *name;
 
-  option_key.guile_option = guile_option;
+    option_key.guile_option = guile_option;
 
-  section_name = gnc_option_section(&option_key);
-  name = gnc_option_name(&option_key);
+    section_name = gnc_option_section(&option_key);
+    name = gnc_option_name(&option_key);
 
-  option = gnc_option_db_get_option_by_name(odb, section_name, name);
+    option = gnc_option_db_get_option_by_name(odb, section_name, name);
 
-  if (section_name != NULL)
-    free(section_name);
+    if (section_name != NULL)
+        free(section_name);
 
-  if (name != NULL)
-    free(name);
+    if (name != NULL)
+        free(name);
 
-  return option;
+    return option;
 }
 
 
 static SCM
 gnc_option_valid_value(GNCOption *option, SCM value)
 {
-  SCM validator;
-  SCM result, ok;
+    SCM validator;
+    SCM result, ok;
 
-  validator = gnc_option_value_validator(option);
+    validator = gnc_option_value_validator(option);
 
-  result = scm_call_1(validator, value);
-  if (!SCM_LISTP(result) || SCM_NULLP(result))
-    return SCM_UNDEFINED;
+    result = scm_call_1(validator, value);
+    if (!SCM_LISTP(result) || SCM_NULLP(result))
+        return SCM_UNDEFINED;
 
-  ok = SCM_CAR(result);
-  if (!SCM_BOOLP(ok))
-    return SCM_UNDEFINED;
+    ok = SCM_CAR(result);
+    if (!SCM_BOOLP(ok))
+        return SCM_UNDEFINED;
 
-  if (!SCM_NFALSEP(ok))
-    return SCM_UNDEFINED;
+    if (!SCM_NFALSEP(ok))
+        return SCM_UNDEFINED;
 
-  result = SCM_CDR(result);
-  if (!SCM_LISTP(result) || SCM_NULLP(result))
-    return SCM_UNDEFINED;
+    result = SCM_CDR(result);
+    if (!SCM_LISTP(result) || SCM_NULLP(result))
+        return SCM_UNDEFINED;
 
-  return SCM_CAR(result);
+    return SCM_CAR(result);
 }
 
 
 static void
 gnc_commit_option(GNCOption *option)
 {
-  SCM validator, setter, value;
-  SCM result, ok;
+    SCM validator, setter, value;
+    SCM result, ok;
 
-  /* Validate the ui's value */
-  value = gnc_option_get_ui_value(option);
-  if (value == SCM_UNDEFINED)
-    return;
+    /* Validate the ui's value */
+    value = gnc_option_get_ui_value(option);
+    if (value == SCM_UNDEFINED)
+        return;
 
-  validator = gnc_option_value_validator(option);
+    validator = gnc_option_value_validator(option);
 
-  result = scm_call_1(validator, value);
-  if (!SCM_LISTP(result) || SCM_NULLP(result))
-  {
-    PERR("bad validation result\n");
-    return;
-  }
+    result = scm_call_1(validator, value);
+    if (!SCM_LISTP(result) || SCM_NULLP(result))
+    {
+        PERR("bad validation result\n");
+        return;
+    }
 
-  /* First element determines validity */
-  ok = SCM_CAR(result);
-  if (!SCM_BOOLP(ok))
-  {
-    PERR("bad validation result\n");
-    return;
-  }
+    /* First element determines validity */
+    ok = SCM_CAR(result);
+    if (!SCM_BOOLP(ok))
+    {
+        PERR("bad validation result\n");
+        return;
+    }
 
-  if (SCM_NFALSEP(ok))
-  {
-    /* Second element is value to use */
-    value = SCM_CADR(result);
-    setter = gnc_option_setter(option);
+    if (SCM_NFALSEP(ok))
+    {
+        /* Second element is value to use */
+        value = SCM_CADR(result);
+        setter = gnc_option_setter(option);
 
-    scm_call_1(setter, value);
+        scm_call_1(setter, value);
 
-    gnc_option_set_ui_value (option, FALSE);
-  }
-  else
-  {
-    SCM oops;
-    char *section, *name;
-    GtkWidget *dialog;
-    const gchar *message;
-    const gchar *format = _("There is a problem with option %s:%s.\n%s");
-
-    /* Second element is error message */
-    oops = SCM_CADR(result);
-    if (!SCM_STRINGP(oops))
+        gnc_option_set_ui_value (option, FALSE);
+    }
+    else
     {
-      PERR("bad validation result\n");
-      return;
-    }
+        SCM oops;
+        char *section, *name;
+        GtkWidget *dialog;
+        const gchar *message;
+        const gchar *format = _("There is a problem with option %s:%s.\n%s");
 
-    message = SCM_STRING_CHARS(oops);
-    name = gnc_option_name(option);
-    section = gnc_option_section(option);
+        /* Second element is error message */
+        oops = SCM_CADR(result);
+        if (!SCM_STRINGP(oops))
+        {
+            PERR("bad validation result\n");
+            return;
+        }
 
-    dialog = gtk_message_dialog_new(NULL,
-				    0,
-				    GTK_MESSAGE_ERROR,
-				    GTK_BUTTONS_OK,
-				    format,
-				    section ? section : "(null)",
-				    name ? name : "(null)",
-				    message ? message : "(null)");
-    gtk_dialog_run(GTK_DIALOG(dialog));
-    gtk_widget_destroy(dialog);
+        message = SCM_STRING_CHARS(oops);
+        name = gnc_option_name(option);
+        section = gnc_option_section(option);
 
-    if (name != NULL)
-      free(name);
-    if (section != NULL)
-      free(section);
-  }
+        dialog = gtk_message_dialog_new(NULL,
+                                        0,
+                                        GTK_MESSAGE_ERROR,
+                                        GTK_BUTTONS_OK,
+                                        format,
+                                        section ? section : "(null)",
+                                        name ? name : "(null)",
+                                        message ? message : "(null)");
+        gtk_dialog_run(GTK_DIALOG(dialog));
+        gtk_widget_destroy(dialog);
+
+        if (name != NULL)
+            free(name);
+        if (section != NULL)
+            free(section);
+    }
 }
 
 
@@ -1740,28 +1755,30 @@
 gboolean
 gnc_option_db_get_changed(GNCOptionDB *odb)
 {
-  GSList *section_node;
-  GSList *option_node;
-  GNCOptionSection *section;
-  GNCOption *option;
+    GSList *section_node;
+    GSList *option_node;
+    GNCOptionSection *section;
+    GNCOption *option;
 
-  g_return_val_if_fail (odb, FALSE);
+    g_return_val_if_fail (odb, FALSE);
 
-  for (section_node = odb->option_sections; section_node;
-       section_node = section_node->next) {
+    for (section_node = odb->option_sections; section_node;
+            section_node = section_node->next)
+    {
 
-    section = section_node->data;
+        section = section_node->data;
 
-    for (option_node = section->options; option_node;
-         option_node = option_node->next) {
+        for (option_node = section->options; option_node;
+                option_node = option_node->next)
+        {
 
-      option = option_node->data;
+            option = option_node->data;
 
-      if (option->changed)
-        return TRUE;
+            if (option->changed)
+                return TRUE;
+        }
     }
-  }
-  return FALSE;
+    return FALSE;
 }
 
 
@@ -1776,39 +1793,39 @@
 void
 gnc_option_db_commit(GNCOptionDB *odb)
 {
-  GSList *section_node;
-  GSList *option_node;
-  GNCOptionSection *section;
-  GNCOption *option;
-  gboolean changed_something = FALSE;
+    GSList *section_node;
+    GSList *option_node;
+    GNCOptionSection *section;
+    GNCOption *option;
+    gboolean changed_something = FALSE;
 
-  g_return_if_fail (odb);
+    g_return_if_fail (odb);
 
-  section_node = odb->option_sections;
-  while (section_node != NULL)
-  {
-    section = section_node->data;
-
-    option_node = section->options;
-    while (option_node != NULL)
+    section_node = odb->option_sections;
+    while (section_node != NULL)
     {
-      option = option_node->data;
+        section = section_node->data;
 
-      if (option->changed)
-      {
-        gnc_commit_option(option_node->data);
-        changed_something = TRUE;
-        option->changed = FALSE;
-      }
+        option_node = section->options;
+        while (option_node != NULL)
+        {
+            option = option_node->data;
 
-      option_node = option_node->next;
+            if (option->changed)
+            {
+                gnc_commit_option(option_node->data);
+                changed_something = TRUE;
+                option->changed = FALSE;
+            }
+
+            option_node = option_node->next;
+        }
+
+        section_node = section_node->next;
     }
 
-    section_node = section_node->next;
-  }
-
-  if (changed_something)
-    gnc_call_option_change_callbacks(odb);
+    if (changed_something)
+        gnc_call_option_change_callbacks(odb);
 }
 
 
@@ -1823,27 +1840,27 @@
 void
 gnc_option_db_section_reset_widgets (GNCOptionSection *section)
 {
-  GSList *option_node;
-  GNCOption *option;
+    GSList *option_node;
+    GNCOption *option;
 
-  g_return_if_fail (section);
+    g_return_if_fail (section);
 
-  /* Don't reset "invisible" options.
-   * If the section name begins "__" we should not reset
-   */
-  if (section->section_name == NULL ||
-      strncmp (section->section_name, "__", 2) == 0)
-    return;
+    /* Don't reset "invisible" options.
+     * If the section name begins "__" we should not reset
+     */
+    if (section->section_name == NULL ||
+            strncmp (section->section_name, "__", 2) == 0)
+        return;
 
-  for (option_node = section->options;
-       option_node != NULL;
-       option_node = option_node->next)
-  {
-    option = option_node->data;
+    for (option_node = section->options;
+            option_node != NULL;
+            option_node = option_node->next)
+    {
+        option = option_node->data;
 
-    gnc_option_set_ui_value (option, TRUE);
-    gnc_option_set_changed (option, TRUE);
-  }
+        gnc_option_set_ui_value (option, TRUE);
+        gnc_option_set_changed (option, TRUE);
+    }
 }
 
 
@@ -1857,18 +1874,18 @@
 void
 gnc_option_db_reset_widgets (GNCOptionDB *odb)
 {
-  GSList *section_node;
-  GNCOptionSection *section;
+    GSList *section_node;
+    GNCOptionSection *section;
 
-  g_return_if_fail (odb);
+    g_return_if_fail (odb);
 
-  for (section_node = odb->option_sections;
-       section_node != NULL;
-       section_node = section_node->next)
-  {
-    section = section_node->data;
-    gnc_option_db_section_reset_widgets (section);
-  }
+    for (section_node = odb->option_sections;
+            section_node != NULL;
+            section_node = section_node->next)
+    {
+        section = section_node->data;
+        gnc_option_db_section_reset_widgets (section);
+    }
 }
 
 
@@ -1883,21 +1900,21 @@
 char *
 gnc_option_db_get_default_section(GNCOptionDB *odb)
 {
-  SCM getter;
-  SCM value;
+    SCM getter;
+    SCM value;
 
-  if (odb == NULL)
-    return NULL;
+    if (odb == NULL)
+        return NULL;
 
-  getter = scm_c_eval_string("gnc:options-get-default-section");
-  if (!SCM_PROCEDUREP(getter))
-    return NULL;
+    getter = scm_c_eval_string("gnc:options-get-default-section");
+    if (!SCM_PROCEDUREP(getter))
+        return NULL;
 
-  value = scm_call_1(getter, odb->guile_options);
-  if (!SCM_STRINGP(value))
-    return NULL;
+    value = scm_call_1(getter, odb->guile_options);
+    if (!SCM_STRINGP(value))
+        return NULL;
 
-  return g_strdup(SCM_STRING_CHARS(value));
+    return g_strdup(SCM_STRING_CHARS(value));
 }
 
 
@@ -1918,19 +1935,19 @@
                             const char *name,
                             SCM default_value)
 {
-  GNCOption *option;
-  SCM getter;
+    GNCOption *option;
+    SCM getter;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
+    option = gnc_option_db_get_option_by_name(odb, section, name);
 
-  if (option == NULL)
-    return default_value;
+    if (option == NULL)
+        return default_value;
 
-  getter = gnc_option_getter(option);
-  if (getter == SCM_UNDEFINED)
-    return default_value;
+    getter = gnc_option_getter(option);
+    if (getter == SCM_UNDEFINED)
+        return default_value;
 
-  return scm_call_0(getter);
+    return scm_call_0(getter);
 }
 
 /********************************************************************\
@@ -1950,25 +1967,25 @@
                                     const char *name,
                                     gboolean default_value)
 {
-  GNCOption *option;
-  SCM getter;
-  SCM value;
+    GNCOption *option;
+    SCM getter;
+    SCM value;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
+    option = gnc_option_db_get_option_by_name(odb, section, name);
 
-  if (option == NULL)
-    return default_value;
+    if (option == NULL)
+        return default_value;
 
-  getter = gnc_option_getter(option);
-  if (getter == SCM_UNDEFINED)
-    return default_value;
+    getter = gnc_option_getter(option);
+    if (getter == SCM_UNDEFINED)
+        return default_value;
 
-  value = scm_call_0(getter);
+    value = scm_call_0(getter);
 
-  if (SCM_BOOLP(value))
-    return SCM_NFALSEP(value);
-  else
-    return default_value;
+    if (SCM_BOOLP(value))
+        return SCM_NFALSEP(value);
+    else
+        return default_value;
 }
 
 
@@ -1990,27 +2007,27 @@
                                    const char *name,
                                    const char *default_value)
 {
-  GNCOption *option;
-  SCM getter;
-  SCM value;
+    GNCOption *option;
+    SCM getter;
+    SCM value;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
+    option = gnc_option_db_get_option_by_name(odb, section, name);
 
-  if (option != NULL)
-  {
-    getter = gnc_option_getter(option);
-    if (getter != SCM_UNDEFINED)
+    if (option != NULL)
     {
-      value = scm_call_0(getter);
-      if (SCM_STRINGP(value))
-        return g_strdup(SCM_STRING_CHARS(value));
+        getter = gnc_option_getter(option);
+        if (getter != SCM_UNDEFINED)
+        {
+            value = scm_call_0(getter);
+            if (SCM_STRINGP(value))
+                return g_strdup(SCM_STRING_CHARS(value));
+        }
     }
-  }
 
-  if (default_value == NULL)
-    return NULL;
+    if (default_value == NULL)
+        return NULL;
 
-  return strdup(default_value);
+    return strdup(default_value);
 }
 
 
@@ -2032,7 +2049,7 @@
                                  const char *name,
                                  const char *default_value)
 {
-  return gnc_option_db_lookup_string_option(odb, section, name, default_value);
+    return gnc_option_db_lookup_string_option(odb, section, name, default_value);
 }
 
 
@@ -2055,27 +2072,27 @@
                                         const char *name,
                                         const char *default_value)
 {
-  GNCOption *option;
-  SCM getter;
-  SCM value;
+    GNCOption *option;
+    SCM getter;
+    SCM value;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
+    option = gnc_option_db_get_option_by_name(odb, section, name);
 
-  if (option != NULL)
-  {
-    getter = gnc_option_getter(option);
-    if (getter != SCM_UNDEFINED)
+    if (option != NULL)
     {
-      value = scm_call_0(getter);
-      if (SCM_SYMBOLP(value))
-        return g_strdup(SCM_SYMBOL_CHARS(value));
+        getter = gnc_option_getter(option);
+        if (getter != SCM_UNDEFINED)
+        {
+            value = scm_call_0(getter);
+            if (SCM_SYMBOLP(value))
+                return g_strdup(SCM_SYMBOL_CHARS(value));
+        }
     }
-  }
 
-  if (default_value == NULL)
-    return NULL;
+    if (default_value == NULL)
+        return NULL;
 
-  return strdup(default_value);
+    return strdup(default_value);
 }
 
 
@@ -2109,79 +2126,79 @@
                                  const char *name,
                                  gboolean *is_relative,
                                  Timespec *set_ab_value,
-                                 char **set_rel_value, 
+                                 char **set_rel_value,
                                  Timespec *default_value)
 {
-  GNCOption *option;
-  Timespec temp = {0,0};
-  char *symbol;
-  SCM getter;
-  SCM value;
+    GNCOption *option;
+    Timespec temp = {0, 0};
+    char *symbol;
+    SCM getter;
+    SCM value;
 
-  initialize_getters();
+    initialize_getters();
 
-  if (set_ab_value == NULL)
-  {
-    set_ab_value = &temp;
-  }
+    if (set_ab_value == NULL)
+    {
+        set_ab_value = &temp;
+    }
 
-  if(set_rel_value != NULL)
-  {
-    *set_rel_value = NULL;
-  }
- 
-  if (is_relative != NULL)
-  {
-    *is_relative = FALSE;
-  }
-  
-  option = gnc_option_db_get_option_by_name(odb, section, name);
+    if (set_rel_value != NULL)
+    {
+        *set_rel_value = NULL;
+    }
 
-  if (option != NULL)
-  {
-    getter = gnc_option_getter(option);
-    if (getter != SCM_UNDEFINED)
+    if (is_relative != NULL)
     {
-      value = scm_call_0(getter);
+        *is_relative = FALSE;
+    }
 
-      if (SCM_CONSP(value))
-      {
-        Timespec absolute;
+    option = gnc_option_db_get_option_by_name(odb, section, name);
 
-        absolute = gnc_date_option_value_get_absolute (value);
+    if (option != NULL)
+    {
+        getter = gnc_option_getter(option);
+        if (getter != SCM_UNDEFINED)
+        {
+            value = scm_call_0(getter);
 
-        *set_ab_value = absolute;
+            if (SCM_CONSP(value))
+            {
+                Timespec absolute;
 
-        symbol = gnc_date_option_value_get_type (value);
+                absolute = gnc_date_option_value_get_absolute (value);
 
-        if (safe_strcmp(symbol, "relative") == 0)
-        {
-          SCM relative = gnc_date_option_value_get_relative (value);
+                *set_ab_value = absolute;
 
-          if (is_relative != NULL)
-            *is_relative = TRUE;
+                symbol = gnc_date_option_value_get_type (value);
 
-          if (set_rel_value != NULL)
-            *set_rel_value = g_strdup(SCM_SYMBOL_CHARS (relative));
+                if (safe_strcmp(symbol, "relative") == 0)
+                {
+                    SCM relative = gnc_date_option_value_get_relative (value);
+
+                    if (is_relative != NULL)
+                        *is_relative = TRUE;
+
+                    if (set_rel_value != NULL)
+                        *set_rel_value = g_strdup(SCM_SYMBOL_CHARS (relative));
+                }
+
+                if (symbol)
+                    free (symbol);
+            }
         }
-
-        if (symbol)
-          free (symbol);
-      }
     }
-  }
-  else
-  {
-    if (default_value == NULL)
+    else
     {
-      set_ab_value->tv_sec = time (NULL);
-      set_ab_value->tv_nsec = 0;
+        if (default_value == NULL)
+        {
+            set_ab_value->tv_sec = time (NULL);
+            set_ab_value->tv_nsec = 0;
+        }
+        else
+            *set_ab_value = *default_value;
     }
-    else
-      *set_ab_value = *default_value;
-  }
 
-  return set_ab_value->tv_sec;
+    return set_ab_value->tv_sec;
 }
 
 
@@ -2202,24 +2219,24 @@
                                    const char *name,
                                    gdouble default_value)
 {
-  GNCOption *option;
-  SCM getter;
-  SCM value;
+    GNCOption *option;
+    SCM getter;
+    SCM value;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
+    option = gnc_option_db_get_option_by_name(odb, section, name);
 
-  if (option != NULL)
-  {
-    getter = gnc_option_getter(option);
-    if (getter != SCM_UNDEFINED)
+    if (option != NULL)
     {
-      value = scm_call_0(getter);
-      if (SCM_NUMBERP(value))
-        return scm_num2dbl(value, G_STRFUNC);
+        getter = gnc_option_getter(option);
+        if (getter != SCM_UNDEFINED)
+        {
+            value = scm_call_0(getter);
+            if (SCM_NUMBERP(value))
+                return scm_num2dbl(value, G_STRFUNC);
+        }
     }
-  }
 
-  return default_value;
+    return default_value;
 }
 
 
@@ -2238,18 +2255,18 @@
  * Return: true if option was found                                 *
 \********************************************************************/
 gboolean gnc_option_db_lookup_color_option(GNCOptionDB *odb,
-                                           const char *section,
-                                           const char *name,
-                                           gdouble *red,
-                                           gdouble *green,
-                                           gdouble *blue,
-                                           gdouble *alpha)
+        const char *section,
+        const char *name,
+        gdouble *red,
+        gdouble *green,
+        gdouble *blue,
+        gdouble *alpha)
 {
-  GNCOption *option;
+    GNCOption *option;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
+    option = gnc_option_db_get_option_by_name(odb, section, name);
 
-  return gnc_option_get_color_info(option, FALSE, red, green, blue, alpha);
+    return gnc_option_get_color_info(option, FALSE, red, green, blue, alpha);
 }
 
 
@@ -2265,17 +2282,17 @@
  * Return: argb value                                               *
 \********************************************************************/
 guint32 gnc_option_db_lookup_color_option_argb(GNCOptionDB *odb,
-                                               const char *section,
-                                               const char *name,
-                                               guint32 default_value)
+        const char *section,
+        const char *name,
+        guint32 default_value)
 {
-  GNCOption *option;
+    GNCOption *option;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
-  if (option == NULL)
-    return default_value;
+    option = gnc_option_db_get_option_by_name(odb, section, name);
+    if (option == NULL)
+        return default_value;
 
-  return gnc_option_get_color_argb(option);
+    return gnc_option_get_color_argb(option);
 }
 
 
@@ -2296,44 +2313,44 @@
                                  const char *name,
                                  GSList *default_value)
 {
-  GNCOption *option;
-  GSList *list = NULL;
-  SCM getter;
-  SCM value;
-  SCM item;
+    GNCOption *option;
+    GSList *list = NULL;
+    SCM getter;
+    SCM value;
+    SCM item;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
-  if (option == NULL)
-    return default_value;
+    option = gnc_option_db_get_option_by_name(odb, section, name);
+    if (option == NULL)
+        return default_value;
 
-  getter = gnc_option_getter(option);
-  if (getter == SCM_UNDEFINED)
-    return default_value;
+    getter = gnc_option_getter(option);
+    if (getter == SCM_UNDEFINED)
+        return default_value;
 
-  value = scm_call_0(getter);
-  while (SCM_LISTP(value) && !SCM_NULLP(value))
-  {
-    item = SCM_CAR(value);
-    value = SCM_CDR(value);
-
-    if (!SCM_SYMBOLP(item))
+    value = scm_call_0(getter);
+    while (SCM_LISTP(value) && !SCM_NULLP(value))
     {
-      gnc_free_list_option_value(list);
+        item = SCM_CAR(value);
+        value = SCM_CDR(value);
 
-      return default_value;
+        if (!SCM_SYMBOLP(item))
+        {
+            gnc_free_list_option_value(list);
+
+            return default_value;
+        }
+
+        list = g_slist_prepend(list, g_strdup(SCM_SYMBOL_CHARS(item)));
     }
 
-    list = g_slist_prepend(list, g_strdup(SCM_SYMBOL_CHARS(item)));
-  }
+    if (!SCM_LISTP(value) || !SCM_NULLP(value))
+    {
+        gnc_free_list_option_value(list);
 
-  if (!SCM_LISTP(value) || !SCM_NULLP(value))
-  {
-    gnc_free_list_option_value(list);
+        return default_value;
+    }
 
-    return default_value;
-  }
-
-  return list;
+    return list;
 }
 
 
@@ -2354,34 +2371,34 @@
                                      const char *name,
                                      gnc_commodity *default_value)
 {
-  GNCOption *option;
-  SCM getter;
-  SCM value;
+    GNCOption *option;
+    SCM getter;
+    SCM value;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
-  if (option == NULL)
-    return default_value;
+    option = gnc_option_db_get_option_by_name(odb, section, name);
+    if (option == NULL)
+        return default_value;
 
-  getter = gnc_option_getter(option);
-  if (getter == SCM_UNDEFINED)
-    return default_value;
+    getter = gnc_option_getter(option);
+    if (getter == SCM_UNDEFINED)
+        return default_value;
 
-  value = scm_call_0(getter);
+    value = scm_call_0(getter);
 
-  return gnc_scm_to_commodity (value);
+    return gnc_scm_to_commodity (value);
 }
 
 static void
 free_helper(gpointer string, gpointer not_used)
 {
-  if (string) free(string);
+    if (string) free(string);
 }
 
 void
 gnc_free_list_option_value(GSList *list)
 {
-  g_slist_foreach(list, free_helper, NULL);
-  g_slist_free(list);
+    g_slist_foreach(list, free_helper, NULL);
+    g_slist_free(list);
 }
 
 
@@ -2399,11 +2416,11 @@
                                  const char *section,
                                  const char *name)
 {
-  GNCOption *option;
+    GNCOption *option;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
+    option = gnc_option_db_get_option_by_name(odb, section, name);
 
-  gnc_option_set_default(option);
+    gnc_option_set_default(option);
 }
 
 
@@ -2424,24 +2441,24 @@
                          const char *name,
                          SCM value)
 {
-  GNCOption *option;
-  SCM setter;
+    GNCOption *option;
+    SCM setter;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
-  if (option == NULL)
-    return FALSE;
+    option = gnc_option_db_get_option_by_name(odb, section, name);
+    if (option == NULL)
+        return FALSE;
 
-  value = gnc_option_valid_value(option, value);
-  if (value == SCM_UNDEFINED)
-    return FALSE;
+    value = gnc_option_valid_value(option, value);
+    if (value == SCM_UNDEFINED)
+        return FALSE;
 
-  setter = gnc_option_setter(option);
-  if (setter == SCM_UNDEFINED)
-    return FALSE;
+    setter = gnc_option_setter(option);
+    if (setter == SCM_UNDEFINED)
+        return FALSE;
 
-  scm_call_1(setter, value);
+    scm_call_1(setter, value);
 
-  return TRUE;
+    return TRUE;
 }
 
 
@@ -2462,27 +2479,27 @@
                                 const char *name,
                                 gdouble value)
 {
-  GNCOption *option;
-  SCM scm_value;
-  SCM setter;
+    GNCOption *option;
+    SCM scm_value;
+    SCM setter;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
-  if (option == NULL)
-    return FALSE;
+    option = gnc_option_db_get_option_by_name(odb, section, name);
+    if (option == NULL)
+        return FALSE;
 
-  scm_value = scm_make_real(value);
+    scm_value = scm_make_real(value);
 
-  scm_value = gnc_option_valid_value(option, scm_value);
-  if (scm_value == SCM_UNDEFINED)
-    return FALSE;
+    scm_value = gnc_option_valid_value(option, scm_value);
+    if (scm_value == SCM_UNDEFINED)
+        return FALSE;
 
-  setter = gnc_option_setter(option);
-  if (setter == SCM_UNDEFINED)
-    return FALSE;
+    setter = gnc_option_setter(option);
+    if (setter == SCM_UNDEFINED)
+        return FALSE;
 
-  scm_call_1(setter, scm_value);
+    scm_call_1(setter, scm_value);
 
-  return TRUE;
+    return TRUE;
 }
 
 /********************************************************************\
@@ -2502,27 +2519,27 @@
                                  const char *name,
                                  gboolean value)
 {
-  GNCOption *option;
-  SCM scm_value;
-  SCM setter;
+    GNCOption *option;
+    SCM scm_value;
+    SCM setter;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
-  if (option == NULL)
-    return FALSE;
+    option = gnc_option_db_get_option_by_name(odb, section, name);
+    if (option == NULL)
+        return FALSE;
 
-  scm_value = SCM_BOOL(value);
+    scm_value = SCM_BOOL(value);
 
-  scm_value = gnc_option_valid_value(option, scm_value);
-  if (scm_value == SCM_UNDEFINED)
-    return FALSE;
+    scm_value = gnc_option_valid_value(option, scm_value);
+    if (scm_value == SCM_UNDEFINED)
+        return FALSE;
 
-  setter = gnc_option_setter(option);
-  if (setter == SCM_UNDEFINED)
-    return FALSE;
+    setter = gnc_option_setter(option);
+    if (setter == SCM_UNDEFINED)
+        return FALSE;
 
-  scm_call_1(setter, scm_value);
+    scm_call_1(setter, scm_value);
 
-  return TRUE;
+    return TRUE;
 }
 
 /********************************************************************\
@@ -2542,30 +2559,30 @@
                                 const char *name,
                                 const char *value)
 {
-  GNCOption *option;
-  SCM scm_value;
-  SCM setter;
+    GNCOption *option;
+    SCM scm_value;
+    SCM setter;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
-  if (option == NULL)
-    return FALSE;
+    option = gnc_option_db_get_option_by_name(odb, section, name);
+    if (option == NULL)
+        return FALSE;
 
-  if (value)
-    scm_value = scm_mem2string(value, strlen(value));
-  else
-    scm_value = SCM_BOOL_F;
+    if (value)
+        scm_value = scm_mem2string(value, strlen(value));
+    else
+        scm_value = SCM_BOOL_F;
 
-  scm_value = gnc_option_valid_value(option, scm_value);
-  if (scm_value == SCM_UNDEFINED)
-    return FALSE;
+    scm_value = gnc_option_valid_value(option, scm_value);
+    if (scm_value == SCM_UNDEFINED)
+        return FALSE;
 
-  setter = gnc_option_setter(option);
-  if (setter == SCM_UNDEFINED)
-    return FALSE;
+    setter = gnc_option_setter(option);
+    if (setter == SCM_UNDEFINED)
+        return FALSE;
 
-  scm_call_1(setter, scm_value);
+    scm_call_1(setter, scm_value);
 
-  return TRUE;
+    return TRUE;
 }
 
 /*******************************************************************\
@@ -2578,16 +2595,16 @@
 char *
 gnc_option_date_option_get_subtype(GNCOption *option)
 {
-  SCM value;
+    SCM value;
 
-  initialize_getters();
+    initialize_getters();
 
-  value = scm_call_1(getters.date_option_subtype, option->guile_option);
+    value = scm_call_1(getters.date_option_subtype, option->guile_option);
 
-  if (SCM_SYMBOLP(value))
-    return g_strdup(SCM_SYMBOL_CHARS(value));
-  else
-    return NULL;
+    if (SCM_SYMBOLP(value))
+        return g_strdup(SCM_SYMBOL_CHARS(value));
+    else
+        return NULL;
 }
 
 /*******************************************************************\
@@ -2600,15 +2617,15 @@
 char *
 gnc_date_option_value_get_type (SCM option_value)
 {
-  SCM value;
+    SCM value;
 
-  initialize_getters();
+    initialize_getters();
 
-  value = scm_call_1 (getters.date_option_value_type, option_value);
-  if (!SCM_SYMBOLP (value))
-    return NULL;
+    value = scm_call_1 (getters.date_option_value_type, option_value);
+    if (!SCM_SYMBOLP (value))
+        return NULL;
 
-  return g_strdup(SCM_SYMBOL_CHARS (value));
+    return g_strdup(SCM_SYMBOL_CHARS (value));
 }
 
 /*******************************************************************\
@@ -2621,13 +2638,13 @@
 Timespec
 gnc_date_option_value_get_absolute (SCM option_value)
 {
-  SCM value;
+    SCM value;
 
-  initialize_getters();
+    initialize_getters();
 
-  value = scm_call_1 (getters.date_option_value_absolute, option_value);
+    value = scm_call_1 (getters.date_option_value_absolute, option_value);
 
-  return gnc_timepair2timespec (value);
+    return gnc_timepair2timespec (value);
 }
 
 /*******************************************************************\
@@ -2640,9 +2657,9 @@
 SCM
 gnc_date_option_value_get_relative (SCM option_value)
 {
-  initialize_getters();
+    initialize_getters();
 
-  return scm_call_1 (getters.date_option_value_relative, option_value);
+    return scm_call_1 (getters.date_option_value_relative, option_value);
 }
 
 /*******************************************************************\
@@ -2657,22 +2674,22 @@
 \*******************************************************************/
 void
 gnc_option_db_set_option_selectable_by_name(SCM guile_option,
-                                            const char *section, 
-                                            const char *name,
-                                            gboolean selectable)
+        const char *section,
+        const char *name,
+        gboolean selectable)
 {
-  GNCOptionDB *odb;
-  GNCOption *option;
+    GNCOptionDB *odb;
+    GNCOption *option;
 
-  odb = gnc_option_db_find (guile_option);
-  if (!odb)
-    return;
+    odb = gnc_option_db_find (guile_option);
+    if (!odb)
+        return;
 
-  option = gnc_option_db_get_option_by_name(odb, section, name);
-  if (!option)
-    return;
+    option = gnc_option_db_get_option_by_name(odb, section, name);
+    if (!option)
+        return;
 
-  gnc_option_set_selectable (option, selectable);
+    gnc_option_set_selectable (option, selectable);
 }
 
 /* the value is a list of:
@@ -2680,106 +2697,112 @@
  */
 
 gboolean gnc_dateformat_option_value_parse(SCM value, QofDateFormat *format,
-                                           GNCDateMonthFormat *months,
-                                           gboolean *years, char **custom)
+        GNCDateMonthFormat *months,
+        gboolean *years, char **custom)
 {
-  SCM val;
-  const char *str;
+    SCM val;
+    const char *str;
 
-  if (!SCM_LISTP(value) || SCM_NULLP(value))
-    return TRUE;
+    if (!SCM_LISTP(value) || SCM_NULLP(value))
+        return TRUE;
 
-  do {
+    do
+    {
 
-    /* Parse the format */
-    val = SCM_CAR(value);
-    value = SCM_CDR(value);
-    if (!SCM_SYMBOLP(val))
-      break;
-    str = SCM_SYMBOL_CHARS (val);
-    if (!str)
-      break;
+        /* Parse the format */
+        val = SCM_CAR(value);
+        value = SCM_CDR(value);
+        if (!SCM_SYMBOLP(val))
+            break;
+        str = SCM_SYMBOL_CHARS (val);
+        if (!str)
+            break;
 
-    if (format) {
-      if (gnc_date_string_to_dateformat(str, format)) {
-        break;
-      }
-    }
+        if (format)
+        {
+            if (gnc_date_string_to_dateformat(str, format))
+            {
+                break;
+            }
+        }
 
-    /* parse the months */
-    val = SCM_CAR(value);
-    value = SCM_CDR(value);
-    if (!SCM_SYMBOLP(val))
-      break;
-    str = SCM_SYMBOL_CHARS (val);
-    if (!str)
-      break;
+        /* parse the months */
+        val = SCM_CAR(value);
+        value = SCM_CDR(value);
+        if (!SCM_SYMBOLP(val))
+            break;
+        str = SCM_SYMBOL_CHARS (val);
+        if (!str)
+            break;
 
-    if (months) {
-      if (gnc_date_string_to_monthformat(str, months)) {
-        break;
-      }
-    }
+        if (months)
+        {
+            if (gnc_date_string_to_monthformat(str, months))
+            {
+                break;
+            }
+        }
 
-    /* parse the years */
-    val = SCM_CAR(value);
-    value = SCM_CDR(value);
-    if (!SCM_BOOLP(val))
-      break;
+        /* parse the years */
+        val = SCM_CAR(value);
+        value = SCM_CDR(value);
+        if (!SCM_BOOLP(val))
+            break;
 
-    if (years)
-      *years = SCM_NFALSEP(val);
+        if (years)
+            *years = SCM_NFALSEP(val);
 
-    /* parse the custom */
-    val = SCM_CAR(value);
-    value = SCM_CDR(value);
-    if (!SCM_STRINGP(val))
-      break;
-    if (!SCM_NULLP(value))
-      break;
+        /* parse the custom */
+        val = SCM_CAR(value);
+        value = SCM_CDR(value);
+        if (!SCM_STRINGP(val))
+            break;
+        if (!SCM_NULLP(value))
+            break;
 
-    if (custom)
-      *custom = g_strdup(SCM_STRING_CHARS(val));
+        if (custom)
+            *custom = g_strdup(SCM_STRING_CHARS(val));
 
-    return FALSE;
+        return FALSE;
 
-  } while (FALSE);
+    }
+    while (FALSE);
 
-  return TRUE;
+    return TRUE;
 }
 
 SCM gnc_dateformat_option_set_value(QofDateFormat format, GNCDateMonthFormat months,
                                     gboolean years, const char *custom)
 {
-  SCM value = SCM_EOL;
-  SCM val;
-  const char *str;
+    SCM value = SCM_EOL;
+    SCM val;
+    const char *str;
 
-  /* build the list in reverse order */
-  if (custom)
-    val = scm_mem2string(custom, strlen(custom));
-  else
-    val = SCM_BOOL_F;
-  value = scm_cons(val, value);
+    /* build the list in reverse order */
+    if (custom)
+        val = scm_mem2string(custom, strlen(custom));
+    else
+        val = SCM_BOOL_F;
+    value = scm_cons(val, value);
 
-  val = SCM_BOOL(years);
-  value = scm_cons(val, value);
+    val = SCM_BOOL(years);
+    value = scm_cons(val, value);
 
-  str = gnc_date_monthformat_to_string(months);
-  if (str)
-    val = scm_str2symbol(str);
-  else
-    val = SCM_BOOL_F;
-  value = scm_cons(val, value);
+    str = gnc_date_monthformat_to_string(months);
+    if (str)
+        val = scm_str2symbol(str);
+    else
+        val = SCM_BOOL_F;
+    value = scm_cons(val, value);
 
-  str = gnc_date_dateformat_to_string(format);
-  if (str)
-    val = scm_str2symbol(str);
-  else
-    val = SCM_BOOL_F;
-  value = scm_cons(val, value);
+    str = gnc_date_dateformat_to_string(format);
+    if (str)
+        val = scm_str2symbol(str);
+    else
+        val = SCM_BOOL_F;
+    value = scm_cons(val, value);
 
-  return value;
+    return value;
 }
 
 /* For now, this is global, just like when it was in guile.
@@ -2823,7 +2846,8 @@
     gnc_new_options = scm_c_eval_string("gnc:new-options");
     options = scm_call_0(gnc_new_options);
 
-    for (p = list; p; p = p->next) {
+    for (p = list; p; p = p->next)
+    {
         SCM generator = p->data;
         scm_call_1(generator, options);
     }

Modified: gnucash/trunk/src/app-utils/option-util.h
===================================================================
--- gnucash/trunk/src/app-utils/option-util.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/option-util.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -79,13 +79,13 @@
                                      GNCOptionSetSelectable set_selectable);
 
 SCM gnc_option_db_register_change_callback(GNCOptionDB *odb,
-                                           GNCOptionChangeCallback callback,
-                                           gpointer data,
-                                           const char *section,
-                                           const char *name);
+        GNCOptionChangeCallback callback,
+        gpointer data,
+        const char *section,
+        const char *name);
 
 void gnc_option_db_unregister_change_callback_id(GNCOptionDB *odb,
-                                                 SCM callback_id);
+        SCM callback_id);
 
 char * gnc_option_section(GNCOption *option);
 char * gnc_option_name(GNCOption *option);
@@ -140,11 +140,11 @@
 GNCOption * gnc_get_option_section_option(GNCOptionSection *section, int i);
 
 GNCOption * gnc_option_db_get_option_by_name(GNCOptionDB *odb,
-                                             const char *section_name,
-                                             const char *name);
+        const char *section_name,
+        const char *name);
 
 GNCOption * gnc_option_db_get_option_by_SCM(GNCOptionDB *odb,
-                                            SCM guile_option);
+        SCM guile_option);
 
 gboolean gnc_option_db_dirty(GNCOptionDB *odb);
 void     gnc_option_db_clean(GNCOptionDB *odb);
@@ -160,14 +160,14 @@
                                 SCM default_value);
 
 gboolean gnc_option_db_lookup_boolean_option(GNCOptionDB *odb,
-                                             const char *section,
-                                             const char *name,
-                                             gboolean default_value);
+        const char *section,
+        const char *name,
+        gboolean default_value);
 
 char * gnc_option_db_lookup_string_option(GNCOptionDB *odb,
-                                          const char *section,
-                                          const char *name,
-                                          const char *default_value);
+        const char *section,
+        const char *name,
+        const char *default_value);
 
 char * gnc_option_db_lookup_font_option(GNCOptionDB *odb,
                                         const char *section,
@@ -175,40 +175,40 @@
                                         const char *default_value);
 
 char * gnc_option_db_lookup_multichoice_option(GNCOptionDB *odb,
-                                               const char *section,
-                                               const char *name,
-                                               const char *default_value);
+        const char *section,
+        const char *name,
+        const char *default_value);
 
 time_t gnc_option_db_lookup_date_option(GNCOptionDB *odb,
-					const char *section,
-					const char *name,
-					gboolean *is_relative,
-					Timespec *set_ab_value,
-					char **set_rel_value, 
-					Timespec *default_value);
+                                        const char *section,
+                                        const char *name,
+                                        gboolean *is_relative,
+                                        Timespec *set_ab_value,
+                                        char **set_rel_value,
+                                        Timespec *default_value);
 
 gdouble gnc_option_db_lookup_number_option(GNCOptionDB *odb,
-                                           const char *section,
-                                           const char *name,
-                                           gdouble default_value);
+        const char *section,
+        const char *name,
+        gdouble default_value);
 
 gboolean gnc_option_db_lookup_color_option(GNCOptionDB *odb,
-                                           const char *section,
-                                           const char *name,
-                                           gdouble *red,
-                                           gdouble *green,
-                                           gdouble *blue,
-                                           gdouble *alpha);
+        const char *section,
+        const char *name,
+        gdouble *red,
+        gdouble *green,
+        gdouble *blue,
+        gdouble *alpha);
 
 guint32 gnc_option_db_lookup_color_option_argb(GNCOptionDB *odb,
-                                               const char *section,
-                                               const char *name,
-                                               guint32 default_value);
+        const char *section,
+        const char *name,
+        guint32 default_value);
 
 GSList * gnc_option_db_lookup_list_option(GNCOptionDB *odb,
-                                          const char *section,
-                                          const char *name,
-                                          GSList *default_value);
+        const char *section,
+        const char *name,
+        GSList *default_value);
 
 void gnc_free_list_option_value(GSList *list);
 
@@ -228,19 +228,19 @@
                                   SCM value);
 
 gboolean gnc_option_db_set_number_option(GNCOptionDB *odb,
-                                         const char *section,
-                                         const char *name,
-                                         gdouble value);
+        const char *section,
+        const char *name,
+        gdouble value);
 
 gboolean gnc_option_db_set_boolean_option(GNCOptionDB *odb,
-                                          const char *section,
-                                          const char *name,
-                                          gboolean value);
+        const char *section,
+        const char *name,
+        gboolean value);
 
 gboolean gnc_option_db_set_string_option(GNCOptionDB *odb,
-                                          const char *section,
-                                          const char *name,
-                                          const char *value);
+        const char *section,
+        const char *name,
+        const char *value);
 
 char * gnc_option_date_option_get_subtype(GNCOption *option);
 
@@ -249,15 +249,15 @@
 SCM gnc_date_option_value_get_relative (SCM option_value);
 
 void gnc_option_db_set_option_selectable_by_name(SCM guile_options,
-                                                 const char *section, 
-                                                 const char *name,
-                                                 gboolean selectable);
+        const char *section,
+        const char *name,
+        gboolean selectable);
 
 gboolean gnc_dateformat_option_value_parse(SCM value, QofDateFormat *format,
-					   GNCDateMonthFormat *months,
-					   gboolean *years, char **custom);
+        GNCDateMonthFormat *months,
+        gboolean *years, char **custom);
 SCM gnc_dateformat_option_set_value(QofDateFormat format, GNCDateMonthFormat months,
-				    gboolean years, const char *custom);
+                                    gboolean years, const char *custom);
 
 
 void gnc_option_db_register_option(GNCOptionDBHandle handle,

Modified: gnucash/trunk/src/app-utils/test/test-exp-parser.c
===================================================================
--- gnucash/trunk/src/app-utils/test/test-exp-parser.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/test/test-exp-parser.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -13,13 +13,13 @@
 
 typedef struct
 {
-  const char * test_name;
-  const char * exp;
-  gboolean should_succeed;
-  gnc_numeric expected_result;
-  int expected_error_offset;
-  const char * file;
-  int line;
+    const char * test_name;
+    const char * exp;
+    gboolean should_succeed;
+    gnc_numeric expected_result;
+    int expected_error_offset;
+    const char * file;
+    int line;
 } TestNode;
 
 #define add_pass_test(n, e, r) _add_pass_test((n), (e), (r), __FILE__, __LINE__)
@@ -27,16 +27,16 @@
 static void
 _add_pass_test (const char *test_name, const char *exp, gnc_numeric result, char *file, int line)
 {
-  TestNode *node = g_new0 (TestNode, 1);
+    TestNode *node = g_new0 (TestNode, 1);
 
-  node->test_name = test_name;
-  node->exp = exp ? exp : test_name;
-  node->should_succeed = TRUE;
-  node->expected_result = result;
-  node->file = file;
-  node->line = line;
+    node->test_name = test_name;
+    node->exp = exp ? exp : test_name;
+    node->should_succeed = TRUE;
+    node->expected_result = result;
+    node->file = file;
+    node->line = line;
 
-  tests = g_list_append (tests, node);
+    tests = g_list_append (tests, node);
 }
 
 
@@ -45,193 +45,194 @@
 static void
 _add_fail_test (const char *test_name, const char *exp, int expected_error_offset, char *file, int line)
 {
-  TestNode *node = g_new0 (TestNode, 1);
+    TestNode *node = g_new0 (TestNode, 1);
 
-  node->test_name = test_name;
-  node->exp = exp ? exp : test_name;
-  node->should_succeed = FALSE;
-  node->expected_error_offset = expected_error_offset;
-  node->file = file;
-  node->line = line;
+    node->test_name = test_name;
+    node->exp = exp ? exp : test_name;
+    node->should_succeed = FALSE;
+    node->expected_error_offset = expected_error_offset;
+    node->file = file;
+    node->line = line;
 
-  tests = g_list_append (tests, node);
+    tests = g_list_append (tests, node);
 }
 
 static void
 run_parser_test (TestNode *node)
 {
-  gboolean succeeded;
-  gnc_numeric result;
-  char *error_loc;
+    gboolean succeeded;
+    gnc_numeric result;
+    char *error_loc;
 
-  result = gnc_numeric_error( -1 );
-  printf("Running test \"%s\" [%s] = ", node->test_name, node->exp);
-  succeeded = gnc_exp_parser_parse (node->exp, &result, &error_loc);
-  {
-    int pass;
-    pass = (succeeded == node->should_succeed);
-    if ( pass && node->should_succeed ) {
-      pass &= gnc_numeric_equal( result, node->expected_result );
+    result = gnc_numeric_error( -1 );
+    printf("Running test \"%s\" [%s] = ", node->test_name, node->exp);
+    succeeded = gnc_exp_parser_parse (node->exp, &result, &error_loc);
+    {
+        int pass;
+        pass = (succeeded == node->should_succeed);
+        if ( pass && node->should_succeed )
+        {
+            pass &= gnc_numeric_equal( result, node->expected_result );
+        }
+        printf( "%0.4f [%s]\n",
+                gnc_numeric_to_double( result ),
+                (pass ? "PASS" : "FAIL" ) );
     }
-    printf( "%0.4f [%s]\n",
-            gnc_numeric_to_double( result ),
-            (pass ? "PASS" : "FAIL" ) );
-  }
 
-  if (succeeded != node->should_succeed)
-  {
-    failure_args (node->test_name, node->file, node->line,
-                  "parser %s on \"%s\"", 
-                  succeeded ? "succeeded" : "failed",
-                  node->exp);
-    return;
-  }
+    if (succeeded != node->should_succeed)
+    {
+        failure_args (node->test_name, node->file, node->line,
+                      "parser %s on \"%s\"",
+                      succeeded ? "succeeded" : "failed",
+                      node->exp);
+        return;
+    }
 
-  if (succeeded)
-  {
-    if (!gnc_numeric_equal (result, node->expected_result))
+    if (succeeded)
     {
-      failure_args (node->test_name, node->file, node->line, "wrong result");
-      return;
+        if (!gnc_numeric_equal (result, node->expected_result))
+        {
+            failure_args (node->test_name, node->file, node->line, "wrong result");
+            return;
+        }
     }
-  }
-  else if (node->expected_error_offset != -1)
-  {
-    if (error_loc != node->exp + node->expected_error_offset)
+    else if (node->expected_error_offset != -1)
     {
-      failure_args (node->test_name, node->file, node->line, "wrong offset; expected %d, got %d",
-                    node->expected_error_offset, (error_loc - node->exp));
-      return;
+        if (error_loc != node->exp + node->expected_error_offset)
+        {
+            failure_args (node->test_name, node->file, node->line, "wrong offset; expected %d, got %d",
+                          node->expected_error_offset, (error_loc - node->exp));
+            return;
+        }
     }
-  }
 
-  success (node->test_name);
+    success (node->test_name);
 }
 
 static void
 run_parser_tests (void)
 {
-  GList *node;
+    GList *node;
 
-  for (node = tests; node; node = node->next)
-    run_parser_test (node->data);
+    for (node = tests; node; node = node->next)
+        run_parser_test (node->data);
 }
 
 static void
 test_parser (void)
 {
-  gnc_exp_parser_init ();
-  success ("initialize expression parser");
+    gnc_exp_parser_init ();
+    success ("initialize expression parser");
 
-  add_fail_test ("null expression", NULL, -1);
-  add_fail_test ("empty expression", "", 0);
-  add_fail_test ("whitespace", "  \t\n", 4);
-  add_fail_test ("bad expression", "\\", 0);
-  add_fail_test ("bad expression", "1 +", 3);
-  /* Bug#334811 - http://bugzilla.gnome.org/show_bug.cgi?id=334811 */
-  add_fail_test ("bad expression", "1 2", 3);
-  /* Bug#308554 - http://bugzilla.gnome.org/show_bug.cgi?id=308554 */
-  add_fail_test ("bad expression", "1 ç", 2);
-  add_fail_test ("bad expression", "ç 1", 0);
-  add_fail_test ("bad expression", "1 asdf", 6);
-  add_fail_test ("bad expression", "asdf 1", 6);
-  add_fail_test ("bad expression", "asdf jkl", 8);
-  add_fail_test ("bad expression", "  (5 + 23)/   ", 14);
-  add_fail_test ("bad expression", "  ((((5 + 23)/   ", 17);
-  add_fail_test ("divide by zero", "  4 / (1 - 1)", -1);
+    add_fail_test ("null expression", NULL, -1);
+    add_fail_test ("empty expression", "", 0);
+    add_fail_test ("whitespace", "  \t\n", 4);
+    add_fail_test ("bad expression", "\\", 0);
+    add_fail_test ("bad expression", "1 +", 3);
+    /* Bug#334811 - http://bugzilla.gnome.org/show_bug.cgi?id=334811 */
+    add_fail_test ("bad expression", "1 2", 3);
+    /* Bug#308554 - http://bugzilla.gnome.org/show_bug.cgi?id=308554 */
+    add_fail_test ("bad expression", "1 ç", 2);
+    add_fail_test ("bad expression", "ç 1", 0);
+    add_fail_test ("bad expression", "1 asdf", 6);
+    add_fail_test ("bad expression", "asdf 1", 6);
+    add_fail_test ("bad expression", "asdf jkl", 8);
+    add_fail_test ("bad expression", "  (5 + 23)/   ", 14);
+    add_fail_test ("bad expression", "  ((((5 + 23)/   ", 17);
+    add_fail_test ("divide by zero", "  4 / (1 - 1)", -1);
 
-  add_pass_test ("zero", "0", gnc_numeric_zero ());
-  add_pass_test ("zero with whitespace", "\n\t   0  ", gnc_numeric_zero ());
-  add_pass_test ("1 + 2", NULL, gnc_numeric_create (3, 1));
-  add_pass_test ("17.3 - 12.3000", NULL, gnc_numeric_create (5, 1));
-  add_pass_test ("5 * 6", NULL, gnc_numeric_create (30, 1));
-  add_pass_test (" 34 / (22) ", NULL, gnc_numeric_create (34, 22));
-  add_pass_test (" (4 + 5 * 2) - 7 / 3", NULL, gnc_numeric_create (35, 3));
-  add_pass_test( "(a = 42) + (b = 12) - a", NULL, gnc_numeric_create( 12, 1 ) );
-  add_fail_test( "AUD $1.23", NULL, 4);
-  add_fail_test( "AUD $0.0", NULL, 4);
-  add_fail_test( "AUD 1.23", NULL, 8);
-  add_fail_test( "AUD 0.0", NULL, 7);
-  add_fail_test( "AUD 1.2 + CAN 2.3", NULL, 7);
-  add_fail_test( "AUD $1.2 + CAN $2.3", NULL, 4);
-  
-  add_pass_test( "1 + 2 * 3 + 4 + 5 * 6 * 7", NULL, gnc_numeric_create(221, 1) );
-  add_pass_test( "1 - 2 * 3 + 4 - 5 * 6 * 7", NULL, gnc_numeric_create(-211, 1) );
-  add_pass_test( "Conrad's bug",
-                 "22.32 * 2 + 16.8 + 34.2 * 2 + 18.81 + 85.44"
-                 "- 42.72 + 13.32 + 15.48 + 23.4 + 115.4",
-                 gnc_numeric_create(35897, 100) );
+    add_pass_test ("zero", "0", gnc_numeric_zero ());
+    add_pass_test ("zero with whitespace", "\n\t   0  ", gnc_numeric_zero ());
+    add_pass_test ("1 + 2", NULL, gnc_numeric_create (3, 1));
+    add_pass_test ("17.3 - 12.3000", NULL, gnc_numeric_create (5, 1));
+    add_pass_test ("5 * 6", NULL, gnc_numeric_create (30, 1));
+    add_pass_test (" 34 / (22) ", NULL, gnc_numeric_create (34, 22));
+    add_pass_test (" (4 + 5 * 2) - 7 / 3", NULL, gnc_numeric_create (35, 3));
+    add_pass_test( "(a = 42) + (b = 12) - a", NULL, gnc_numeric_create( 12, 1 ) );
+    add_fail_test( "AUD $1.23", NULL, 4);
+    add_fail_test( "AUD $0.0", NULL, 4);
+    add_fail_test( "AUD 1.23", NULL, 8);
+    add_fail_test( "AUD 0.0", NULL, 7);
+    add_fail_test( "AUD 1.2 + CAN 2.3", NULL, 7);
+    add_fail_test( "AUD $1.2 + CAN $2.3", NULL, 4);
 
-  /* This must be defined for the function-parsing to work. */
-  scm_c_eval_string("(define (gnc:error->string tag args)   (define (write-error port)     (if (and (list? args) (not (null? args)))         (let ((func (car args)))           (if func               (begin                 (display \"Function: \" port)                 (display func port)                 (display \", \" port)                 (display tag port)                 (display \"\n\n\" port)))))     (false-if-exception      (apply display-error (fluid-ref the-last-stack) port args))     (display-backtrace (fluid-ref the-last-stack) port)     (force-output port))   (false-if-exception    (call-with-output-string write-error)))");
+    add_pass_test( "1 + 2 * 3 + 4 + 5 * 6 * 7", NULL, gnc_numeric_create(221, 1) );
+    add_pass_test( "1 - 2 * 3 + 4 - 5 * 6 * 7", NULL, gnc_numeric_create(-211, 1) );
+    add_pass_test( "Conrad's bug",
+                   "22.32 * 2 + 16.8 + 34.2 * 2 + 18.81 + 85.44"
+                   "- 42.72 + 13.32 + 15.48 + 23.4 + 115.4",
+                   gnc_numeric_create(35897, 100) );
 
-  scm_c_eval_string( "(define (gnc:plus a b) (+ a b))" );
-  add_pass_test("plus(2 : 1)", NULL, gnc_numeric_create(3,1));
-  add_fail_test("plus(1:2) plus(3:4)", NULL, 15);
-  add_pass_test( "plus( 1 : 2 ) + 3", NULL, gnc_numeric_create( 6, 1 ) );
-  add_pass_test( "plus( 1 : 2 ) * 3", NULL, gnc_numeric_create( 9, 1 ) );
-  add_pass_test( "plus( 1 + 2 : 3 ) * 5", NULL, gnc_numeric_create( 30, 1 ) );
-  add_pass_test( "plus( ( 1 + 2 ) * 3 : 4 ) + 5", NULL, gnc_numeric_create( 18, 1) );
-  add_pass_test( "5 + plus( ( 1 + 2 ) * 3 : 4 )", NULL, gnc_numeric_create( 18, 1) );
-  add_pass_test( "plus( plus( 1 : 2 ) : 3 )", NULL, gnc_numeric_create( 6, 1 ) );
-  add_pass_test( "plus( 4 : plus( plus( 1 : 2 ) : 3))", NULL, gnc_numeric_create( 10, 1 ) );
+    /* This must be defined for the function-parsing to work. */
+    scm_c_eval_string("(define (gnc:error->string tag args)   (define (write-error port)     (if (and (list? args) (not (null? args)))         (let ((func (car args)))           (if func               (begin                 (display \"Function: \" port)                 (display func port)                 (display \", \" port)                 (display tag port)                 (display \"\n\n\" port)))))     (false-if-exception      (apply display-error (fluid-ref the-last-stack) port args))     (display-backtrace (fluid-ref the-last-stack) port)     (force-output port))   (false-if-exception    (call-with-output-string write-error)))");
 
-  scm_c_eval_string( "(define (gnc:sub a b) (- a b))" );
-  add_pass_test( "sub( 1 : 2 ) + 4", NULL, gnc_numeric_create( 3, 1 ) );
+    scm_c_eval_string( "(define (gnc:plus a b) (+ a b))" );
+    add_pass_test("plus(2 : 1)", NULL, gnc_numeric_create(3, 1));
+    add_fail_test("plus(1:2) plus(3:4)", NULL, 15);
+    add_pass_test( "plus( 1 : 2 ) + 3", NULL, gnc_numeric_create( 6, 1 ) );
+    add_pass_test( "plus( 1 : 2 ) * 3", NULL, gnc_numeric_create( 9, 1 ) );
+    add_pass_test( "plus( 1 + 2 : 3 ) * 5", NULL, gnc_numeric_create( 30, 1 ) );
+    add_pass_test( "plus( ( 1 + 2 ) * 3 : 4 ) + 5", NULL, gnc_numeric_create( 18, 1) );
+    add_pass_test( "5 + plus( ( 1 + 2 ) * 3 : 4 )", NULL, gnc_numeric_create( 18, 1) );
+    add_pass_test( "plus( plus( 1 : 2 ) : 3 )", NULL, gnc_numeric_create( 6, 1 ) );
+    add_pass_test( "plus( 4 : plus( plus( 1 : 2 ) : 3))", NULL, gnc_numeric_create( 10, 1 ) );
 
-  add_pass_test( "sub( (1 + 2 * 3) : 4 ) + 5",
-                 NULL, gnc_numeric_create( 8, 1 ) );
-  add_pass_test( "sub( 1 : 2 ) + sub( 3 : 4 ) + 5",
-                 NULL, gnc_numeric_create( 3, 1 ) );
-  add_pass_test( "sub( a = 42 : sub( plus( 1 : 2 ) : 6 * 7 )) + a",
-                 NULL, gnc_numeric_create( 123, 1 ) );
+    scm_c_eval_string( "(define (gnc:sub a b) (- a b))" );
+    add_pass_test( "sub( 1 : 2 ) + 4", NULL, gnc_numeric_create( 3, 1 ) );
 
-  scm_c_eval_string( "(define (gnc:test_str str b)"
-		     "  (+ b (cond ((equal? str \"one\") 1)"
-		     "             ((equal? str \"two\") 2)"
-		     "             ((equal? str \"three\") 3)"
-		     "             (0))))" );
-  add_pass_test( "test_str( \"one\" : 1 )",  NULL, gnc_numeric_create( 2, 1 ) );
-  add_pass_test( "test_str( \"two\" : 2 )",  NULL, gnc_numeric_create( 4, 1 ) );
-  add_fail_test( "test_str( 3 : \"three\" )", NULL, 23 );
-  add_pass_test( "test_str( \"asdf\" : 1 )", NULL, gnc_numeric_create( 1, 1 ) );
-  add_fail_test("\"asdf\" + 0", NULL, 8);
+    add_pass_test( "sub( (1 + 2 * 3) : 4 ) + 5",
+                   NULL, gnc_numeric_create( 8, 1 ) );
+    add_pass_test( "sub( 1 : 2 ) + sub( 3 : 4 ) + 5",
+                   NULL, gnc_numeric_create( 3, 1 ) );
+    add_pass_test( "sub( a = 42 : sub( plus( 1 : 2 ) : 6 * 7 )) + a",
+                   NULL, gnc_numeric_create( 123, 1 ) );
 
-  scm_c_eval_string( "(define (gnc:blindreturn val) val)" );
-  add_pass_test( "blindreturn( 123.1 )", NULL, gnc_numeric_create( 1231, 10 ) );
-  add_pass_test( "blindreturn( 123.01 )", NULL, gnc_numeric_create( 12301, 100 ) );
-  add_pass_test( "blindreturn( 123.001 )", NULL, gnc_numeric_create( 123001, 1000 ) );
+    scm_c_eval_string( "(define (gnc:test_str str b)"
+                       "  (+ b (cond ((equal? str \"one\") 1)"
+                       "             ((equal? str \"two\") 2)"
+                       "             ((equal? str \"three\") 3)"
+                       "             (0))))" );
+    add_pass_test( "test_str( \"one\" : 1 )",  NULL, gnc_numeric_create( 2, 1 ) );
+    add_pass_test( "test_str( \"two\" : 2 )",  NULL, gnc_numeric_create( 4, 1 ) );
+    add_fail_test( "test_str( 3 : \"three\" )", NULL, 23 );
+    add_pass_test( "test_str( \"asdf\" : 1 )", NULL, gnc_numeric_create( 1, 1 ) );
+    add_fail_test("\"asdf\" + 0", NULL, 8);
 
-  run_parser_tests ();
+    scm_c_eval_string( "(define (gnc:blindreturn val) val)" );
+    add_pass_test( "blindreturn( 123.1 )", NULL, gnc_numeric_create( 1231, 10 ) );
+    add_pass_test( "blindreturn( 123.01 )", NULL, gnc_numeric_create( 12301, 100 ) );
+    add_pass_test( "blindreturn( 123.001 )", NULL, gnc_numeric_create( 123001, 1000 ) );
 
-  gnc_exp_parser_shutdown ();
-  success ("shutdown expression parser");
+    run_parser_tests ();
+
+    gnc_exp_parser_shutdown ();
+    success ("shutdown expression parser");
 }
 
 static void
 test_variable_expressions()
 {
-  gnc_numeric num;
-  gchar *errLoc = NULL;
-  GHashTable *vars = g_hash_table_new(g_str_hash, g_str_equal);
-  do_test(gnc_exp_parser_parse_separate_vars("123 + a", &num, &errLoc, vars), "parsing");
-  do_test(g_hash_table_size(vars) == 1, "'a' is the variable; good job, gnc-exp-parser!");
-  success("variable found");
+    gnc_numeric num;
+    gchar *errLoc = NULL;
+    GHashTable *vars = g_hash_table_new(g_str_hash, g_str_equal);
+    do_test(gnc_exp_parser_parse_separate_vars("123 + a", &num, &errLoc, vars), "parsing");
+    do_test(g_hash_table_size(vars) == 1, "'a' is the variable; good job, gnc-exp-parser!");
+    success("variable found");
 }
 
 static void
 real_main (void *closure, int argc, char **argv)
 {
-  /* set_should_print_success (TRUE); */
-  test_parser();
-  test_variable_expressions();
-  print_test_results();
-  exit(get_rv());
+    /* set_should_print_success (TRUE); */
+    test_parser();
+    test_variable_expressions();
+    print_test_results();
+    exit(get_rv());
 }
 
 int main ( int argc, char **argv )
 {
-  /* do things this way so we can test scheme function calls from expressions */
-  scm_boot_guile( argc, argv, real_main, NULL );
-  return 0;
+    /* do things this way so we can test scheme function calls from expressions */
+    scm_boot_guile( argc, argv, real_main, NULL );
+    return 0;
 }

Modified: gnucash/trunk/src/app-utils/test/test-link-module.c
===================================================================
--- gnucash/trunk/src/app-utils/test/test-link-module.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/test/test-link-module.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 
 int
-main(int argc, char ** argv) {
-  exit(0);
+main(int argc, char ** argv)
+{
+    exit(0);
 }

Modified: gnucash/trunk/src/app-utils/test/test-print-parse-amount.c
===================================================================
--- gnucash/trunk/src/app-utils/test/test-print-parse-amount.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/test/test-print-parse-amount.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -11,76 +11,77 @@
 static void
 test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line)
 {
-  gnc_numeric n_parsed = gnc_numeric_zero();
-  const char *s;
-  gboolean ok, print_ok;
+    gnc_numeric n_parsed = gnc_numeric_zero();
+    const char *s;
+    gboolean ok, print_ok;
 
-  s = xaccPrintAmount (n, print_info);
-  print_ok = (s && s[0] != '\0');
-  if (!print_ok)
-      return;
+    s = xaccPrintAmount (n, print_info);
+    print_ok = (s && s[0] != '\0');
+    if (!print_ok)
+        return;
 
-  ok = xaccParseAmount (s, print_info.monetary, &n_parsed, NULL);
+    ok = xaccParseAmount (s, print_info.monetary, &n_parsed, NULL);
 
-  do_test_args (ok, "parsing failure", __FILE__, __LINE__,
-                "num: %s, string %s (line %d)", gnc_numeric_to_string (n), s, line);
+    do_test_args (ok, "parsing failure", __FILE__, __LINE__,
+                  "num: %s, string %s (line %d)", gnc_numeric_to_string (n), s, line);
 
-  ok = gnc_numeric_equal (n, n_parsed);
+    ok = gnc_numeric_equal (n, n_parsed);
 
-  do_test_args (ok, "not equal", __FILE__, __LINE__,
-                "start: %s, string %s, finish: %s (line %d)",
-                gnc_numeric_to_string (n), s,
-                gnc_numeric_to_string (n_parsed), line);
+    do_test_args (ok, "not equal", __FILE__, __LINE__,
+                  "start: %s, string %s, finish: %s (line %d)",
+                  gnc_numeric_to_string (n), s,
+                  gnc_numeric_to_string (n_parsed), line);
 }
 
 static void
 test_num (gnc_numeric n)
 {
-  GNCPrintAmountInfo print_info;
-  int fraction;
-  int i;
+    GNCPrintAmountInfo print_info;
+    int fraction;
+    int i;
 
-  print_info.commodity = NULL;
-  print_info.min_decimal_places = 0;
-  print_info.use_locale = 1;
-  print_info.use_symbol = 0;
+    print_info.commodity = NULL;
+    print_info.min_decimal_places = 0;
+    print_info.use_locale = 1;
+    print_info.use_symbol = 0;
 
-  for (i = 1, fraction = 10; i < 9; i++, fraction *= 10)
-  {
-    gnc_numeric n1;
+    for (i = 1, fraction = 10; i < 9; i++, fraction *= 10)
+    {
+        gnc_numeric n1;
 
-    print_info.use_separators = 1;
-    print_info.monetary = 1;
-    print_info.max_decimal_places = i;
-    print_info.force_fit = 0;
-    print_info.round = 0;
+        print_info.use_separators = 1;
+        print_info.monetary = 1;
+        print_info.max_decimal_places = i;
+        print_info.force_fit = 0;
+        print_info.round = 0;
 
-    n1 = gnc_numeric_convert (n, fraction, GNC_RND_ROUND);
-    if (gnc_numeric_check(n1)) {
-        do_test_args((gnc_numeric_check(n1) == GNC_ERROR_OVERFLOW), 
-                     "BAD NUMERIC CONVERSION", __FILE__, __LINE__,
-		   "num: %s, fraction: %d", gnc_numeric_to_string(n), fraction);
-      continue;
-    }
+        n1 = gnc_numeric_convert (n, fraction, GNC_RND_ROUND);
+        if (gnc_numeric_check(n1))
+        {
+            do_test_args((gnc_numeric_check(n1) == GNC_ERROR_OVERFLOW),
+                         "BAD NUMERIC CONVERSION", __FILE__, __LINE__,
+                         "num: %s, fraction: %d", gnc_numeric_to_string(n), fraction);
+            continue;
+        }
 
-    test_num_print_info (n1, print_info, __LINE__);
-	
-    print_info.monetary = 0;
-    test_num_print_info (n1, print_info, __LINE__);
+        test_num_print_info (n1, print_info, __LINE__);
 
-    print_info.use_separators = 0;
-    test_num_print_info (n1, print_info, __LINE__);
+        print_info.monetary = 0;
+        test_num_print_info (n1, print_info, __LINE__);
 
-    print_info.round = 1;
-    test_num_print_info (n1, print_info, __LINE__);
+        print_info.use_separators = 0;
+        test_num_print_info (n1, print_info, __LINE__);
 
-    print_info.round = 0;
-    print_info.force_fit = 1;
-    test_num_print_info (n1, print_info, __LINE__);
+        print_info.round = 1;
+        test_num_print_info (n1, print_info, __LINE__);
 
-    print_info.round = 1;
-    test_num_print_info (n1, print_info, __LINE__);
-  }
+        print_info.round = 0;
+        print_info.force_fit = 1;
+        test_num_print_info (n1, print_info, __LINE__);
+
+        print_info.round = 1;
+        test_num_print_info (n1, print_info, __LINE__);
+    }
 }
 
 #define IS_VALID_NUM(n,m)                                               \
@@ -96,31 +97,31 @@
 static void
 run_tests (void)
 {
-  int i;
+    int i;
 
-  for (i = 0; i < 50; i++)
-  {
-    gnc_numeric n;
-    gnc_numeric n1;
+    for (i = 0; i < 50; i++)
+    {
+        gnc_numeric n;
+        gnc_numeric n1;
 
-    n = get_random_gnc_numeric ();
-    IS_VALID_NUM(n,n);
-    test_num (n);
+        n = get_random_gnc_numeric ();
+        IS_VALID_NUM(n, n);
+        test_num (n);
 
-    n1 = gnc_numeric_mul (n, n, n.denom, GNC_RND_ROUND);
-    IS_VALID_NUM(n1,n);
-    test_num (n);
+        n1 = gnc_numeric_mul (n, n, n.denom, GNC_RND_ROUND);
+        IS_VALID_NUM(n1, n);
+        test_num (n);
 
-    n1 = gnc_numeric_mul (n, n, n.denom, GNC_RND_ROUND);
-    IS_VALID_NUM(n1,n);
-    test_num (n);
-  }
+        n1 = gnc_numeric_mul (n, n, n.denom, GNC_RND_ROUND);
+        IS_VALID_NUM(n1, n);
+        test_num (n);
+    }
 }
 
 int
 main (int argc, char **argv)
 {
-  run_tests ();
-  print_test_results ();
-  exit (get_rv ());
+    run_tests ();
+    print_test_results ();
+    exit (get_rv ());
 }

Modified: gnucash/trunk/src/app-utils/test/test-print-queries.c
===================================================================
--- gnucash/trunk/src/app-utils/test/test-print-queries.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/test/test-print-queries.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -15,69 +15,70 @@
 static void
 test_query (Query *q, SCM val2str)
 {
-  SCM scm_q;
-  SCM str_q;
-  SCM args = SCM_EOL;
+    SCM scm_q;
+    SCM str_q;
+    SCM args = SCM_EOL;
 
-  scm_q = gnc_query2scm (q);
-  args = scm_cons (scm_q, SCM_EOL);
-  str_q = scm_apply (val2str, args, SCM_EOL);
+    scm_q = gnc_query2scm (q);
+    args = scm_cons (scm_q, SCM_EOL);
+    str_q = scm_apply (val2str, args, SCM_EOL);
 
-  args = scm_cons (scm_makfrom0str ("'"), scm_cons (str_q, SCM_EOL));
-  str_q = scm_string_append (args);
+    args = scm_cons (scm_makfrom0str ("'"), scm_cons (str_q, SCM_EOL));
+    str_q = scm_string_append (args);
 
-  scm_display (str_q, SCM_UNDEFINED);
-  scm_newline (SCM_UNDEFINED);
-  scm_newline (SCM_UNDEFINED);
+    scm_display (str_q, SCM_UNDEFINED);
+    scm_newline (SCM_UNDEFINED);
+    scm_newline (SCM_UNDEFINED);
 }
 
 static void
 run_tests (int count)
 {
-  Query *q;
-  SCM val2str;
-  int i;
+    Query *q;
+    SCM val2str;
+    int i;
 
-  val2str = scm_c_eval_string ("gnc:value->string");
-  g_return_if_fail (SCM_PROCEDUREP (val2str));
+    val2str = scm_c_eval_string ("gnc:value->string");
+    g_return_if_fail (SCM_PROCEDUREP (val2str));
 
-  for (i = 0; i < count; i++) {
-    q = get_random_query ();
-    test_query (q, val2str);
-    xaccFreeQuery (q);
-  }
-  success ("");
+    for (i = 0; i < count; i++)
+    {
+        q = get_random_query ();
+        test_query (q, val2str);
+        xaccFreeQuery (q);
+    }
+    success ("");
 }
 
 static void
 main_helper (void *closure, int argc, char **argv)
 {
-  int count = 50;
+    int count = 50;
 
-  gnc_module_load("gnucash/engine", 0);
-  gnc_module_load("gnucash/app-utils", 0);
+    gnc_module_load("gnucash/engine", 0);
+    gnc_module_load("gnucash/app-utils", 0);
 
-  if (argc > 1)
-    count = atoi (argv[1]);
+    if (argc > 1)
+        count = atoi (argv[1]);
 
-  if (count < 0)
-    count = 0;
+    if (count < 0)
+        count = 0;
 
-  xaccLogDisable ();
+    xaccLogDisable ();
 
-  /* scm conversion doesn't handle binary atm */
-  kvp_exclude_type (KVP_TYPE_BINARY);
+    /* scm conversion doesn't handle binary atm */
+    kvp_exclude_type (KVP_TYPE_BINARY);
 
-  run_tests (count);
+    run_tests (count);
 
-  print_test_results ();
+    print_test_results ();
 
-  exit (get_rv ());
+    exit (get_rv ());
 }
 
 int
 main (int argc, char **argv)
 {
-  scm_boot_guile (argc, argv, main_helper, NULL);
-  return 0;
+    scm_boot_guile (argc, argv, main_helper, NULL);
+    return 0;
 }

Modified: gnucash/trunk/src/app-utils/test/test-scm-query-string.c
===================================================================
--- gnucash/trunk/src/app-utils/test/test-scm-query-string.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/test/test-scm-query-string.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -15,106 +15,110 @@
 static void
 test_query (Query *q, SCM val2str)
 {
-  SCM scm_q;
-  SCM str_q;
-  SCM res_q;
-  SCM args = SCM_EOL;
-  Query *q2;
-  const gchar * str;
-  gchar *str2 = NULL;
+    SCM scm_q;
+    SCM str_q;
+    SCM res_q;
+    SCM args = SCM_EOL;
+    Query *q2;
+    const gchar * str;
+    gchar *str2 = NULL;
 
-  scm_q = gnc_query2scm (q);
-  args = scm_cons (scm_q, SCM_EOL);
-  str_q = scm_apply (val2str, args, SCM_EOL);
+    scm_q = gnc_query2scm (q);
+    args = scm_cons (scm_q, SCM_EOL);
+    str_q = scm_apply (val2str, args, SCM_EOL);
 
-  args = scm_cons (scm_makfrom0str ("'"), scm_cons (str_q, SCM_EOL));
-  str_q = scm_string_append (args);
+    args = scm_cons (scm_makfrom0str ("'"), scm_cons (str_q, SCM_EOL));
+    str_q = scm_string_append (args);
 
-  str = SCM_STRING_CHARS (str_q);
-  if (str) str2 = g_strdup(str);
-  if (str2) {
-    res_q = scm_c_eval_string (str2);
-  } else {
-    res_q = SCM_BOOL_F;
-  }
+    str = SCM_STRING_CHARS (str_q);
+    if (str) str2 = g_strdup(str);
+    if (str2)
+    {
+        res_q = scm_c_eval_string (str2);
+    }
+    else
+    {
+        res_q = SCM_BOOL_F;
+    }
 
-  q2 = gnc_scm2query (res_q);
+    q2 = gnc_scm2query (res_q);
 
-  if (!xaccQueryEqual (q, q2))
-  {
-    failure ("queries don't match");
-    fprintf (stderr, "%s\n\n", str2 ? str2 : "(null)");
-    scm_q = gnc_query2scm (q2);
-    scm_display (scm_q, SCM_UNDEFINED);
-    scm_newline (SCM_UNDEFINED);
+    if (!xaccQueryEqual (q, q2))
+    {
+        failure ("queries don't match");
+        fprintf (stderr, "%s\n\n", str2 ? str2 : "(null)");
+        scm_q = gnc_query2scm (q2);
+        scm_display (scm_q, SCM_UNDEFINED);
+        scm_newline (SCM_UNDEFINED);
+        if (str2) g_free(str2);
+        exit (1);
+    }
+    else
+    {
+        success ("queries match");
+    }
     if (str2) g_free(str2);
-    exit (1);
-  }
-  else
-  {
-    success ("queries match");
-  }
-  if (str2) g_free(str2);
-  if (q2) xaccFreeQuery (q2);
+    if (q2) xaccFreeQuery (q2);
 }
 
 static void
 run_tests (void)
 {
-  Query *q;
-  SCM val2str;
-  int i;
+    Query *q;
+    SCM val2str;
+    int i;
 
-  val2str = scm_c_eval_string ("gnc:value->string");
-  g_return_if_fail (SCM_PROCEDUREP (val2str));
+    val2str = scm_c_eval_string ("gnc:value->string");
+    g_return_if_fail (SCM_PROCEDUREP (val2str));
 
-  for (i = 0; i < 1000; i++) {
-    q = get_random_query ();
-    test_query (q, val2str);
-    xaccFreeQuery (q);
-    printf("%d ", i);
-    fflush(stdout);
-  }
+    for (i = 0; i < 1000; i++)
+    {
+        q = get_random_query ();
+        test_query (q, val2str);
+        xaccFreeQuery (q);
+        printf("%d ", i);
+        fflush(stdout);
+    }
 
-  { 
-    q = get_random_query ();
-    test_query (q, val2str);
-    xaccFreeQuery (q);
-    printf("%d ", i);
-    fflush(stdout);
-  }
+    {
+        q = get_random_query ();
+        test_query (q, val2str);
+        xaccFreeQuery (q);
+        printf("%d ", i);
+        fflush(stdout);
+    }
 
-  printf("\n");
+    printf("\n");
 }
 
 static void
 main_helper (void *closure, int argc, char **argv)
 {
-  gnc_module_load("gnucash/engine", 0);
-  gnc_module_load("gnucash/app-utils", 0);
+    gnc_module_load("gnucash/engine", 0);
+    gnc_module_load("gnucash/app-utils", 0);
 
-  xaccLogDisable ();
+    xaccLogDisable ();
 
-  /* scm conversion doesn't handle binary atm */
-  kvp_exclude_type (KVP_TYPE_BINARY);
+    /* scm conversion doesn't handle binary atm */
+    kvp_exclude_type (KVP_TYPE_BINARY);
 
-  /* double->string->double is not idempotent */
-  kvp_exclude_type (KVP_TYPE_DOUBLE);
+    /* double->string->double is not idempotent */
+    kvp_exclude_type (KVP_TYPE_DOUBLE);
 
-  /* Initialize to a known RNG position */
-  guid_init();
-  srand(1);
+    /* Initialize to a known RNG position */
+    guid_init();
+    srand(1);
 
-  run_tests ();
+    run_tests ();
 
-  print_test_results ();
+    print_test_results ();
 
-  exit (get_rv ());
+    exit (get_rv ());
 }
 
 int
 main (int argc, char **argv)
 {
-  scm_boot_guile (argc, argv, main_helper, NULL);
-  return 0;
+    scm_boot_guile (argc, argv, main_helper, NULL);
+    return 0;
 }

Modified: gnucash/trunk/src/app-utils/test/test-sx.c
===================================================================
--- gnucash/trunk/src/app-utils/test/test-sx.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/app-utils/test/test-sx.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -12,187 +12,187 @@
 static void
 test_basic()
 {
-     GncSxInstanceModel *model;
-     GDate *yesterday, *range_end_tomorrow;
-     SchedXaction *foo;
+    GncSxInstanceModel *model;
+    GDate *yesterday, *range_end_tomorrow;
+    SchedXaction *foo;
 
-     yesterday = g_date_new();
-     g_date_clear(yesterday, 1);
-     g_date_set_time_t(yesterday, time(NULL));
-     g_date_subtract_days(yesterday, 1);
+    yesterday = g_date_new();
+    g_date_clear(yesterday, 1);
+    g_date_set_time_t(yesterday, time(NULL));
+    g_date_subtract_days(yesterday, 1);
 
-     foo = add_daily_sx("foo", yesterday, NULL, NULL);
+    foo = add_daily_sx("foo", yesterday, NULL, NULL);
 
-     range_end_tomorrow = g_date_new();
-     g_date_clear(range_end_tomorrow, 1);
-     g_date_set_time_t(range_end_tomorrow, time(NULL));
-     g_date_add_days(range_end_tomorrow, 1);
-     model = gnc_sx_get_instances(range_end_tomorrow, TRUE);
+    range_end_tomorrow = g_date_new();
+    g_date_clear(range_end_tomorrow, 1);
+    g_date_set_time_t(range_end_tomorrow, time(NULL));
+    g_date_add_days(range_end_tomorrow, 1);
+    model = gnc_sx_get_instances(range_end_tomorrow, TRUE);
 
-     {
-          GncSxInstances *insts;
-          GList *iter;
+    {
+        GncSxInstances *insts;
+        GList *iter;
 
-          do_test(g_list_length(model->sx_instance_list) == 1, "1 GncSxInstances");
-          insts = (GncSxInstances*)model->sx_instance_list->data;
-          do_test(g_list_length(insts->instance_list) == 3, "yesterday, today and tomorrow");
-          for (iter = insts->instance_list; iter != NULL; iter = iter->next)
-          {
-               GncSxInstance *inst = (GncSxInstance*)iter->data;
-               do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "to-create");
-          }
-     }
+        do_test(g_list_length(model->sx_instance_list) == 1, "1 GncSxInstances");
+        insts = (GncSxInstances*)model->sx_instance_list->data;
+        do_test(g_list_length(insts->instance_list) == 3, "yesterday, today and tomorrow");
+        for (iter = insts->instance_list; iter != NULL; iter = iter->next)
+        {
+            GncSxInstance *inst = (GncSxInstance*)iter->data;
+            do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "to-create");
+        }
+    }
 
-     g_object_unref(G_OBJECT(model));
-     remove_sx(foo);
+    g_object_unref(G_OBJECT(model));
+    remove_sx(foo);
 }
 
 static void
 test_empty()
 {
-     // no sxes should exist at this point.
-     int way_in_the_future_year = 2038;
-     GDate *end;
-     GncSxInstanceModel *model;
+    // no sxes should exist at this point.
+    int way_in_the_future_year = 2038;
+    GDate *end;
+    GncSxInstanceModel *model;
 
-     end = g_date_new_dmy(31, 12, way_in_the_future_year);
-     model = gnc_sx_get_instances(end, TRUE);
-     do_test(g_list_length(model->sx_instance_list) == 0, "no instances");
-     g_object_unref(G_OBJECT(model));
-     success("empty");
+    end = g_date_new_dmy(31, 12, way_in_the_future_year);
+    model = gnc_sx_get_instances(end, TRUE);
+    do_test(g_list_length(model->sx_instance_list) == 0, "no instances");
+    g_object_unref(G_OBJECT(model));
+    success("empty");
 }
 
 static void
 test_once()
 {
-     SchedXaction *lonely;
-     GDate *when, *end;
-     int random_offset_within_one_year = 0;
-     GncSxInstanceModel *model;
-     GncSxInstances *instances;
-     GncSxInstance *instance;
+    SchedXaction *lonely;
+    GDate *when, *end;
+    int random_offset_within_one_year = 0;
+    GncSxInstanceModel *model;
+    GncSxInstances *instances;
+    GncSxInstance *instance;
 
-     when = g_date_new();
-     g_date_clear(when, 1);
-     g_date_set_time_t(when, time(NULL));
-     while (random_offset_within_one_year == 0)
-          random_offset_within_one_year = get_random_int_in_range(-365, 365);
-     g_date_add_days(when, random_offset_within_one_year);
+    when = g_date_new();
+    g_date_clear(when, 1);
+    g_date_set_time_t(when, time(NULL));
+    while (random_offset_within_one_year == 0)
+        random_offset_within_one_year = get_random_int_in_range(-365, 365);
+    g_date_add_days(when, random_offset_within_one_year);
 
-     end = g_date_new();
-     g_date_clear(end, 1);
-     g_date_set_time_t(end, time(NULL));
-     g_date_add_years(end, 1);
+    end = g_date_new();
+    g_date_clear(end, 1);
+    g_date_set_time_t(end, time(NULL));
+    g_date_add_years(end, 1);
 
-     lonely = add_once_sx("once", when);
+    lonely = add_once_sx("once", when);
 
-     model = gnc_sx_get_instances(end, TRUE);
+    model = gnc_sx_get_instances(end, TRUE);
 
-     do_test(g_list_length(model->sx_instance_list) == 1, "1 instances");
-     instances = (GncSxInstances*)model->sx_instance_list->data;
-     do_test(g_list_length(instances->instance_list) == 1, "1 instance");
-     instance = (GncSxInstance*)instances->instance_list->data;
-     do_test(g_date_compare(when, &instances->next_instance_date) == 0, "next instance is expected");
-     do_test(g_date_compare(when, &instance->date) == 0, "instance date is expected");
+    do_test(g_list_length(model->sx_instance_list) == 1, "1 instances");
+    instances = (GncSxInstances*)model->sx_instance_list->data;
+    do_test(g_list_length(instances->instance_list) == 1, "1 instance");
+    instance = (GncSxInstance*)instances->instance_list->data;
+    do_test(g_date_compare(when, &instances->next_instance_date) == 0, "next instance is expected");
+    do_test(g_date_compare(when, &instance->date) == 0, "instance date is expected");
 
-     g_object_unref(model);
-     success("model unref");
-     remove_sx(lonely);
+    g_object_unref(model);
+    success("model unref");
+    remove_sx(lonely);
 }
 
 static GncSxInstance*
 _nth_instance(GncSxInstances *instances, int i)
 {
-     return (GncSxInstance*)g_list_nth_data(instances->instance_list, i);
+    return (GncSxInstance*)g_list_nth_data(instances->instance_list, i);
 }
 
 static void
 test_state_changes()
 {
-     SchedXaction *foo;
-     GDate *start, *end;
-     GncSxInstanceModel *model;
-     GncSxInstances *insts;
-     GncSxInstance *inst;
+    SchedXaction *foo;
+    GDate *start, *end;
+    GncSxInstanceModel *model;
+    GncSxInstances *insts;
+    GncSxInstance *inst;
 
-     start = g_date_new();
-     g_date_set_time_t(start, time(NULL));
-     
-     end = g_date_new();
-     g_date_set_time_t(end, time(NULL));
-     g_date_add_days(end, 3);
+    start = g_date_new();
+    g_date_set_time_t(start, time(NULL));
 
-     foo = add_daily_sx("foo", start, NULL, NULL);
-     model = gnc_sx_get_instances(end, TRUE);
+    end = g_date_new();
+    g_date_set_time_t(end, time(NULL));
+    g_date_add_days(end, 3);
 
-     do_test(g_list_length(model->sx_instance_list) == 1, "one sx");
-     insts = (GncSxInstances*)g_list_nth_data(model->sx_instance_list, 0);
-     do_test(g_list_length(insts->instance_list) == 4, "4 instances");
+    foo = add_daily_sx("foo", start, NULL, NULL);
+    model = gnc_sx_get_instances(end, TRUE);
 
-     inst = _nth_instance(insts, 2);
-     gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_TO_CREATE);
-     {
-          int i;
-          for (i = 0; i < 4; i++)
-          {
-               inst = _nth_instance(insts, i);
-               do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "0 didn't change");
-          }
-          success("nothing else changed");
-     }
+    do_test(g_list_length(model->sx_instance_list) == 1, "one sx");
+    insts = (GncSxInstances*)g_list_nth_data(model->sx_instance_list, 0);
+    do_test(g_list_length(insts->instance_list) == 4, "4 instances");
 
-     inst = _nth_instance(insts, 1);
-     gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_POSTPONED);
-     {
-          int i;
-          inst = _nth_instance(insts, 1);
-          do_test(inst->state == SX_INSTANCE_STATE_POSTPONED, "as we said");
-          for (i = 0; i < 4; i++)
-          {
-               if (i == 1)
-                    continue; // skip
-               inst = _nth_instance(insts, i);
-               do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "still to create");
-          }
-     }
-     success("postponed changed what it needed to");
+    inst = _nth_instance(insts, 2);
+    gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_TO_CREATE);
+    {
+        int i;
+        for (i = 0; i < 4; i++)
+        {
+            inst = _nth_instance(insts, i);
+            do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "0 didn't change");
+        }
+        success("nothing else changed");
+    }
 
-     inst = _nth_instance(insts, 1);
-     gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_REMINDER);
-     success("changed to reminder");
-     {
-          int i;
-          inst = _nth_instance(insts, 0);
-          do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "left alone");
-          inst = _nth_instance(insts, 1);
-          do_test(inst->state == SX_INSTANCE_STATE_REMINDER, "as we asked for");
-          for (i = 2; i < 4; i++)
-          {
-               inst = _nth_instance(insts, i);
-               do_test(inst->state == SX_INSTANCE_STATE_REMINDER, "changed as well");
-          }
-     }
+    inst = _nth_instance(insts, 1);
+    gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_POSTPONED);
+    {
+        int i;
+        inst = _nth_instance(insts, 1);
+        do_test(inst->state == SX_INSTANCE_STATE_POSTPONED, "as we said");
+        for (i = 0; i < 4; i++)
+        {
+            if (i == 1)
+                continue; // skip
+            inst = _nth_instance(insts, i);
+            do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "still to create");
+        }
+    }
+    success("postponed changed what it needed to");
 
-     g_object_unref(model);
-     remove_sx(foo);
+    inst = _nth_instance(insts, 1);
+    gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_REMINDER);
+    success("changed to reminder");
+    {
+        int i;
+        inst = _nth_instance(insts, 0);
+        do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "left alone");
+        inst = _nth_instance(insts, 1);
+        do_test(inst->state == SX_INSTANCE_STATE_REMINDER, "as we asked for");
+        for (i = 2; i < 4; i++)
+        {
+            inst = _nth_instance(insts, i);
+            do_test(inst->state == SX_INSTANCE_STATE_REMINDER, "changed as well");
+        }
+    }
+
+    g_object_unref(model);
+    remove_sx(foo);
 }
 
 int
 main(int argc, char **argv)
 {
-     g_type_init();
-     qof_init();
-     gnc_engine_init(0, NULL);
+    g_type_init();
+    qof_init();
+    gnc_engine_init(0, NULL);
 
-     test_empty();
-     {
-          int i;
-          for (i = 0; i < 10; i++)
-               test_once();
-     }
-     test_basic();
-     test_state_changes();
+    test_empty();
+    {
+        int i;
+        for (i = 0; i < 10; i++)
+            test_once();
+    }
+    test_basic();
+    test_state_changes();
 
-     print_test_results();
-     exit(get_rv());
+    print_test_results();
+    exit(get_rv());
 }

Modified: gnucash/trunk/src/backend/postgres/PostgresBackend.c
===================================================================
--- gnucash/trunk/src/backend/postgres/PostgresBackend.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/PostgresBackend.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -27,15 +27,15 @@
 #include <ctype.h>
 #include <netdb.h>
 #include <pwd.h>
-#include <stdio.h>  
-#include <stdlib.h>  
-#include <string.h>  
-#include <sys/types.h>  
-#include <unistd.h>  
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
 #if HAVE_LANGINFO_CODESET
 #include <langinfo.h>
 #endif
-#include <libpq-fe.h>  
+#include <libpq-fe.h>
 
 #include "AccountP.h"
 #include "gnc-commodity.h"
@@ -70,7 +70,7 @@
 /* hack alert -- this is the query buffer size, it can be overflowed.
  * Ideally, its dynamically resized.  On the other hand, Postgres
  * rejects queries longer than 8192 bytes, (according to the
- * documentation) so there's not much point in getting fancy ... 
+ * documentation) so there's not much point in getting fancy ...
  */
 #define QBUFSIZE 16350
 
@@ -80,50 +80,50 @@
 static char *
 pgendGetHostname (PGBackend *be)
 {
-   char * p;
+    char * p;
 
-   p = be->buff;
-   *p = 0;
-   if (0 == gethostname (p, QBUFSIZE/3)) 
-   {
-      extern int h_errno;
-      struct hostent *hent;
+    p = be->buff;
+    *p = 0;
+    if (0 == gethostname (p, QBUFSIZE / 3))
+    {
+        extern int h_errno;
+        struct hostent *hent;
 
-      hent = gethostbyname (be->buff);
-      if (hent) 
-      {
-         strcpy (be->buff, hent->h_name);
-      }
-      else
-      {
-         PERR ("can't get domainname: %s", hstrerror(h_errno));
-      }
-   } 
-   else
-   {
-      *p = 0;
-      PERR ("can't get hostname");
-   }
+        hent = gethostbyname (be->buff);
+        if (hent)
+        {
+            strcpy (be->buff, hent->h_name);
+        }
+        else
+        {
+            PERR ("can't get domainname: %s", hstrerror(h_errno));
+        }
+    }
+    else
+    {
+        *p = 0;
+        PERR ("can't get hostname");
+    }
 
-   return be->buff;
+    return be->buff;
 }
 
 static char *
 pgendGetUsername (PGBackend *be)
 {
-   uid_t uid = getuid();
-   struct passwd *pw = getpwuid (uid);
-   if (pw) return (pw->pw_name);
-   return NULL;
+    uid_t uid = getuid();
+    struct passwd *pw = getpwuid (uid);
+    if (pw) return (pw->pw_name);
+    return NULL;
 }
 
 static char *
 pgendGetUserGecos (PGBackend *be)
 {
-   uid_t uid = getuid();
-   struct passwd *pw = getpwuid (uid);
-   if (pw) return (pw->pw_gecos);
-   return NULL;
+    uid_t uid = getuid();
+    struct passwd *pw = getpwuid (uid);
+    if (pw) return (pw->pw_gecos);
+    return NULL;
 }
 
 /* ============================================================= */
@@ -131,101 +131,115 @@
 Account *
 pgendAccountLookup (PGBackend *be, const GUID *acct_guid)
 {
-   GList *node;
-   Account * acc = NULL;
+    GList *node;
+    Account * acc = NULL;
 
-   ENTER("guid = %s", guid_to_string(acct_guid));
-   for (node=be->blist; node; node=node->next)
-   {
-      QofBook *book = node->data;
-      acc = xaccAccountLookup (acct_guid, book);
-      if (acc) { LEAVE("acc = %p", acc); return acc; }
-   }
+    ENTER("guid = %s", guid_to_string(acct_guid));
+    for (node = be->blist; node; node = node->next)
+    {
+        QofBook *book = node->data;
+        acc = xaccAccountLookup (acct_guid, book);
+        if (acc)
+        {
+            LEAVE("acc = %p", acc);
+            return acc;
+        }
+    }
 
-   LEAVE("acc = (null)");
-   return NULL;
+    LEAVE("acc = (null)");
+    return NULL;
 }
 
 Transaction *
 pgendTransLookup (PGBackend *be, const GUID *txn_guid)
 {
-   GList *node;
-   Transaction * txn = NULL;
+    GList *node;
+    Transaction * txn = NULL;
 
-   ENTER("guid = %s", guid_to_string(txn_guid));
-   for (node=be->blist; node; node=node->next)
-   {
-      QofBook *book = node->data;
-      txn = xaccTransLookup (txn_guid, book);
-      if (txn) { LEAVE("txt = %p", txn); return txn; }
-   }
+    ENTER("guid = %s", guid_to_string(txn_guid));
+    for (node = be->blist; node; node = node->next)
+    {
+        QofBook *book = node->data;
+        txn = xaccTransLookup (txn_guid, book);
+        if (txn)
+        {
+            LEAVE("txt = %p", txn);
+            return txn;
+        }
+    }
 
-   LEAVE("txn = (null");
-   return NULL;
+    LEAVE("txn = (null");
+    return NULL;
 }
 
 Split *
 pgendSplitLookup (PGBackend *be, const GUID *split_guid)
 {
-   GList *node;
-   Split * split = NULL;
+    GList *node;
+    Split * split = NULL;
 
-   ENTER("guid = %s", guid_to_string(split_guid));
-   for (node=be->blist; node; node=node->next)
-   {
-      QofBook *book = node->data;
-      split = xaccSplitLookup (split_guid, book);
-      if (split) { LEAVE("split = %p", split); return split; }
-   }
+    ENTER("guid = %s", guid_to_string(split_guid));
+    for (node = be->blist; node; node = node->next)
+    {
+        QofBook *book = node->data;
+        split = xaccSplitLookup (split_guid, book);
+        if (split)
+        {
+            LEAVE("split = %p", split);
+            return split;
+        }
+    }
 
-   LEAVE("split = (null)");
-   return NULL;
+    LEAVE("split = (null)");
+    return NULL;
 }
 
-struct _iter {
-  const GUID *guid;
-  QofInstance *ent;
+struct _iter
+{
+    const GUID *guid;
+    QofInstance *ent;
 };
 
 static void
 cforeach (QofCollection *col, gpointer data)
 {
-  struct _iter *iter = data;
-  if (iter->ent) return;
-  iter->ent = qof_collection_lookup_entity (col, iter->guid);
+    struct _iter *iter = data;
+    if (iter->ent) return;
+    iter->ent = qof_collection_lookup_entity (col, iter->guid);
 }
 
 QofIdType
 pgendGUIDType (PGBackend *be, const GUID *guid)
 {
-   GList *node;
-   struct _iter iter;
+    GList *node;
+    struct _iter iter;
 
-   iter.guid = guid;
-   iter.ent = NULL;
+    iter.guid = guid;
+    iter.ent = NULL;
 
-   ENTER("guid = %s", guid_to_string(guid));
-   for (node=be->blist; node; node=node->next)
-   {
-      QofBook *book = node->data;
-      qof_book_foreach_collection (book, cforeach, &iter);
-      if (iter.ent) 
-      { 
-         LEAVE("tip = %s", iter.ent->e_type); 
-         return iter.ent->e_type; 
-      }
-   }
+    ENTER("guid = %s", guid_to_string(guid));
+    for (node = be->blist; node; node = node->next)
+    {
+        QofBook *book = node->data;
+        qof_book_foreach_collection (book, cforeach, &iter);
+        if (iter.ent)
+        {
+            LEAVE("tip = %s", iter.ent->e_type);
+            return iter.ent->e_type;
+        }
+    }
 
-   LEAVE("tip = NULL");
-   return GNC_ID_NONE;
+    LEAVE("tip = NULL");
+    return GNC_ID_NONE;
 }
 
 /* ============================================================= */
 
 QofBook *
-pgendGetBook(PGBackend *pbe) {
+pgendGetBook(PGBackend *pbe)
+{
     QofBook *book;
-    
+
     ENTER(" ");
     book = qof_session_get_book(pbe->session);
 
@@ -233,18 +247,18 @@
     return book;
 }
 
-static void 
+static void
 pgend_set_book (PGBackend *be, QofBook *book)
 {
-   GList *node;
-   be->book = book;
+    GList *node;
+    be->book = book;
 
-   for (node=be->blist; node; node=node->next)
-   {
-      if (book == node->data) return;
-   }
+    for (node = be->blist; node; node = node->next)
+    {
+        if (book == node->data) return;
+    }
 
-   be->blist = g_list_prepend (be->blist, book);
+    be->blist = g_list_prepend (be->blist, book);
 }
 
 /* ============================================================= */
@@ -255,61 +269,63 @@
 gnc_commodity *
 gnc_string_to_commodity (const char *str, QofBook *book)
 {
-   gnc_commodity_table *comtab;
-   gnc_commodity *com;
-   char *space, *name;
+    gnc_commodity_table *comtab;
+    gnc_commodity *com;
+    char *space, *name;
 
-   comtab = gnc_book_get_commodity_table (book);
+    comtab = gnc_book_get_commodity_table (book);
 
-   space = g_strdup(str);
-   name = strchr (space, ':'); /* BUG */
+    space = g_strdup(str);
+    name = strchr (space, ':'); /* BUG */
 
-   if (!name)
-   {
-     PERR ("bad commodity string: %s", str ? str : "(null)");
-     g_free (space);
-     return NULL;
-   }
+    if (!name)
+    {
+        PERR ("bad commodity string: %s", str ? str : "(null)");
+        g_free (space);
+        return NULL;
+    }
 
-   *name = 0;
-   name += 2;
+    *name = 0;
+    name += 2;
 
-   com = gnc_commodity_table_lookup(comtab, space, name);
-   g_free (space);
-   return com;
+    com = gnc_commodity_table_lookup(comtab, space, name);
+    g_free (space);
+    return com;
 }
 
 /* ============================================================= */
 /* send the query, process the results */
 
 gpointer
-pgendGetResults (PGBackend *be, 
-             gpointer (*handler) (PGBackend *, PGresult *, int, gpointer),
-             gpointer data)
-{   
-   PGresult *result;
-   int i=0;
-   be->nrows=0;
-   do {
-      GET_RESULTS (be->connection, result);
-      {
-         int j, jrows;
-         int ncols = PQnfields (result);
-         jrows = PQntuples (result);
-         be->nrows += jrows;
-         PINFO ("query result %d has %d rows and %d cols",
-            i, jrows, ncols);
+pgendGetResults (PGBackend *be,
+                 gpointer (*handler) (PGBackend *, PGresult *, int, gpointer),
+                 gpointer data)
+{
+    PGresult *result;
+    int i = 0;
+    be->nrows = 0;
+    do
+    {
+        GET_RESULTS (be->connection, result);
+        {
+            int j, jrows;
+            int ncols = PQnfields (result);
+            jrows = PQntuples (result);
+            be->nrows += jrows;
+            PINFO ("query result %d has %d rows and %d cols",
+                   i, jrows, ncols);
 
-         for (j=0; j<jrows; j++)
-         {
-            data = handler (be, result, j, data);
-         }
-      }
-      i++;
-      PQclear (result);
-   } while (result);
+            for (j = 0; j < jrows; j++)
+            {
+                data = handler (be, result, j, data);
+            }
+        }
+        i++;
+        PQclear (result);
+    }
+    while (result);
 
-   return data;
+    return data;
 }
 
 /* ============================================================= */
@@ -318,10 +334,10 @@
 static gpointer
 get_version_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   int version = atoi(DB_GET_VAL ("version", j));
-   int incoming = GPOINTER_TO_INT (data);
-   if (version < incoming) version = incoming;
-   return GINT_TO_POINTER (version);
+    int version = atoi(DB_GET_VAL ("version", j));
+    int incoming = GPOINTER_TO_INT (data);
+    if (version < incoming) version = incoming;
+    return GINT_TO_POINTER (version);
 }
 
 /* ============================================================= */
@@ -330,41 +346,41 @@
 #include "base-autogen.h"
 #include "base-autogen.c"
 
-static const char *table_audit_str = 
+static const char *table_audit_str =
 #include "table-audit.c"
-;
+    ;
 
-static const char *table_create_str = 
+static const char *table_create_str =
 #include "table-create.c"
-;
+    ;
 
-static const char *table_version_str = 
+static const char *table_version_str =
 #include "table-version.c"
-;
+    ;
 
-static const char *sql_functions_str = 
+static const char *sql_functions_str =
 #include "functions.c"
-;
+    ;
 
 #if 0
-static const char *table_drop_str = 
+static const char *table_drop_str =
 #include "table-drop.c"
-;
+    ;
 #endif
 
 /* ============================================================= */
 /*             QUERY STUFF                                       */
 /* ============================================================= */
-/* The pgendRunQuery() routine performs a search on the SQL database for 
- * all of the splits that correspond to gnc-style query, and then 
+/* The pgendRunQuery() routine performs a search on the SQL database for
+ * all of the splits that correspond to gnc-style query, and then
  * integrates them into the engine cache.  It then performs a 'closure'
  * in order to maintain accurate balances.  Warning: this routine
  * is a bit of a pig, and should be replaced with a better algorithm.
  * See below.
- * 
+ *
  * The problem that this routine is trying to solve is the need to
  * to run a query *and* maintain consistent balance checkpoints
- * within the engine data. As a by-product, it can pull in a vast 
+ * within the engine data. As a by-product, it can pull in a vast
  * amount of sql data into the engine.  The steps of the algorithm
  * are:
  *
@@ -378,9 +394,9 @@
  * 7) go to step 3) until a consistent set of transactions
  *    has been pulled into the engine.
  *
- * Note regarding step 4): 
- * We only ever pull complete transactions out of the engine, 
- * and never dangling splits. This helps make sure that the 
+ * Note regarding step 4):
+ * We only ever pull complete transactions out of the engine,
+ * and never dangling splits. This helps make sure that the
  * splits always balance in a transaction; it also allows the
  * ledger to operate in 'journal' mode.
  *
@@ -391,315 +407,326 @@
  *
  * The process may pull in a huge amount of data.
  *
- * Oops: mega-bug: if the checkpoints on all accounts don't share 
+ * Oops: mega-bug: if the checkpoints on all accounts don't share
  * a common set of dates, then the above process will 'walk' until
- * the start of time, essentially pulling *all* data, and not that 
+ * the start of time, essentially pulling *all* data, and not that
  * efficiently, either.  This is a killer bug with this implementation.
  * We can work around it by fixing checkpoints in time ...
  *
  * There are certainly alternate possible implementations.  In one
- * alternate, 'better' implementation, we don't fill out to to the 
+ * alternate, 'better' implementation, we don't fill out to to the
  * checkpoint for all accounts, but only for the one being displayed.
- * However, doing so would require considerable jiggering in the 
- * engine proper, where we'd have to significantly modify 
- * RecomputeBalance() to do the 'right thing' when it has access to 
- * only some of the splits.   Yow.  Wait til after gnucash-1.6 for 
+ * However, doing so would require considerable jiggering in the
+ * engine proper, where we'd have to significantly modify
+ * RecomputeBalance() to do the 'right thing' when it has access to
+ * only some of the splits.   Yow.  Wait til after gnucash-1.6 for
  * this tear-up.
  */
 
 typedef struct
 {
-  Transaction * trans;
-  char * commodity_string;
+    Transaction * trans;
+    char * commodity_string;
 } TransResolveInfo;
 
 typedef struct
 {
-  GList * xaction_list;
-  GList * resolve_list;
+    GList * xaction_list;
+    GList * resolve_list;
 } QueryData;
 
 static gpointer
 query_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   QueryData *qd = data;
-   GUID trans_guid;
-   Transaction *trans;
-   gnc_commodity *currency;
-   Timespec ts;
+    QueryData *qd = data;
+    GUID trans_guid;
+    Transaction *trans;
+    gnc_commodity *currency;
+    Timespec ts;
 
-   /* find the transaction this goes into */
-   trans_guid = nullguid;  /* just in case the read fails ... */
-   string_to_guid (DB_GET_VAL("transGUID",j), &trans_guid);
+    /* find the transaction this goes into */
+    trans_guid = nullguid;  /* just in case the read fails ... */
+    string_to_guid (DB_GET_VAL("transGUID", j), &trans_guid);
 
-   /* use markers to avoid redundant traversals of transactions we've
-    * already checked recently. */
-   trans = pgendTransLookup (be, &trans_guid);
-   if (NULL != trans)
-   {
-      if (0 != trans->marker)
-      {
-         return qd;
-      }
-      else
-      {
-         gint32 db_version, cache_version;
-         db_version = atoi (DB_GET_VAL("version",j));
-         cache_version = qof_instance_get_version (trans);
-         if (db_version <= cache_version) {
+    /* use markers to avoid redundant traversals of transactions we've
+     * already checked recently. */
+    trans = pgendTransLookup (be, &trans_guid);
+    if (NULL != trans)
+    {
+        if (0 != trans->marker)
+        {
             return qd;
-         }
-         xaccTransBeginEdit (trans);
-      }
-   }
-   else
-   {
-      trans = xaccMallocTransaction(pgendGetBook(be));
-      xaccTransBeginEdit (trans);
-      xaccTransSetGUID (trans, &trans_guid);
-   }
+        }
+        else
+        {
+            gint32 db_version, cache_version;
+            db_version = atoi (DB_GET_VAL("version", j));
+            cache_version = qof_instance_get_version (trans);
+            if (db_version <= cache_version)
+            {
+                return qd;
+            }
+            xaccTransBeginEdit (trans);
+        }
+    }
+    else
+    {
+        trans = xaccMallocTransaction(pgendGetBook(be));
+        xaccTransBeginEdit (trans);
+        xaccTransSetGUID (trans, &trans_guid);
+    }
 
-   xaccTransSetNum (trans, DB_GET_VAL("num",j));
-   xaccTransSetDescription (trans, DB_GET_VAL("description",j));
-   ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted",j));
-   xaccTransSetDatePostedTS (trans, &ts);
-   ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_entered",j));
-   xaccTransSetDateEnteredTS (trans, &ts);
-   qof_instance_set_version (trans, atoi(DB_GET_VAL("version",j)));
-   qof_instance_set_idata(trans, atoi(DB_GET_VAL("iguid",j)));
+    xaccTransSetNum (trans, DB_GET_VAL("num", j));
+    xaccTransSetDescription (trans, DB_GET_VAL("description", j));
+    ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted", j));
+    xaccTransSetDatePostedTS (trans, &ts);
+    ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_entered", j));
+    xaccTransSetDateEnteredTS (trans, &ts);
+    qof_instance_set_version (trans, atoi(DB_GET_VAL("version", j)));
+    qof_instance_set_idata(trans, atoi(DB_GET_VAL("iguid", j)));
 
-   currency = gnc_string_to_commodity (DB_GET_VAL("currency",j), 
-                                       pgendGetBook(be));
-   if (currency)
-     xaccTransSetCurrency (trans, currency);
-   else
-   {
-     TransResolveInfo * ri = g_new0 (TransResolveInfo, 1);
+    currency = gnc_string_to_commodity (DB_GET_VAL("currency", j),
+                                        pgendGetBook(be));
+    if (currency)
+        xaccTransSetCurrency (trans, currency);
+    else
+    {
+        TransResolveInfo * ri = g_new0 (TransResolveInfo, 1);
 
-     ri->trans = trans;
-     ri->commodity_string = g_strdup (DB_GET_VAL("currency",j));
+        ri->trans = trans;
+        ri->commodity_string = g_strdup (DB_GET_VAL("currency", j));
 
-     qd->resolve_list = g_list_prepend (qd->resolve_list, ri);
-   }
+        qd->resolve_list = g_list_prepend (qd->resolve_list, ri);
+    }
 
-   trans->marker = 1;
-   qd->xaction_list = g_list_prepend (qd->xaction_list, trans);
+    trans->marker = 1;
+    qd->xaction_list = g_list_prepend (qd->xaction_list, trans);
 
-   return qd;
+    return qd;
 }
 
 typedef struct acct_earliest
 {
-   Account *acct;
-   Timespec ts;
+    Account *acct;
+    Timespec ts;
 } AcctEarliest;
 
 static int ncalls = 0;
 
-static void 
+static void
 pgendFillOutToCheckpoint (PGBackend *be, const char *query_string)
 {
-   int call_count = ncalls;
-   int nact=0;
-   QueryData qd;
-   GList *node, *anode, *acct_list = NULL;
+    int call_count = ncalls;
+    int nact = 0;
+    QueryData qd;
+    GList *node, *anode, *acct_list = NULL;
 
-   qd.xaction_list = NULL;
-   qd.resolve_list = NULL;
+    qd.xaction_list = NULL;
+    qd.resolve_list = NULL;
 
-   ENTER (" ");
-   if (!be) { LEAVE(""); return; }
+    ENTER (" ");
+    if (!be)
+    {
+        LEAVE("");
+        return;
+    }
 
-   if (0 == ncalls) {
-      START_CLOCK (9, "starting at level 0");
-   } 
-   else 
-   {
-      REPORT_CLOCK (9, "call count %d", call_count);
-   }
-   ncalls ++;
+    if (0 == ncalls)
+    {
+        START_CLOCK (9, "starting at level 0");
+    }
+    else
+    {
+        REPORT_CLOCK (9, "call count %d", call_count);
+    }
+    ncalls ++;
 
-   SEND_QUERY (be, query_string, );
-   pgendGetResults (be, query_cb, &qd);
-   REPORT_CLOCK (9, "fetched results at call %d", call_count);
+    SEND_QUERY (be, query_string, );
+    pgendGetResults (be, query_cb, &qd);
+    REPORT_CLOCK (9, "fetched results at call %d", call_count);
 
-   for (node = qd.resolve_list; node; node = node->next)
-   {
-     TransResolveInfo * ri = node->data;
-     gnc_commodity * commodity;
+    for (node = qd.resolve_list; node; node = node->next)
+    {
+        TransResolveInfo * ri = node->data;
+        gnc_commodity * commodity;
 
-     pgendGetCommodity (be, ri->commodity_string);
-     commodity = gnc_string_to_commodity (ri->commodity_string,
-                                          pgendGetBook(be));
+        pgendGetCommodity (be, ri->commodity_string);
+        commodity = gnc_string_to_commodity (ri->commodity_string,
+                                             pgendGetBook(be));
 
-     if (commodity)
-     {
-       xaccTransSetCurrency (ri->trans, commodity);
-     }
-     else
-     {
-       PERR ("Can't find commodity %s", ri->commodity_string);
-     }
+        if (commodity)
+        {
+            xaccTransSetCurrency (ri->trans, commodity);
+        }
+        else
+        {
+            PERR ("Can't find commodity %s", ri->commodity_string);
+        }
 
-     g_free (ri->commodity_string);
-     ri->commodity_string = NULL;
+        g_free (ri->commodity_string);
+        ri->commodity_string = NULL;
 
-     g_free (ri);
-     node->data = NULL;
-   }
-   g_list_free (qd.resolve_list);
-   qd.resolve_list = NULL;
+        g_free (ri);
+        node->data = NULL;
+    }
+    g_list_free (qd.resolve_list);
+    qd.resolve_list = NULL;
 
-   /* restore the splits for these transactions */
-   for (node = qd.xaction_list; node; node = node->next)
-   {
-      Transaction *trans = (Transaction *) node->data;
+    /* restore the splits for these transactions */
+    for (node = qd.xaction_list; node; node = node->next)
+    {
+        Transaction *trans = (Transaction *) node->data;
 
-      pgendCopySplitsToEngine (be, trans);
-   }
+        pgendCopySplitsToEngine (be, trans);
+    }
 
-   /* restore any kvp data associated with the transaction and splits */
-   for (node = qd.xaction_list; node; node = node->next)
-   {
-      Transaction *trans = (Transaction *) node->data;
-      GList *engine_splits, *snode;
+    /* restore any kvp data associated with the transaction and splits */
+    for (node = qd.xaction_list; node; node = node->next)
+    {
+        Transaction *trans = (Transaction *) node->data;
+        GList *engine_splits, *snode;
 
-      trans->inst.kvp_data = pgendKVPFetch(be, qof_instance_get_idata(trans),
-                                           trans->inst.kvp_data);
-   
-      engine_splits = xaccTransGetSplitList(trans);
-      for (snode = engine_splits; snode; snode=snode->next)
-      {
-         Split *s = snode->data;
-         s->inst.kvp_data = pgendKVPFetch(be, qof_instance_get_idata(s),
-                                          s->inst.kvp_data);
-      }
+        trans->inst.kvp_data = pgendKVPFetch(be, qof_instance_get_idata(trans),
+                                             trans->inst.kvp_data);
 
-      xaccTransCommitEdit (trans);
-   }
+        engine_splits = xaccTransGetSplitList(trans);
+        for (snode = engine_splits; snode; snode = snode->next)
+        {
+            Split *s = snode->data;
+            s->inst.kvp_data = pgendKVPFetch(be, qof_instance_get_idata(s),
+                                             s->inst.kvp_data);
+        }
 
-   /* run the fill-out algorithm */
-   for (node = qd.xaction_list; node; node = node->next)
-   {
-      Transaction *trans = (Transaction *) node->data;
-      GList *split_list, *snode;
-      Timespec ts;
+        xaccTransCommitEdit (trans);
+    }
 
-      ts = xaccTransRetDatePostedTS (trans);
+    /* run the fill-out algorithm */
+    for (node = qd.xaction_list; node; node = node->next)
+    {
+        Transaction *trans = (Transaction *) node->data;
+        GList *split_list, *snode;
+        Timespec ts;
 
-      /* Back off by a second to disambiguate time.
-       * This is safe, because the fill-out will recurse
-       * if something got into this one-second gap. */
-      ts.tv_sec --; 
-      split_list = xaccTransGetSplitList (trans);
-      for (snode=split_list; snode; snode=snode->next)
-      {
-         int found = 0;
-         Split *s = (Split *) snode->data;
-         Account *acc = xaccSplitGetAccount (s);
-         GList *splits;
+        ts = xaccTransRetDatePostedTS (trans);
 
-         /* make sure the earliest split is first */
-         xaccAccountSortSplits (acc, TRUE);
+        /* Back off by a second to disambiguate time.
+         * This is safe, because the fill-out will recurse
+         * if something got into this one-second gap. */
+        ts.tv_sec --;
+        split_list = xaccTransGetSplitList (trans);
+        for (snode = split_list; snode; snode = snode->next)
+        {
+            int found = 0;
+            Split *s = (Split *) snode->data;
+            Account *acc = xaccSplitGetAccount (s);
+            GList *splits;
 
-         splits = xaccAccountGetSplitList (acc);
+            /* make sure the earliest split is first */
+            xaccAccountSortSplits (acc, TRUE);
 
-         /* See if we already have a split (acc_split)
-          * earlier than this transaction. Then either:
-          *
-          *   1) The acc_split was pulled in by the same
-          *      query which brought in the current split
-          *      and we will get to acc_split later.
-          *   2) The acc_split was loaded already and
-          *      the account starting balance is correct
-          *      up to that point.
-          *
-          * Either way, we can ignore the current split
-          * for the purposes of checkpointing.
-          */
-         if (splits)
-         {
-           Split *acc_split = splits->data;
-           Transaction *t = xaccSplitGetParent (acc_split);
-           Timespec ts_2 = xaccTransRetDatePostedTS (t);
+            splits = xaccAccountGetSplitList (acc);
 
-           if (timespec_cmp (&ts_2, &ts) < 0)
-             continue;
-         }
+            /* See if we already have a split (acc_split)
+             * earlier than this transaction. Then either:
+             *
+             *   1) The acc_split was pulled in by the same
+             *      query which brought in the current split
+             *      and we will get to acc_split later.
+             *   2) The acc_split was loaded already and
+             *      the account starting balance is correct
+             *      up to that point.
+             *
+             * Either way, we can ignore the current split
+             * for the purposes of checkpointing.
+             */
+            if (splits)
+            {
+                Split *acc_split = splits->data;
+                Transaction *t = xaccSplitGetParent (acc_split);
+                Timespec ts_2 = xaccTransRetDatePostedTS (t);
 
-         /* lets see if we have a record of this account already */
-         for (anode = acct_list; anode; anode = anode->next)
-         {
-            AcctEarliest * ae = (AcctEarliest *) anode->data;
-            if (ae->acct == acc) 
+                if (timespec_cmp (&ts_2, &ts) < 0)
+                    continue;
+            }
+
+            /* lets see if we have a record of this account already */
+            for (anode = acct_list; anode; anode = anode->next)
             {
-               if (0 > timespec_cmp(&ts, &(ae->ts)))
-               {
-                  ae->ts = ts;
-               }
-               found = 1;
-               break;
+                AcctEarliest * ae = (AcctEarliest *) anode->data;
+                if (ae->acct == acc)
+                {
+                    if (0 > timespec_cmp(&ts, &(ae->ts)))
+                    {
+                        ae->ts = ts;
+                    }
+                    found = 1;
+                    break;
+                }
             }
-         }
 
-         /* if not found, make note of this account, and the date */
-         if (0 == found)
-         {
-            AcctEarliest * ae = g_new (AcctEarliest, 1);
-            ae->acct = acc;
-            ae->ts = ts;
-            acct_list = g_list_prepend (acct_list, ae);
-         }
-      }
-   }
-   g_list_free (qd.xaction_list);
-   qd.xaction_list = NULL;
+            /* if not found, make note of this account, and the date */
+            if (0 == found)
+            {
+                AcctEarliest * ae = g_new (AcctEarliest, 1);
+                ae->acct = acc;
+                ae->ts = ts;
+                acct_list = g_list_prepend (acct_list, ae);
+            }
+        }
+    }
+    g_list_free (qd.xaction_list);
+    qd.xaction_list = NULL;
 
-   REPORT_CLOCK (9, "done gathering at call %d", call_count);
-   if (NULL == acct_list) { LEAVE(""); return; }
+    REPORT_CLOCK (9, "done gathering at call %d", call_count);
+    if (NULL == acct_list)
+    {
+        LEAVE("");
+        return;
+    }
 
-   /* OK, at this point, we have a list of accounts, including the 
-    * date of the earliest split in that account.  Now, we need to 
-    * do two queries: first, get the running balances to that point,
-    * and then all of the splits from that date onwards.
-    */
-   nact = 0;
-   for (anode = acct_list; anode; anode = anode->next)
-   {
-      char *p;
-      AcctEarliest * ae = (AcctEarliest *) anode->data;
-      pgendAccountGetBalance (be, ae->acct, ae->ts);
+    /* OK, at this point, we have a list of accounts, including the
+     * date of the earliest split in that account.  Now, we need to
+     * do two queries: first, get the running balances to that point,
+     * and then all of the splits from that date onwards.
+     */
+    nact = 0;
+    for (anode = acct_list; anode; anode = anode->next)
+    {
+        char *p;
+        AcctEarliest * ae = (AcctEarliest *) anode->data;
+        pgendAccountGetBalance (be, ae->acct, ae->ts);
 
-      /* n.b. date_posted compare must be strictly greater than, since the 
-       * GetBalance goes to less-then-or-equal-to because of the BETWEEN
-       * that appears in the gncSubTotalBalance sql function. */
-      p = be->buff; *p = 0;
-      p = stpcpy (p,
-                  "SELECT DISTINCT gncTransaction.* "
-                  "FROM gncSplit, gncTransaction WHERE "
-                  "gncSplit.transGuid = gncTransaction.transGuid AND "
-                  "gncSplit.accountGuid='");
-      p = guid_to_string_buff(xaccAccountGetGUID(ae->acct), p);
-      p = stpcpy (p, "' AND gncTransaction.date_posted > '");
-      p = gnc_timespec_to_iso8601_buff (ae->ts, p);
-      p = stpcpy (p, "';");
+        /* n.b. date_posted compare must be strictly greater than, since the
+         * GetBalance goes to less-then-or-equal-to because of the BETWEEN
+         * that appears in the gncSubTotalBalance sql function. */
+        p = be->buff;
+        *p = 0;
+        p = stpcpy (p,
+                    "SELECT DISTINCT gncTransaction.* "
+                    "FROM gncSplit, gncTransaction WHERE "
+                    "gncSplit.transGuid = gncTransaction.transGuid AND "
+                    "gncSplit.accountGuid='");
+        p = guid_to_string_buff(xaccAccountGetGUID(ae->acct), p);
+        p = stpcpy (p, "' AND gncTransaction.date_posted > '");
+        p = gnc_timespec_to_iso8601_buff (ae->ts, p);
+        p = stpcpy (p, "';");
 
-      pgendFillOutToCheckpoint (be, be->buff);
+        pgendFillOutToCheckpoint (be, be->buff);
 
-      g_free (ae);
-      nact ++;
-   }
-   g_list_free(acct_list);
+        g_free (ae);
+        nact ++;
+    }
+    g_list_free(acct_list);
 
-   REPORT_CLOCK (9, "done w/ fillout at call %d, handled %d accounts",
-                 call_count, nact);
-   LEAVE (" ");
+    REPORT_CLOCK (9, "done w/ fillout at call %d, handled %d accounts",
+                  call_count, nact);
+    LEAVE (" ");
 }
 
 static gpointer
 pgendCompileQuery (QofBackend *bend, Query *q)
 {
-  return q;
+    return q;
 }
 
 static void
@@ -707,65 +734,69 @@
 {
 }
 
-static void 
+static void
 pgendRunQuery (QofBackend *bend, gpointer q_p)
 {
-   PGBackend *be = (PGBackend *)bend;
-   Query *q = (Query*) q_p;
-   const char * sql_query_string;
-   Account *root;
-   sqlQuery *sq;
+    PGBackend *be = (PGBackend *)bend;
+    Query *q = (Query*) q_p;
+    const char * sql_query_string;
+    Account *root;
+    sqlQuery *sq;
 
-   ENTER ("be=%p, qry=%p", be, q);
-   if (!be || !q) { LEAVE("(null) args"); return; }
-   be->version_check = (guint32) time(0);
+    ENTER ("be=%p, qry=%p", be, q);
+    if (!be || !q)
+    {
+        LEAVE("(null) args");
+        return;
+    }
+    be->version_check = (guint32) time(0);
 
-   qof_event_suspend();
-   pgendDisable(be);
+    qof_event_suspend();
+    pgendDisable(be);
 
-   /* first thing we do is convert the gnc-engine query into
-    * an sql string. */
-   sq = sqlQuery_new();
-   sql_query_string = sqlQuery_build (sq, q);
+    /* first thing we do is convert the gnc-engine query into
+     * an sql string. */
+    sq = sqlQuery_new();
+    sql_query_string = sqlQuery_build (sq, q);
 
-   root = gnc_book_get_root_account(pgendGetBook(be));
+    root = gnc_book_get_root_account(pgendGetBook(be));
 
-   /* stage transactions, save some postgres overhead */
-   gnc_account_tree_begin_staged_transaction_traversals (root);
+    /* stage transactions, save some postgres overhead */
+    gnc_account_tree_begin_staged_transaction_traversals (root);
 
-   /* We will be doing a bulk insertion of transactions below.
-    * We can gain a tremendous performance improvement,
-    * for example, a factor of 10x when querying 3000 transactions,
-    * by opening all accounts for editing before we start, and
-    * closing them all only after we're done.  This is because
-    * an account must be open for editing in order to insert a split, 
-    * and when the commit is made, the splits are sorted in date order. 
-    * If we're sloppy, then there's an ordering for every insertion.
-    * By defering the Commit, we defer the sort, and thus save gobs.
-    * Of course, this hurts 'shallow' queries some, but I beleive 
-    * by not very much.
-    */
-   ncalls = 0;
-   xaccAccountBeginEdit(root);
-   pgendFillOutToCheckpoint (be, sql_query_string);
-   xaccAccountCommitEdit(root);
-   PINFO ("number of calls to fill out=%d", ncalls);
+    /* We will be doing a bulk insertion of transactions below.
+     * We can gain a tremendous performance improvement,
+     * for example, a factor of 10x when querying 3000 transactions,
+     * by opening all accounts for editing before we start, and
+     * closing them all only after we're done.  This is because
+     * an account must be open for editing in order to insert a split,
+     * and when the commit is made, the splits are sorted in date order.
+     * If we're sloppy, then there's an ordering for every insertion.
+     * By defering the Commit, we defer the sort, and thus save gobs.
+     * Of course, this hurts 'shallow' queries some, but I beleive
+     * by not very much.
+     */
+    ncalls = 0;
+    xaccAccountBeginEdit(root);
+    pgendFillOutToCheckpoint (be, sql_query_string);
+    xaccAccountCommitEdit(root);
+    PINFO ("number of calls to fill out=%d", ncalls);
 
-   sql_Query_destroy(sq);
+    sql_Query_destroy(sq);
 
-   pgendEnable(be);
-   qof_event_resume();
+    pgendEnable(be);
+    qof_event_resume();
 
-   LEAVE (" ");
+    LEAVE (" ");
 }
 
 
 /* ============================================================= */
-/* The pgendGetAllTransactions() routine sucks *all* of the 
- *    transactions out of the database.  This is a potential 
+/* The pgendGetAllTransactions() routine sucks *all* of the
+ *    transactions out of the database.  This is a potential
  *    CPU and memory-burner; its use is not suggested for anything
  *    but single-user mode.
- * 
+ *
  *    NB. This routine has been obsoleted by the more efficient
  *    pgendGetMassTransactions().  We keep it around here ...
  *    for a rainy day...
@@ -775,42 +806,42 @@
 static gpointer
 get_all_trans_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   GList *xaction_list = (GList *) data;
-   GUID *trans_guid;
+    GList *xaction_list = (GList *) data;
+    GUID *trans_guid;
 
-   /* find the transaction this goes into */
-   trans_guid = guid_malloc();
-   *trans_guid = nullguid;  /* just in case the read fails ... */
-   string_to_guid (DB_GET_VAL("transGUID",j), trans_guid);
+    /* find the transaction this goes into */
+    trans_guid = guid_malloc();
+    *trans_guid = nullguid;  /* just in case the read fails ... */
+    string_to_guid (DB_GET_VAL("transGUID", j), trans_guid);
 
-   xaction_list = g_list_prepend (xaction_list, trans_guid);
-   return xaction_list;
+    xaction_list = g_list_prepend (xaction_list, trans_guid);
+    return xaction_list;
 }
 
 
 static void
 pgendGetAllTransactions (PGBackend *be, Account *root)
 {
-   GList *node, *xaction_list = NULL;
+    GList *node, *xaction_list = NULL;
 
-   qof_event_suspend();
-   pgendDisable(be);
+    qof_event_suspend();
+    pgendDisable(be);
 
-   SEND_QUERY (be, "SELECT transGuid FROM gncTransaction;", );
-   xaction_list = pgendGetResults (be, get_all_trans_cb, xaction_list);
+    SEND_QUERY (be, "SELECT transGuid FROM gncTransaction;", );
+    xaction_list = pgendGetResults (be, get_all_trans_cb, xaction_list);
 
-   /* restore the transactions */
-   xaccAccountBeginEdit (root);
-   for (node=xaction_list; node; node=node->next)
-   {
-      xxxpgendCopyTransactionToEngine (be, (GUID *)node->data);
-      guid_free (node->data);
-   }
-   g_list_free(xaction_list);
-   xaccAccountCommitEdit (root);
+    /* restore the transactions */
+    xaccAccountBeginEdit (root);
+    for (node = xaction_list; node; node = node->next)
+    {
+        xxxpgendCopyTransactionToEngine (be, (GUID *)node->data);
+        guid_free (node->data);
+    }
+    g_list_free(xaction_list);
+    xaccAccountCommitEdit (root);
 
-   pgendEnable(be);
-   qof_event_resume();
+    pgendEnable(be);
+    qof_event_resume();
 }
 #endif
 
@@ -827,15 +858,15 @@
  * I can't vouch that there aren't any subtle issues or race conditions
  * lurking in this.  Anyway, with that introduction:
  *
- * The pgendSync() routine 'synchronizes' the accounts & commodities 
- * cached in the engine to those in the database.  It does this first 
- * by writing out all of the accounts and transactions, from the 
+ * The pgendSync() routine 'synchronizes' the accounts & commodities
+ * cached in the engine to those in the database.  It does this first
+ * by writing out all of the accounts and transactions, from the
  * top-group down, and then re-reading from the database.  This
  * write-then-read cycle has the effect of merging the engine data
  * into the sql database.  Note that version checking is done during
  * the writing: only accounts and transactions that are 'newer' in
  * the engine are written out.  Then during the read cycle, anything
- * in the DB that is newer than what's in the engine is sucked back 
+ * in the DB that is newer than what's in the engine is sucked back
  * into the engine.
  *
  * There are three scenarios to contemplate with the update with
@@ -843,7 +874,7 @@
  *
  * 1) Database merge:  the user has two substantialy similar copies
  *    of the same data; the first copy was read into the engine earlier,
- *    and now, in this routine, it is being written into the second. 
+ *    and now, in this routine, it is being written into the second.
  *    Because the merge uses version numbers, this merge should be
  *    'safe' in that only the newer copy of any account or transaction
  *    is merged.  But this 'safety' can break down, in certain cases;
@@ -866,73 +897,73 @@
 static void
 pgendSync (QofBackend *bend, QofBook *book)
 {
-   PGBackend *be = (PGBackend *)bend;
-   Account *root = gnc_book_get_root_account(book);
+    PGBackend *be = (PGBackend *)bend;
+    Account *root = gnc_book_get_root_account(book);
 
-   ENTER ("be=%p, root=%p", be, root);
+    ENTER ("be=%p, root=%p", be, root);
 
-   pgend_set_book (be, book);
-   be->version_check = (guint32) time(0);
+    pgend_set_book (be, book);
+    be->version_check = (guint32) time(0);
 
-   /* For the multi-user modes, we allow a save only once,
-    * when the database is created for the first time.
-    * Ditto for the single-user update mode: it should never
-    * wander out of sync.
-    */
-   if ((MODE_SINGLE_FILE != be->session_mode) &&
-       (FALSE == be->freshly_created_db))
-   {
-      LEAVE("no sync");
-      return;
-   }
-   be->freshly_created_db = FALSE;
+    /* For the multi-user modes, we allow a save only once,
+     * when the database is created for the first time.
+     * Ditto for the single-user update mode: it should never
+     * wander out of sync.
+     */
+    if ((MODE_SINGLE_FILE != be->session_mode) &&
+            (FALSE == be->freshly_created_db))
+    {
+        LEAVE("no sync");
+        return;
+    }
+    be->freshly_created_db = FALSE;
 
-   pgendStoreBook (be, book);
+    pgendStoreBook (be, book);
 
-   /* store the account group hierarchy, and then all transactions */
-   pgendStoreAccountTree (be, root);
-   pgendStoreAllTransactions (be, root);
+    /* store the account group hierarchy, and then all transactions */
+    pgendStoreAccountTree (be, root);
+    pgendStoreAllTransactions (be, root);
 
-   /* don't send events  to GUI, don't accept callbacks to backend */
-   qof_event_suspend();
-   pgendDisable(be);
+    /* don't send events  to GUI, don't accept callbacks to backend */
+    qof_event_suspend();
+    pgendDisable(be);
 
-   pgendKVPInit(be);
-   pgendGetAllAccountsInBook (be, book);
-   if ((MODE_SINGLE_FILE != be->session_mode) &&
-       (MODE_SINGLE_UPDATE != be->session_mode))
-   {
-      Timespec ts = gnc_iso8601_to_timespec_gmt (CK_BEFORE_LAST_DATE);
-      pgendAccountTreeGetAllBalances (be, root, ts);
-   } 
-   else
-   {
-      /* in single user mode, read all the transactions */
-      pgendGetMassTransactions (be, book);
-   }
+    pgendKVPInit(be);
+    pgendGetAllAccountsInBook (be, book);
+    if ((MODE_SINGLE_FILE != be->session_mode) &&
+            (MODE_SINGLE_UPDATE != be->session_mode))
+    {
+        Timespec ts = gnc_iso8601_to_timespec_gmt (CK_BEFORE_LAST_DATE);
+        pgendAccountTreeGetAllBalances (be, root, ts);
+    }
+    else
+    {
+        /* in single user mode, read all the transactions */
+        pgendGetMassTransactions (be, book);
+    }
 
-   /* hack alert -- In some deranged theory, we should be
-    * syncing prices here, as well as syncing any/all other
-    * engine structures that need to be stored.  But instead,
-    * price sync is handled as a separate routine ...
-    */
+    /* hack alert -- In some deranged theory, we should be
+     * syncing prices here, as well as syncing any/all other
+     * engine structures that need to be stored.  But instead,
+     * price sync is handled as a separate routine ...
+     */
 
-   /* re-enable events */
-   pgendEnable(be);
-   qof_event_resume();
+    /* re-enable events */
+    pgendEnable(be);
+    qof_event_resume();
 
-   LEAVE(" ");
+    LEAVE(" ");
 }
 
 /* ============================================================= */
 /* The pgendSyncSingleFile() routine syncs the engine and database.
  *    In single file mode, we treat 'sync' as 'file save'.
- *    We start by deleting *everything*, and then writing 
+ *    We start by deleting *everything*, and then writing
  *    everything out.  This is rather nasty, ugly and dangerous,
  *    but that's the nature of single-file mode.  Note: we
- *    have to delete everything because in this mode, there is 
- *    no other way of finding out that an account, transaction 
- *    or split was deleted. i.e. there's no other way to delete.  
+ *    have to delete everything because in this mode, there is
+ *    no other way of finding out that an account, transaction
+ *    or split was deleted. i.e. there's no other way to delete.
  *    So start with a clean slate.
  *
  *    The use of this routine/this mode is 'depricated'.
@@ -943,97 +974,97 @@
 static int
 trans_traverse_cb (Transaction *trans, void *cb_data)
 {
-   pgendStoreTransactionNoLock ((PGBackend *) cb_data, trans, TRUE);
-   return 0;
+    pgendStoreTransactionNoLock ((PGBackend *) cb_data, trans, TRUE);
+    return 0;
 }
 
 static void
 pgendSyncSingleFile (QofBackend *bend, QofBook *book)
 {
-   char book_guid[40];
-   char buff[4000];
-   char *p;
-   PGBackend *be = (PGBackend *)bend;
-   Account *root = gnc_book_get_root_account(book);
+    char book_guid[40];
+    char buff[4000];
+    char *p;
+    PGBackend *be = (PGBackend *)bend;
+    Account *root = gnc_book_get_root_account(book);
 
-   ENTER ("be=%p, root=%p", be, root);
+    ENTER ("be=%p, root=%p", be, root);
 
-   pgend_set_book (be, book);
+    pgend_set_book (be, book);
 
-   /* hack alert -- we shouldn't be doing a global delete, 
-    * we should only be deleting the stuff that's in this particular 
-    * book .... */
-   p = "BEGIN;\n"
-       "LOCK TABLE gncBook IN EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncAccount IN EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncCommodity IN EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncSplit IN EXCLUSIVE MODE;\n";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    /* hack alert -- we shouldn't be doing a global delete,
+     * we should only be deleting the stuff that's in this particular
+     * book .... */
+    p = "BEGIN;\n"
+        "LOCK TABLE gncBook IN EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncAccount IN EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncCommodity IN EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncSplit IN EXCLUSIVE MODE;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   guid_to_string_buff (qof_book_get_guid(book), book_guid);
+    guid_to_string_buff (qof_book_get_guid(book), book_guid);
 
-   /* First, we delete all of the accounts, splits and transactions
-    * associated with this book.  Its very tempting to just delete
-    * everything in the SQL db, but we note that there may be several 
-    * books stored here, and we want to delete only one book. 
-    */
-   /* do the one-book equivalent of "DELETE FROM gncTransaction;" */
-   p = buff;
-   p = stpcpy (p, "DELETE FROM gncTransaction WHERE "
-                  "  gncTransaction.transGuid = gncSplit.transGuid AND "
-                  "  gncSplit.accountGuid = gncAccount.accountGuid AND "
-                  "  gncAccount.bookGuid = '");
-   p = stpcpy (p, book_guid);
-   p = stpcpy (p, "';");
-   SEND_QUERY (be,buff, );
-   FINISH_QUERY(be->connection);
+    /* First, we delete all of the accounts, splits and transactions
+     * associated with this book.  Its very tempting to just delete
+     * everything in the SQL db, but we note that there may be several
+     * books stored here, and we want to delete only one book.
+     */
+    /* do the one-book equivalent of "DELETE FROM gncTransaction;" */
+    p = buff;
+    p = stpcpy (p, "DELETE FROM gncTransaction WHERE "
+                "  gncTransaction.transGuid = gncSplit.transGuid AND "
+                "  gncSplit.accountGuid = gncAccount.accountGuid AND "
+                "  gncAccount.bookGuid = '");
+    p = stpcpy (p, book_guid);
+    p = stpcpy (p, "';");
+    SEND_QUERY (be, buff, );
+    FINISH_QUERY(be->connection);
 
-   /* do the one-book equivalent of "DELETE FROM gncSplit;" */
-   p = buff;
-   p = stpcpy (p, "DELETE FROM gncSplit WHERE "
-                  "  gncSplit.accountGuid = gncAccount.accountGuid AND "
-                  "  gncAccount.bookGuid = '");
-   p = stpcpy (p, book_guid);
-   p = stpcpy (p, "';");
-   SEND_QUERY (be,buff, );
-   FINISH_QUERY(be->connection);
+    /* do the one-book equivalent of "DELETE FROM gncSplit;" */
+    p = buff;
+    p = stpcpy (p, "DELETE FROM gncSplit WHERE "
+                "  gncSplit.accountGuid = gncAccount.accountGuid AND "
+                "  gncAccount.bookGuid = '");
+    p = stpcpy (p, book_guid);
+    p = stpcpy (p, "';");
+    SEND_QUERY (be, buff, );
+    FINISH_QUERY(be->connection);
 
 
-   /* do the one-book equivalent of "DELETE FROM gncAccount;" */
-   p = buff;
-   p = stpcpy (p, "DELETE FROM gncAccount WHERE bookGuid='");
-   p = stpcpy (p, book_guid);
-   p = stpcpy (p, "';");
-   SEND_QUERY (be,buff, );
-   FINISH_QUERY(be->connection);
+    /* do the one-book equivalent of "DELETE FROM gncAccount;" */
+    p = buff;
+    p = stpcpy (p, "DELETE FROM gncAccount WHERE bookGuid='");
+    p = stpcpy (p, book_guid);
+    p = stpcpy (p, "';");
+    SEND_QUERY (be, buff, );
+    FINISH_QUERY(be->connection);
 
-   /* store the book struct */
-   pgendStoreBookNoLock (be, book, TRUE);
+    /* store the book struct */
+    pgendStoreBookNoLock (be, book, TRUE);
 
-   /* Store accounts and commodities */
-   xaccClearMarkDown (root, 0);
-   pgendStoreAccountTreeNoLock (be, root, TRUE, TRUE);
-   xaccClearMarkDown (root, 0);
+    /* Store accounts and commodities */
+    xaccClearMarkDown (root, 0);
+    pgendStoreAccountTreeNoLock (be, root, TRUE, TRUE);
+    xaccClearMarkDown (root, 0);
 
-   /* Recursively walk transactions. Start by reseting the write 
-    * flags. We use this to avoid infinite recursion */
-   gnc_account_tree_begin_staged_transaction_traversals(root);
-   gnc_account_tree_staged_transaction_traversal (root, 1, trans_traverse_cb, be);
+    /* Recursively walk transactions. Start by reseting the write
+     * flags. We use this to avoid infinite recursion */
+    gnc_account_tree_begin_staged_transaction_traversals(root);
+    gnc_account_tree_staged_transaction_traversal (root, 1, trans_traverse_cb, be);
 
-   /* hack alert -- In some deranged theory, we should be
-    * syncing prices here, as well as syncing any/all other
-    * engine structures that need to be stored.  But instead,
-    * price sync is handled as a separate routine ...
-    */
+    /* hack alert -- In some deranged theory, we should be
+     * syncing prices here, as well as syncing any/all other
+     * engine structures that need to be stored.  But instead,
+     * price sync is handled as a separate routine ...
+     */
 
 
-   p = "COMMIT;";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    p = "COMMIT;";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   LEAVE(" ");
+    LEAVE(" ");
 }
 
 /* ============================================================= */
@@ -1044,49 +1075,49 @@
 static void
 pgendSyncPriceDB (QofBackend *bend, QofBook *book)
 {
-   PGBackend *be = (PGBackend *)bend;
-   ENTER ("be=%p", be);
-   if (!be) return;
+    PGBackend *be = (PGBackend *)bend;
+    ENTER ("be=%p", be);
+    if (!be) return;
 
-   pgend_set_book (be, book);
-   be->version_check = (guint32) time(0);
+    pgend_set_book (be, book);
+    be->version_check = (guint32) time(0);
 
-   /* for the multi-user modes, we allow a save only once,
-    * when the database is created for the first time */
-   if ((MODE_SINGLE_FILE != be->session_mode) &&
-       (MODE_SINGLE_UPDATE != be->session_mode) &&
-       (FALSE == be->freshly_created_prdb))
-   {
-      LEAVE("no sync");
-      return;
-   }
-   be->freshly_created_prdb = FALSE;
+    /* for the multi-user modes, we allow a save only once,
+     * when the database is created for the first time */
+    if ((MODE_SINGLE_FILE != be->session_mode) &&
+            (MODE_SINGLE_UPDATE != be->session_mode) &&
+            (FALSE == be->freshly_created_prdb))
+    {
+        LEAVE("no sync");
+        return;
+    }
+    be->freshly_created_prdb = FALSE;
 
-   pgendStorePriceDB (be, book);
+    pgendStorePriceDB (be, book);
 
-   /* don't send events  to GUI, don't accept callbacks to backend */
-   qof_event_suspend();
-   pgendDisable(be);
+    /* don't send events  to GUI, don't accept callbacks to backend */
+    qof_event_suspend();
+    pgendDisable(be);
 
-   pgendGetAllPricesInBook (be, book);
+    pgendGetAllPricesInBook (be, book);
 
-   /* re-enable events */
-   pgendEnable(be);
-   qof_event_resume();
+    /* re-enable events */
+    pgendEnable(be);
+    qof_event_resume();
 
-   LEAVE(" ");
+    LEAVE(" ");
 }
 
 /* ============================================================= */
-/* The pgendSyncPriceSingleFile() routine syncs the prices in the 
+/* The pgendSyncPriceSingleFile() routine syncs the prices in the
  *    engine with the database.
  *    In single file mode, we treat 'sync' as 'file save'.
- *    We start by deleting *everything*, and then writing 
+ *    We start by deleting *everything*, and then writing
  *    everything out.  This is rather nasty, ugly and dangerous,
  *    but that's the nature of single-file mode.  Note: we
- *    have to delete everything because in this mode, there is 
- *    no other way of finding out that a price was deleted. 
- *    i.e. there's no other way to delete.  
+ *    have to delete everything because in this mode, there is
+ *    no other way of finding out that a price was deleted.
+ *    i.e. there's no other way to delete.
  *    So start with a clean slate.
  *
  *    The use of this routine/this mode is 'depricated'.
@@ -1097,29 +1128,29 @@
 static void
 pgendSyncPriceDBSingleFile (QofBackend *bend, QofBook *book)
 {
-   char buff[400], *p;
-   PGBackend *be = (PGBackend *)bend;
-   ENTER ("be=%p", be);
+    char buff[400], *p;
+    PGBackend *be = (PGBackend *)bend;
+    ENTER ("be=%p", be);
 
-   pgend_set_book (be, book);
-    
-   p = buff;
-   p = stpcpy (p, "BEGIN;\n"
-                  "LOCK TABLE gncPrice IN EXCLUSIVE MODE;\n"
-                  "DELETE FROM gncPrice WHERE bookGuid='\n");
-   p = guid_to_string_buff (qof_book_get_guid(book), p);
-   p = stpcpy (p, "';");
-   SEND_QUERY (be,buff, );
-   FINISH_QUERY(be->connection);
+    pgend_set_book (be, book);
 
-   /* Store accounts and commodities */
-   pgendStorePriceDBNoLock (be, book);
+    p = buff;
+    p = stpcpy (p, "BEGIN;\n"
+                "LOCK TABLE gncPrice IN EXCLUSIVE MODE;\n"
+                "DELETE FROM gncPrice WHERE bookGuid='\n");
+    p = guid_to_string_buff (qof_book_get_guid(book), p);
+    p = stpcpy (p, "';");
+    SEND_QUERY (be, buff, );
+    FINISH_QUERY(be->connection);
 
-   p = "COMMIT;";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    /* Store accounts and commodities */
+    pgendStorePriceDBNoLock (be, book);
 
-   LEAVE(" ");
+    p = "COMMIT;";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+
+    LEAVE(" ");
 }
 
 /* ============================================================= */
@@ -1127,21 +1158,21 @@
 static const char *
 pgendSessionGetMode (PGBackend *be)
 {
-   switch (be->session_mode)
-   {
-      case MODE_SINGLE_FILE:
-         return "SINGLE-FILE";
-      case MODE_SINGLE_UPDATE:
-         return "SINGLE-UPDATE";
-      case MODE_POLL:
-         return "POLL";
-      case MODE_EVENT:
-         return "EVENT";
-      /* quiet compiler warnings about MODE_NONE */
-      default:
-         return "ERROR";
-   }
-   return "ERROR";
+    switch (be->session_mode)
+    {
+    case MODE_SINGLE_FILE:
+        return "SINGLE-FILE";
+    case MODE_SINGLE_UPDATE:
+        return "SINGLE-UPDATE";
+    case MODE_POLL:
+        return "POLL";
+    case MODE_EVENT:
+        return "EVENT";
+        /* quiet compiler warnings about MODE_NONE */
+    default:
+        return "ERROR";
+    }
+    return "ERROR";
 }
 
 /* ============================================================= */
@@ -1150,15 +1181,15 @@
 static void
 pgend_book_load_single_lockerr (QofBackend *bend, QofBook *book)
 {
-   PGBackend *be = (PGBackend *)bend;
+    PGBackend *be = (PGBackend *)bend;
 
-   if (!be) return;
+    if (!be) return;
 
-   qof_backend_set_error (&be->be, ERR_BACKEND_LOCKED);
+    qof_backend_set_error (&be->be, ERR_BACKEND_LOCKED);
 }
 
 /* ============================================================= */
-/* The get_session_cb() routine can determine whether we can start 
+/* The get_session_cb() routine can determine whether we can start
  *    a session of the desired type.
  *    The logic used is as follows:
  *    -- if there is any (other) session at all, and we want single
@@ -1168,87 +1199,88 @@
  *    -- otherwise, suceed.
  *    Return TRUE if we can get a session.
  *
- *    This routine does not lock, but may be used inside a 
+ *    This routine does not lock, but may be used inside a
  *    test-n-set atomic operation.
  */
 
 static gpointer
 get_session_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   char *lock_holder = (char *) data;
-   char *mode = DB_GET_VAL("session_mode", j);
+    char *lock_holder = (char *) data;
+    char *mode = DB_GET_VAL("session_mode", j);
 
-   if ((MODE_SINGLE_FILE == be->session_mode) ||
-       (MODE_SINGLE_UPDATE == be->session_mode) ||
-       (0 == strcasecmp (mode, "SINGLE-FILE")) ||
-       (0 == strcasecmp (mode, "SINGLE-UPDATE")))
-   {
-      char * hostname = DB_GET_VAL("hostname", j);
-      char * username = DB_GET_VAL("login_name",j);
-      char * gecos = DB_GET_VAL("gecos",j);
-      char * datestr = DB_GET_VAL("time_on", j);
+    if ((MODE_SINGLE_FILE == be->session_mode) ||
+            (MODE_SINGLE_UPDATE == be->session_mode) ||
+            (0 == strcasecmp (mode, "SINGLE-FILE")) ||
+            (0 == strcasecmp (mode, "SINGLE-UPDATE")))
+    {
+        char * hostname = DB_GET_VAL("hostname", j);
+        char * username = DB_GET_VAL("login_name", j);
+        char * gecos = DB_GET_VAL("gecos", j);
+        char * datestr = DB_GET_VAL("time_on", j);
 
-      PWARN ("This database is already opened by \n"
-             "\t%s@%s (%s) in mode %s on %s \n",
-             username ? username : "(null)",
-             hostname ? hostname : "(null)",
-             gecos ? gecos : "(null)",
-             mode ? mode : "(null)",
-             datestr ? datestr : "(null)");
+        PWARN ("This database is already opened by \n"
+               "\t%s@%s (%s) in mode %s on %s \n",
+               username ? username : "(null)",
+               hostname ? hostname : "(null)",
+               gecos ? gecos : "(null)",
+               mode ? mode : "(null)",
+               datestr ? datestr : "(null)");
 
-      PWARN ("The above messages should be handled by the GUI\n");
+        PWARN ("The above messages should be handled by the GUI\n");
 
-      if (lock_holder) return lock_holder;
-      lock_holder = g_strdup (DB_GET_VAL("sessionGUID",j));
-   }
-   return lock_holder;
+        if (lock_holder) return lock_holder;
+        lock_holder = g_strdup (DB_GET_VAL("sessionGUID", j));
+    }
+    return lock_holder;
 }
 
 static gboolean
 pgendSessionCanStart (PGBackend *be, int break_lock)
 {
-   gboolean retval = TRUE;
-   char *p, *lock_holder;
+    gboolean retval = TRUE;
+    char *p, *lock_holder;
 
-   ENTER (" ");
-   /* Find out if there are any open sessions.
-    * If 'time_off' is infinity, then user hasn't logged off yet  */
-   p = "SELECT * FROM gncSession "
-       "WHERE time_off='INFINITY';";
-   SEND_QUERY (be,p, FALSE);
-   lock_holder = pgendGetResults (be, get_session_cb, NULL);
-  
-   if (lock_holder) retval = FALSE;
+    ENTER (" ");
+    /* Find out if there are any open sessions.
+     * If 'time_off' is infinity, then user hasn't logged off yet  */
+    p = "SELECT * FROM gncSession "
+        "WHERE time_off='INFINITY';";
+    SEND_QUERY (be, p, FALSE);
+    lock_holder = pgendGetResults (be, get_session_cb, NULL);
 
-   /* If just one other user has a lock, then will go ahead and 
-    * break the lock... If the user approved.  I don't like this
-    * but that's what the GUI is set up to do ...
-    */
-   PINFO ("break_lock=%d nrows=%d lock_holder=%s\n", 
+    if (lock_holder) retval = FALSE;
+
+    /* If just one other user has a lock, then will go ahead and
+     * break the lock... If the user approved.  I don't like this
+     * but that's what the GUI is set up to do ...
+     */
+    PINFO ("break_lock=%d nrows=%d lock_holder=%s\n",
            break_lock, be->nrows,
-          lock_holder ? lock_holder : "(null)");
-   if (break_lock && (1==be->nrows) && lock_holder)
-   {
-      p = be->buff; *p=0;
-      p = stpcpy (p, "UPDATE gncSession SET time_off='NOW' "
-                     "WHERE sessionGuid='");
-      p = stpcpy (p, lock_holder);
-      p = stpcpy (p, "';");
-     
-      SEND_QUERY (be,be->buff, retval);
-      FINISH_QUERY(be->connection);
-      retval = TRUE;
-   }
+           lock_holder ? lock_holder : "(null)");
+    if (break_lock && (1 == be->nrows) && lock_holder)
+    {
+        p = be->buff;
+        *p = 0;
+        p = stpcpy (p, "UPDATE gncSession SET time_off='NOW' "
+                    "WHERE sessionGuid='");
+        p = stpcpy (p, lock_holder);
+        p = stpcpy (p, "';");
 
-   if (lock_holder) g_free (lock_holder);
+        SEND_QUERY (be, be->buff, retval);
+        FINISH_QUERY(be->connection);
+        retval = TRUE;
+    }
 
-   LEAVE (" ");
-   return retval;
+    if (lock_holder) g_free (lock_holder);
+
+    LEAVE (" ");
+    return retval;
 }
 
 
 /* ============================================================= */
-/* The pgendSessionValidate() routine determines whether a valid 
+/* The pgendSessionValidate() routine determines whether a valid
  *    session could be obtained.  It checks to see if:
  *    1) Database appers to have gnucash data in it
  *    2) the session table can be locked and updated to start
@@ -1256,143 +1288,152 @@
  *    Return TRUE if we have a session.
  */
 
-static gpointer 
+static gpointer
 is_gnucash_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   if (TRUE == GPOINTER_TO_INT (data)) return GINT_TO_POINTER (TRUE);
+    if (TRUE == GPOINTER_TO_INT (data)) return GINT_TO_POINTER (TRUE);
 
-   if (0 == strcmp ("gncsession", (DB_GET_VAL ("tablename", j)))) 
-      return GINT_TO_POINTER (TRUE);
-   return GINT_TO_POINTER (FALSE);
+    if (0 == strcmp ("gncsession", (DB_GET_VAL ("tablename", j))))
+        return GINT_TO_POINTER (TRUE);
+    return GINT_TO_POINTER (FALSE);
 }
 
 static gboolean
 pgendSessionValidate (PGBackend *be, int break_lock)
 {
-   gboolean retval = FALSE;
-   char *p;
-   ENTER(" ");
+    gboolean retval = FALSE;
+    char *p;
+    ENTER(" ");
 
-   if (MODE_NONE == be->session_mode) return FALSE;
+    if (MODE_NONE == be->session_mode) return FALSE;
 
-   /* check to see if this database actually contains 
-    * GnuCash data... */
-   p = "SELECT * FROM pg_tables; ";
-   SEND_QUERY (be,p, FALSE);
-   retval = GPOINTER_TO_INT (pgendGetResults (be,
-                                              is_gnucash_cb,
-                                              GINT_TO_POINTER (FALSE)));
-   if (FALSE == retval) {
-      qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT);
-      return FALSE;
-   }
-   
-   /* Lock it up so that we test-n-set atomically 
-    * i.e. we want to avoid a race condition when testing
-    * for the single-user session.
-    */
-   p = "BEGIN;"
-       "LOCK TABLE gncSession IN EXCLUSIVE MODE; ";
-   SEND_QUERY (be,p, FALSE);
-   
-   /* Instead of doing a simple FINISH_QUERY(be->connection); 
-    * We need to see if we actually have permission to lock 
-    * the table. If its not lockable, then user doesn't have 
-    * perms. */
-   retval = TRUE;
-   {
-      int i=0;
-      PGresult *result;
-      do {
-         ExecStatusType status;
-         result = PQgetResult(be->connection);
-         if (!result) break;
-         PINFO ("clearing result %d", i);
-         status = PQresultStatus(result);
-         if (PGRES_COMMAND_OK != status) {
-            PINFO("cannot lock:\n"
-                 "\t%s", PQerrorMessage(be->connection));
-            retval = FALSE;
-         }
-         PQclear(result);
-         i++;
-      } while (result);
-   }
-   
-   if (FALSE == retval)
-   {
-      qof_backend_set_error (&be->be, ERR_BACKEND_PERM);
-      p = "ROLLBACK;";
-      SEND_QUERY (be,p, FALSE);
-      FINISH_QUERY(be->connection);
-      return FALSE;
-   }
+    /* check to see if this database actually contains
+     * GnuCash data... */
+    p = "SELECT * FROM pg_tables; ";
+    SEND_QUERY (be, p, FALSE);
+    retval = GPOINTER_TO_INT (pgendGetResults (be,
+                              is_gnucash_cb,
+                              GINT_TO_POINTER (FALSE)));
+    if (FALSE == retval)
+    {
+        qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT);
+        return FALSE;
+    }
 
+    /* Lock it up so that we test-n-set atomically
+     * i.e. we want to avoid a race condition when testing
+     * for the single-user session.
+     */
+    p = "BEGIN;"
+        "LOCK TABLE gncSession IN EXCLUSIVE MODE; ";
+    SEND_QUERY (be, p, FALSE);
 
-   /* Check to see if we can start a session of the desired type.  */
-   if (FALSE == pgendSessionCanStart (be, break_lock))
-   {
-      /* This error should be treated just like the 
-       * file-lock error from the GUI perspective:
-       * (The GUI allows users to break the lock, if desired).
-       */
-      be->be.load = pgend_book_load_single_lockerr;
-      qof_backend_set_error (&be->be, ERR_BACKEND_LOCKED);
-      retval = FALSE;
-   } else {
+    /* Instead of doing a simple FINISH_QUERY(be->connection);
+     * We need to see if we actually have permission to lock
+     * the table. If its not lockable, then user doesn't have
+     * perms. */
+    retval = TRUE;
+    {
+        int i = 0;
+        PGresult *result;
+        do
+        {
+            ExecStatusType status;
+            result = PQgetResult(be->connection);
+            if (!result) break;
+            PINFO ("clearing result %d", i);
+            status = PQresultStatus(result);
+            if (PGRES_COMMAND_OK != status)
+            {
+                PINFO("cannot lock:\n"
+                      "\t%s", PQerrorMessage(be->connection));
+                retval = FALSE;
+            }
+            PQclear(result);
+            i++;
+        }
+        while (result);
+    }
 
-      /* make note of the session. */
-      be->sessionGuid = guid_malloc();
-      guid_new (be->sessionGuid);
-      guid_to_string_buff (be->sessionGuid, be->session_guid_str);
-      pgendStoreOneSessionOnly (be, (void *)-1, SQL_INSERT);
-      retval = TRUE;
-   }
+    if (FALSE == retval)
+    {
+        qof_backend_set_error (&be->be, ERR_BACKEND_PERM);
+        p = "ROLLBACK;";
+        SEND_QUERY (be, p, FALSE);
+        FINISH_QUERY(be->connection);
+        return FALSE;
+    }
 
-   p = "COMMIT;\n"
-       "NOTIFY gncSession;";
-   SEND_QUERY (be,p, FALSE);
-   FINISH_QUERY(be->connection);
 
-   LEAVE(" ");
-   return retval;
+    /* Check to see if we can start a session of the desired type.  */
+    if (FALSE == pgendSessionCanStart (be, break_lock))
+    {
+        /* This error should be treated just like the
+         * file-lock error from the GUI perspective:
+         * (The GUI allows users to break the lock, if desired).
+         */
+        be->be.load = pgend_book_load_single_lockerr;
+        qof_backend_set_error (&be->be, ERR_BACKEND_LOCKED);
+        retval = FALSE;
+    }
+    else
+    {
+
+        /* make note of the session. */
+        be->sessionGuid = guid_malloc();
+        guid_new (be->sessionGuid);
+        guid_to_string_buff (be->sessionGuid, be->session_guid_str);
+        pgendStoreOneSessionOnly (be, (void *) - 1, SQL_INSERT);
+        retval = TRUE;
+    }
+
+    p = "COMMIT;\n"
+        "NOTIFY gncSession;";
+    SEND_QUERY (be, p, FALSE);
+    FINISH_QUERY(be->connection);
+
+    LEAVE(" ");
+    return retval;
 }
 
 /* ============================================================= */
-/* The pgendSessionEnd() routine will log the end of session in 
- *    the session table of the database. 
+/* The pgendSessionEnd() routine will log the end of session in
+ *    the session table of the database.
  */
 
 static void
 pgendSessionEnd (PGBackend *be)
 {
-   char *p;
+    char *p;
 
-   if (!be->sessionGuid) return;
+    if (!be->sessionGuid) return;
 
 #if 0
-   /* vacuuming w/ analyze can improve performance 20%.
-    * Should this really be done on every session end?
-    * The postgres manual recommends once every night! */
-   p = be->buff; *p=0;
-   p = stpcpy (p, "VACUUM ANALYZE;\n");
+    /* vacuuming w/ analyze can improve performance 20%.
+     * Should this really be done on every session end?
+     * The postgres manual recommends once every night! */
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "VACUUM ANALYZE;\n");
 
-   SEND_QUERY (be,be->buff, );
-   FINISH_QUERY(be->connection);
+    SEND_QUERY (be, be->buff, );
+    FINISH_QUERY(be->connection);
 #endif
 
-   p = be->buff; *p=0;
-   p = stpcpy (p, "UPDATE gncSession SET time_off='NOW' "
-                  "WHERE sessionGuid='");
-   p = stpcpy (p, be->session_guid_str);
-   p = stpcpy (p, "';\n"
-                  "NOTIFY gncSession;");
-  
-   SEND_QUERY (be,be->buff, );
-   FINISH_QUERY(be->connection);
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "UPDATE gncSession SET time_off='NOW' "
+                "WHERE sessionGuid='");
+    p = stpcpy (p, be->session_guid_str);
+    p = stpcpy (p, "';\n"
+                "NOTIFY gncSession;");
 
-   guid_free (be->sessionGuid); be->sessionGuid = NULL;
-   guid_to_string_buff (&nullguid, be->session_guid_str);
+    SEND_QUERY (be, be->buff, );
+    FINISH_QUERY(be->connection);
+
+    guid_free (be->sessionGuid);
+    be->sessionGuid = NULL;
+    guid_to_string_buff (&nullguid, be->session_guid_str);
 }
 
 /* ============================================================= */
@@ -1405,113 +1446,127 @@
 static void
 pgend_session_end (QofBackend *bend)
 {
-   int i;
-   PGBackend *be = (PGBackend *)bend;
-   if (!be) return;
+    int i;
+    PGBackend *be = (PGBackend *)bend;
+    if (!be) return;
 
-   ENTER("be=%p", be);
+    ENTER("be=%p", be);
 
-   /* mode-specific shutdowns */
-   switch (be->session_mode)
-   {
-      case MODE_SINGLE_FILE:
-      case MODE_SINGLE_UPDATE:
-         /* although the book may be open in 'single-user' mode right now,
-          * it might be opened in multi-user mode next time. Thus, update
-          * the account balance checkpoints just in case. 
-          */
-         /* pgendAccountTreeRecomputeAllCheckpoints (be, be->root); */
-         break;
+    /* mode-specific shutdowns */
+    switch (be->session_mode)
+    {
+    case MODE_SINGLE_FILE:
+    case MODE_SINGLE_UPDATE:
+        /* although the book may be open in 'single-user' mode right now,
+         * it might be opened in multi-user mode next time. Thus, update
+         * the account balance checkpoints just in case.
+         */
+        /* pgendAccountTreeRecomputeAllCheckpoints (be, be->root); */
+        break;
 
-      case MODE_POLL:
-         break;
+    case MODE_POLL:
+        break;
 
-      case MODE_EVENT:
-         break;
+    case MODE_EVENT:
+        break;
 
-      default:
-         PERR ("bad mode specified");
-         break;
-   }
+    default:
+        PERR ("bad mode specified");
+        break;
+    }
 
-   /* prevent further callbacks into backend */
-   pgendDisable(be);
-   be->be.session_begin = NULL;
-   be->be.session_end = NULL;
+    /* prevent further callbacks into backend */
+    pgendDisable(be);
+    be->be.session_begin = NULL;
+    be->be.session_end = NULL;
 
-   /* note the logoff time in the session directory */
-   pgendSessionEnd (be);
+    /* note the logoff time in the session directory */
+    pgendSessionEnd (be);
 
-   /* disconnect from the backend */
-   if(be->connection) PQfinish (be->connection);
-   be->connection = 0;
+    /* disconnect from the backend */
+    if (be->connection) PQfinish (be->connection);
+    be->connection = 0;
 
-   if (be->dbName) { g_free(be->dbName); be->dbName = NULL; }
-   if (be->portno) { g_free(be->portno); be->portno = NULL; }
-   if (be->hostname) { g_free(be->hostname); be->hostname = NULL; }
+    if (be->dbName)
+    {
+        g_free(be->dbName);
+        be->dbName = NULL;
+    }
+    if (be->portno)
+    {
+        g_free(be->portno);
+        be->portno = NULL;
+    }
+    if (be->hostname)
+    {
+        g_free(be->hostname);
+        be->hostname = NULL;
+    }
 
-   sqlBuilder_destroy (be->builder); be->builder = NULL;
-   g_free (be->buff); be->buff = NULL; 
+    sqlBuilder_destroy (be->builder);
+    be->builder = NULL;
+    g_free (be->buff);
+    be->buff = NULL;
 
-   /* free the path strings */
-   for (i=0; i< be->path_cache_size; i++) 
-   {
-      if ((be->path_cache)[i]) g_free ((be->path_cache)[i]);
-      (be->path_cache)[i] = NULL;
-   }
-   g_free (be->path_cache);
-   be->path_cache = NULL;
-   be->path_cache_size = 0;
-   be->ipath_max = 0;
+    /* free the path strings */
+    for (i = 0; i < be->path_cache_size; i++)
+    {
+        if ((be->path_cache)[i]) g_free ((be->path_cache)[i]);
+        (be->path_cache)[i] = NULL;
+    }
+    g_free (be->path_cache);
+    be->path_cache = NULL;
+    be->path_cache_size = 0;
+    be->ipath_max = 0;
 
-   LEAVE("be=%p", be);
+    LEAVE("be=%p", be);
 }
 
 /* ============================================================= */
 /* The pgend_book_load_poll() routine loads account info from
- *    the database into the engine.   Its to be used only for 
- *    the poll & event style load, where only the accounts, 
- *    and never the transactions, need to be loaded. 
+ *    the database into the engine.   Its to be used only for
+ *    the poll & event style load, where only the accounts,
+ *    and never the transactions, need to be loaded.
  */
 static void
 pgend_book_load_poll (QofBackend *bend, QofBook *book)
 {
-   Timespec ts = gnc_iso8601_to_timespec_gmt (CK_BEFORE_LAST_DATE);
-   Account *root;
-   PGBackend *be = (PGBackend *)bend;
+    Timespec ts = gnc_iso8601_to_timespec_gmt (CK_BEFORE_LAST_DATE);
+    Account *root;
+    PGBackend *be = (PGBackend *)bend;
 
-   if (!be) return;
+    if (!be) return;
 
-   /* don't send events  to GUI, don't accept callbacks to backend */
-   qof_event_suspend();
-   pgendDisable(be);
-   be->version_check = (guint32) time(0);
+    /* don't send events  to GUI, don't accept callbacks to backend */
+    qof_event_suspend();
+    pgendDisable(be);
+    be->version_check = (guint32) time(0);
 
-   pgendKVPInit(be);
+    pgendKVPInit(be);
 
-   if (be->blist) 
-   {
-      PWARN ("old book list not empty--clearing it out ");
-      /* XXX not clear what this means ... should we free old books ?? */
-      g_list_free (be->blist);
-      be->blist = NULL;
-   }
-   pgendBookRestore (be, book);
-   pgend_set_book (be, book);
-                        
-   PINFO("Book GUID = %s\n",
-           guid_to_string(qof_book_get_guid(book)));
+    if (be->blist)
+    {
+        PWARN ("old book list not empty--clearing it out ");
+        /* XXX not clear what this means ... should we free old books ?? */
+        g_list_free (be->blist);
+        be->blist = NULL;
+    }
+    pgendBookRestore (be, book);
+    pgend_set_book (be, book);
 
-   pgendGetAllAccountsInBook (be, book);
+    PINFO("Book GUID = %s\n",
+          guid_to_string(qof_book_get_guid(book)));
 
-   root = gnc_book_get_root_account (book);
-   xaccAccountBeginEdit (root);
-   pgendAccountTreeGetAllBalances (be, root, ts);
-   xaccAccountCommitEdit (root);
+    pgendGetAllAccountsInBook (be, book);
 
-   /* re-enable events */
-   pgendEnable(be);
-   qof_event_resume();
+    root = gnc_book_get_root_account (book);
+    xaccAccountBeginEdit (root);
+    pgendAccountTreeGetAllBalances (be, root, ts);
+    xaccAccountCommitEdit (root);
+
+    /* re-enable events */
+    pgendEnable(be);
+    qof_event_resume();
 }
 
 /* ============================================================= */
@@ -1525,64 +1580,68 @@
 static void
 pgend_book_load_single (QofBackend *bend, QofBook *book)
 {
-   PGBackend *be = (PGBackend *)bend;
+    PGBackend *be = (PGBackend *)bend;
 
-   if (!be) return;
+    if (!be) return;
 
 
-   /* don't send events  to GUI, don't accept callbacks to backend */
-   qof_event_suspend();
-   pgendDisable(be);
-   be->version_check = (guint32) time(0);
+    /* don't send events  to GUI, don't accept callbacks to backend */
+    qof_event_suspend();
+    pgendDisable(be);
+    be->version_check = (guint32) time(0);
 
-   pgendKVPInit(be);
+    pgendKVPInit(be);
 
-   if (be->blist) 
-   {
-      PWARN ("old book list not empty--clearing it out ");
-      /* XXX not clear what this means ... should we free old books ?? */
-      g_list_free (be->blist);
-      be->blist = NULL;
-   }
-   pgendBookRestore (be, book);
-   pgend_set_book (be, book);
+    if (be->blist)
+    {
+        PWARN ("old book list not empty--clearing it out ");
+        /* XXX not clear what this means ... should we free old books ?? */
+        g_list_free (be->blist);
+        be->blist = NULL;
+    }
+    pgendBookRestore (be, book);
+    pgend_set_book (be, book);
 
-   pgendGetAllAccountsInBook (be, book);
+    pgendGetAllAccountsInBook (be, book);
 
-   pgendGetMassTransactions (be, book);
+    pgendGetMassTransactions (be, book);
 
-   /* re-enable events */
-   pgendEnable(be);
-   qof_event_resume();
+    /* re-enable events */
+    pgendEnable(be);
+    qof_event_resume();
 }
 
 /* ============================================================= */
 /* The pgend_price_load_single() routine loads the engine with
- *    price data from the database.  
+ *    price data from the database.
  */
 
 static void
 pgend_price_load_single (QofBackend *bend, QofBook *book)
 {
-   PGBackend *be = (PGBackend *)bend;
+    PGBackend *be = (PGBackend *)bend;
 
-   ENTER("be = %p", bend);
-   
-   if (!be || !book) { LEAVE("(null) args"); return; }
+    ENTER("be = %p", bend);
 
-   pgend_set_book (be, book);
+    if (!be || !book)
+    {
+        LEAVE("(null) args");
+        return;
+    }
 
-   /* don't send events  to GUI, don't accept callbacks to backend */
-   qof_event_suspend();
-   pgendDisable(be);
-   be->version_check = (guint32) time(0);
+    pgend_set_book (be, book);
 
-   pgendGetAllPricesInBook (be, book);
+    /* don't send events  to GUI, don't accept callbacks to backend */
+    qof_event_suspend();
+    pgendDisable(be);
+    be->version_check = (guint32) time(0);
 
-   /* re-enable events */
-   pgendEnable(be);
-   qof_event_resume();
-   LEAVE(" ");
+    pgendGetAllPricesInBook (be, book);
+
+    /* re-enable events */
+    pgendEnable(be);
+    qof_event_resume();
+    LEAVE(" ");
 }
 
 /* ============================================================= */
@@ -1595,120 +1654,124 @@
 static void
 pgend_do_load_single (QofBackend *bend, QofBook *book)
 {
-  ENTER ("be=%p", bend);
-  pgend_book_load_single (bend, book);
-  pgend_price_load_single (bend, book);
+    ENTER ("be=%p", bend);
+    pgend_book_load_single (bend, book);
+    pgend_price_load_single (bend, book);
 
-  /* XXX: Other things to load here.... (dynamic data) */
-  LEAVE ("be=%p", bend);
+    /* XXX: Other things to load here.... (dynamic data) */
+    LEAVE ("be=%p", bend);
 }
 
 static void
 pgendDoSyncSingleFile (QofBackend *bend, QofBook *book)
 {
-  ENTER ("be=%p", bend);
-  pgendSyncSingleFile (bend, book);
-  pgendSyncPriceDBSingleFile (bend, book);
+    ENTER ("be=%p", bend);
+    pgendSyncSingleFile (bend, book);
+    pgendSyncPriceDBSingleFile (bend, book);
 
-  /* XXX: Other data types */
-  LEAVE ("be=%p", bend);
+    /* XXX: Other data types */
+    LEAVE ("be=%p", bend);
 }
 
 static void
 pgendDoSync (QofBackend *bend, QofBook *book)
 {
-  ENTER ("be=%p", bend);
-  pgendSync (bend, book);
-  pgendSyncPriceDB (bend, book);
+    ENTER ("be=%p", bend);
+    pgendSync (bend, book);
+    pgendSyncPriceDB (bend, book);
 
-  /* XXX: Other data types */
-  LEAVE ("be=%p", bend);
+    /* XXX: Other data types */
+    LEAVE ("be=%p", bend);
 }
 
 static void
 pgend_do_begin (QofBackend *bend, QofInstance *inst)
 {
-  PGBackend *be = (PGBackend*)bend;
-  QofIdTypeConst type = inst->e_type;
+    PGBackend *be = (PGBackend*)bend;
+    QofIdTypeConst type = inst->e_type;
 
-  ENTER ("be=%p, type=%s", bend, type);
-  // if (!safe_strcmp (type, GNC_ID_PERIOD))
-  //   return pgend_book_transfer_begin (bend, object);
+    ENTER ("be=%p, type=%s", bend, type);
+    // if (!safe_strcmp (type, GNC_ID_PERIOD))
+    //   return pgend_book_transfer_begin (bend, object);
 
-  switch (be->session_mode) {
-      case MODE_EVENT:
-      case MODE_POLL:
-      case MODE_SINGLE_UPDATE:
-          if (!safe_strcmp (type, GNC_ID_PRICE))
-              return pgend_price_begin_edit (bend, (GNCPrice *) inst);
+    switch (be->session_mode)
+    {
+    case MODE_EVENT:
+    case MODE_POLL:
+    case MODE_SINGLE_UPDATE:
+        if (!safe_strcmp (type, GNC_ID_PRICE))
+            return pgend_price_begin_edit (bend, (GNCPrice *) inst);
 
-      case MODE_SINGLE_FILE:
-      case MODE_NONE:
-          break;
-  }
+    case MODE_SINGLE_FILE:
+    case MODE_NONE:
+        break;
+    }
 
-  /* XXX: Add dynamic plug-in here */
-  LEAVE ("be=%p, type=%s", bend, type);
+    /* XXX: Add dynamic plug-in here */
+    LEAVE ("be=%p, type=%s", bend, type);
 }
 
 static void
 pgend_do_commit (QofBackend *bend, QofInstance *inst)
 {
-  PGBackend *be = (PGBackend*)bend;
-  QofIdTypeConst type = inst->e_type;
+    PGBackend *be = (PGBackend*)bend;
+    QofIdTypeConst type = inst->e_type;
 
-  ENTER ("be=%p, type=%s", bend, type);
-  // if (!safe_strcmp (type, GNC_ID_PERIOD))
-  //  return pgend_book_transfer_commit (bend, object);
+    ENTER ("be=%p, type=%s", bend, type);
+    // if (!safe_strcmp (type, GNC_ID_PERIOD))
+    //  return pgend_book_transfer_commit (bend, object);
 
-  switch (be->session_mode) {
-  case MODE_EVENT:
-  case MODE_POLL:
-  case MODE_SINGLE_UPDATE:
+    switch (be->session_mode)
+    {
+    case MODE_EVENT:
+    case MODE_POLL:
+    case MODE_SINGLE_UPDATE:
 
-    if (!safe_strcmp (type, GNC_ID_TRANS)) {
-      Transaction *txn = (Transaction*) inst;
-      return pgend_trans_commit_edit (bend, txn, txn->orig);
-    }
+        if (!safe_strcmp (type, GNC_ID_TRANS))
+        {
+            Transaction *txn = (Transaction*) inst;
+            return pgend_trans_commit_edit (bend, txn, txn->orig);
+        }
 
-    if (!safe_strcmp (type, GNC_ID_PRICE))
-      return pgend_price_commit_edit (bend, (GNCPrice *) inst);
+        if (!safe_strcmp (type, GNC_ID_PRICE))
+            return pgend_price_commit_edit (bend, (GNCPrice *) inst);
 
-    if (!safe_strcmp (type, GNC_ID_ACCOUNT))
-      return pgend_account_commit_edit (bend, (Account *) inst);
+        if (!safe_strcmp (type, GNC_ID_ACCOUNT))
+            return pgend_account_commit_edit (bend, (Account *) inst);
 
-  case MODE_SINGLE_FILE:
-  case MODE_NONE:
-    break;
-    
-  }
+    case MODE_SINGLE_FILE:
+    case MODE_NONE:
+        break;
 
-  /* XXX: Add dynamic plug-in here */
-  LEAVE ("be=%p, type=%s", bend, type);
+    }
+
+    /* XXX: Add dynamic plug-in here */
+    LEAVE ("be=%p, type=%s", bend, type);
 }
 
 static void
 pgend_do_rollback (QofBackend *bend, QofInstance *inst)
 {
-  PGBackend *be = (PGBackend*)bend;
-  QofIdTypeConst type = inst->e_type;
+    PGBackend *be = (PGBackend*)bend;
+    QofIdTypeConst type = inst->e_type;
 
-  ENTER ("be=%p, type=%s", bend, type);
-  switch (be->session_mode) {
-  case MODE_EVENT:
-  case MODE_POLL:
+    ENTER ("be=%p, type=%s", bend, type);
+    switch (be->session_mode)
+    {
+    case MODE_EVENT:
+    case MODE_POLL:
 
-    if (!safe_strcmp (type, GNC_ID_TRANS))
-      return pgend_trans_rollback_edit (bend, (Transaction *)inst);
+        if (!safe_strcmp (type, GNC_ID_TRANS))
+            return pgend_trans_rollback_edit (bend, (Transaction *)inst);
 
-  case MODE_SINGLE_UPDATE:
-  case MODE_SINGLE_FILE:
-  case MODE_NONE:
-    break;
-  }
+    case MODE_SINGLE_UPDATE:
+    case MODE_SINGLE_FILE:
+    case MODE_NONE:
+        break;
+    }
 
-  /* XXX: Add dynamic plug-in here */
-  LEAVE ("be=%p, type=%s", bend, type);
+    /* XXX: Add dynamic plug-in here */
+    LEAVE ("be=%p, type=%s", bend, type);
 }
 
 /* ============================================================= */
@@ -1716,7 +1779,7 @@
  *    into the SQL backend code.
  *
  *    1) It parses the URL to find the database, username, password, etc.
- *    2) It makes the first contact to the database, and tries to 
+ *    2) It makes the first contact to the database, and tries to
  *       initiate a user session.
  *    3) It creates the GnuCash tables for the first time, if these
  *       need to be created.
@@ -1724,530 +1787,552 @@
  *    5) loads data from the database into the engine.
  */
 
-static gpointer 
+static gpointer
 has_results_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   return GINT_TO_POINTER (TRUE);
+    return GINT_TO_POINTER (TRUE);
 }
 
 static void
 pgend_create_db (PGBackend *be)
 {
-  /* We do this in pieces, so as not to exceed the max length
-   * for postgres queries (which is 8192). */
+    /* We do this in pieces, so as not to exceed the max length
+     * for postgres queries (which is 8192). */
 
-  SEND_QUERY (be,table_create_str, );
-  FINISH_QUERY(be->connection);
-  SEND_QUERY (be,table_version_str, );
-  FINISH_QUERY(be->connection);
-  SEND_QUERY (be,table_audit_str, );
-  FINISH_QUERY(be->connection);
-  SEND_QUERY (be,sql_functions_str, );
-  FINISH_QUERY(be->connection);
-  be->freshly_created_db = TRUE;
-  be->freshly_created_prdb = TRUE;
+    SEND_QUERY (be, table_create_str, );
+    FINISH_QUERY(be->connection);
+    SEND_QUERY (be, table_version_str, );
+    FINISH_QUERY(be->connection);
+    SEND_QUERY (be, table_audit_str, );
+    FINISH_QUERY(be->connection);
+    SEND_QUERY (be, sql_functions_str, );
+    FINISH_QUERY(be->connection);
+    be->freshly_created_db = TRUE;
+    be->freshly_created_prdb = TRUE;
 }
 
 static void
 pgend_session_begin (QofBackend *backend,
                      QofSession *session,
-                     const char * sessionid, 
+                     const char * sessionid,
                      gboolean ignore_lock,
                      gboolean create_new_db)
 {
-   int rc;
-   PGBackend *be;
-   char *url, *start, *end;
-   char *password=NULL;
-   char *pg_options=NULL;
-   char *pg_tty=NULL;
-   char *p;
-   gboolean db_exists = FALSE;
+    int rc;
+    PGBackend *be;
+    char *url, *start, *end;
+    char *password = NULL;
+    char *pg_options = NULL;
+    char *pg_tty = NULL;
+    char *p;
+    gboolean db_exists = FALSE;
 
-   if (!backend) return;
-   be = (PGBackend*)backend;
+    if (!backend) return;
+    be = (PGBackend*)backend;
 
-   ENTER("be=%p, sessionid=%s", be,
-         sessionid ? sessionid : "(null)");
+    ENTER("be=%p, sessionid=%s", be,
+          sessionid ? sessionid : "(null)");
 
-   /* close any dangling sessions from before; reinitialize */
-   pgend_session_end ((QofBackend *) be);
-   pgendInit (be);
+    /* close any dangling sessions from before; reinitialize */
+    pgend_session_end ((QofBackend *) be);
+    pgendInit (be);
 
-   be->session = session;
+    be->session = session;
 
-   if (be->blist) 
-   {
-      /* XXX not clear what this means ... should we free old books ?? */
-      PWARN ("old book list not empty ");
-      g_list_free (be->blist);
-      be->blist = NULL;
-   }
+    if (be->blist)
+    {
+        /* XXX not clear what this means ... should we free old books ?? */
+        PWARN ("old book list not empty ");
+        g_list_free (be->blist);
+        be->blist = NULL;
+    }
 
-   /* Parse the sessionid for the hostname, port number and db name.
-    * The expected URL format is
-    * postgres://some.host.com/db_name
-    * postgres://some.host.com:portno/db_name
-    * postgres://localhost/db_name
-    * postgres://localhost:nnn/db_name
-    * 
-    * Also parse urls of the form
-    * postgres://some.host.com/db_name?pgkey=pgval&pgkey=pgval
-    * e.g.
-    * postgres://some.host.com/db_name?user=r00t&pass=3733t&mode=multi-user
-    */
+    /* Parse the sessionid for the hostname, port number and db name.
+     * The expected URL format is
+     * postgres://some.host.com/db_name
+     * postgres://some.host.com:portno/db_name
+     * postgres://localhost/db_name
+     * postgres://localhost:nnn/db_name
+     *
+     * Also parse urls of the form
+     * postgres://some.host.com/db_name?pgkey=pgval&pgkey=pgval
+     * e.g.
+     * postgres://some.host.com/db_name?user=r00t&pass=3733t&mode=multi-user
+     */
 
-   if (strncmp (sessionid, "postgres://", 11)) 
-   {
-      qof_backend_set_error (&be->be, ERR_BACKEND_BAD_URL);
-      return;
-   }
-   url = g_strdup(sessionid);
-   start = url + 11;
-   end = strchr (start, ':');
-   if (end) 
-   {
-     /* if colon found, then extract port number */
-     *end = 0x0;
-     be->hostname = g_strdup (start);
-     start = end+1;
-     end = strchr (start, '/');
-     if (!end) { g_free(url); return; }
-     *end = 0;
-     be->portno = g_strdup (start);
-   } 
-   else 
-   {
-     end = strchr (start, '/');
-     if (!end) { g_free(url); return; }
-     *end = 0;
-     be->hostname = g_strdup (start);
-   }
-   start = end+1;
-   if (0x0 == *start) 
-   { 
-      qof_backend_set_error (&be->be, ERR_BACKEND_BAD_URL);
-      g_free(url); 
-      return; 
-   }
+    if (strncmp (sessionid, "postgres://", 11))
+    {
+        qof_backend_set_error (&be->be, ERR_BACKEND_BAD_URL);
+        return;
+    }
+    url = g_strdup(sessionid);
+    start = url + 11;
+    end = strchr (start, ':');
+    if (end)
+    {
+        /* if colon found, then extract port number */
+        *end = 0x0;
+        be->hostname = g_strdup (start);
+        start = end + 1;
+        end = strchr (start, '/');
+        if (!end)
+        {
+            g_free(url);
+            return;
+        }
+        *end = 0;
+        be->portno = g_strdup (start);
+    }
+    else
+    {
+        end = strchr (start, '/');
+        if (!end)
+        {
+            g_free(url);
+            return;
+        }
+        *end = 0;
+        be->hostname = g_strdup (start);
+    }
+    start = end + 1;
+    if (0x0 == *start)
+    {
+        qof_backend_set_error (&be->be, ERR_BACKEND_BAD_URL);
+        g_free(url);
+        return;
+    }
 
-   /* dbname is the last thing before the url-encoded data */
-   end = strchr (start, '?');
-   if (end) *end = 0;
-   be->dbName = g_strdup (start);
+    /* dbname is the last thing before the url-encoded data */
+    end = strchr (start, '?');
+    if (end) *end = 0;
+    be->dbName = g_strdup (start);
 
-   /* loop and parse url-encoded data */
-   while (end)
-   {
-      start = end+1;
-      end = strchr (start, '&');
-      if (end) *end = 0;
+    /* loop and parse url-encoded data */
+    while (end)
+    {
+        start = end + 1;
+        end = strchr (start, '&');
+        if (end) *end = 0;
 
-      /* mode keyword */
-      if (0 == strncasecmp (start, "mode=", 5))
-      {
-         start += 5;
-         if (0 == strcasecmp (start, "single-file")) {
-             be->session_mode = MODE_SINGLE_FILE;
-         } else
-         if (0 == strcasecmp (start, "single-update")) {
-             be->session_mode = MODE_SINGLE_UPDATE;
-         } else
-         if (0 == strcasecmp (start, "multi-user-poll")) {
-             be->session_mode = MODE_POLL;
-         } else
-         if (0 == strcasecmp (start, "multi-user")) {
-             be->session_mode = MODE_EVENT;
-         } else
-         {
-             PWARN ("the following message should be shown in a gui");
-             PWARN ("unknown mode %s, will use multi-user mode",
-                    start ? start : "(null)");
-             qof_backend_set_message((QofBackend *)be, _("Unknown database access mode '%s'. Using default mode: multi-user."),
-			           start ? start : "(null)");
-             be->session_mode = MODE_EVENT;
-         } 
-         
-      } else
+        /* mode keyword */
+        if (0 == strncasecmp (start, "mode=", 5))
+        {
+            start += 5;
+            if (0 == strcasecmp (start, "single-file"))
+            {
+                be->session_mode = MODE_SINGLE_FILE;
+            }
+            else if (0 == strcasecmp (start, "single-update"))
+            {
+                be->session_mode = MODE_SINGLE_UPDATE;
+            }
+            else if (0 == strcasecmp (start, "multi-user-poll"))
+            {
+                be->session_mode = MODE_POLL;
+            }
+            else if (0 == strcasecmp (start, "multi-user"))
+            {
+                be->session_mode = MODE_EVENT;
+            }
+            else
+            {
+                PWARN ("the following message should be shown in a gui");
+                PWARN ("unknown mode %s, will use multi-user mode",
+                       start ? start : "(null)");
+                qof_backend_set_message((QofBackend *)be, _("Unknown database access mode '%s'. Using default mode: multi-user."),
+                                        start ? start : "(null)");
+                be->session_mode = MODE_EVENT;
+            }
 
-      /* username and password */
-      if ((0 == strncasecmp (start, "username=", 9)) ||
-          (0 == strncasecmp (start, "user=", 5)) ||
-          (0 == strncasecmp (start, "login=", 6)))
-      {
-         start = strchr (start, '=') +1;
-         be->username = g_strdup (start);
-      } else
+        }
+        else
 
-      if ((0 == strncasecmp (start, "password=", 9)) ||
-          (0 == strncasecmp (start, "passwd=", 7)) ||
-          (0 == strncasecmp (start, "pass=", 5)) ||
-          (0 == strncasecmp (start, "pwd=", 4)))
-      {
-         start = strchr (start, '=') +1;
-         password = start;
-         if (0 == strcmp (password, "''")) password = "";
-      } else
+            /* username and password */
+            if ((0 == strncasecmp (start, "username=", 9)) ||
+                    (0 == strncasecmp (start, "user=", 5)) ||
+                    (0 == strncasecmp (start, "login=", 6)))
+            {
+                start = strchr (start, '=') + 1;
+                be->username = g_strdup (start);
+            }
+            else
 
-      /* postgres-specific options and debug tty  */
-      if (0 == strncasecmp (start, "options=", 8))
-      {
-         start = strchr (start, '=') +1;
-         pg_options = start;
-      } else
+                if ((0 == strncasecmp (start, "password=", 9)) ||
+                        (0 == strncasecmp (start, "passwd=", 7)) ||
+                        (0 == strncasecmp (start, "pass=", 5)) ||
+                        (0 == strncasecmp (start, "pwd=", 4)))
+                {
+                    start = strchr (start, '=') + 1;
+                    password = start;
+                    if (0 == strcmp (password, "''")) password = "";
+                }
+                else
 
-      if (0 == strncasecmp (start, "tty=", 4))
-      {
-         start = strchr (start, '=') +1;
-         pg_tty = start;
-      } else
+                    /* postgres-specific options and debug tty  */
+                    if (0 == strncasecmp (start, "options=", 8))
+                    {
+                        start = strchr (start, '=') + 1;
+                        pg_options = start;
+                    }
+                    else
 
-      /* ignore other postgres-specific keywords */
-      if ((0 == strncasecmp (start, "host=", 5)) ||
-          (0 == strncasecmp (start, "port=", 5)) ||
-          (0 == strncasecmp (start, "dbname=", 7)) ||
-          (0 == strncasecmp (start, "authtype=", 9)))
-      {
-         PWARN ("the following message should be shown in a gui");
-         PWARN ("ignoring the postgres keyword %s",
-                start ? start : "(null)");
-      } else
-      {
-         PWARN ("the following message should be shown in a gui");
-         PWARN ("unknown keyword %s, ignoring",
-                start ? start : "(null)");
-      }
-   }
+                        if (0 == strncasecmp (start, "tty=", 4))
+                        {
+                            start = strchr (start, '=') + 1;
+                            pg_tty = start;
+                        }
+                        else
 
+                            /* ignore other postgres-specific keywords */
+                            if ((0 == strncasecmp (start, "host=", 5)) ||
+                                    (0 == strncasecmp (start, "port=", 5)) ||
+                                    (0 == strncasecmp (start, "dbname=", 7)) ||
+                                    (0 == strncasecmp (start, "authtype=", 9)))
+                            {
+                                PWARN ("the following message should be shown in a gui");
+                                PWARN ("ignoring the postgres keyword %s",
+                                       start ? start : "(null)");
+                            }
+                            else
+                            {
+                                PWARN ("the following message should be shown in a gui");
+                                PWARN ("unknown keyword %s, ignoring",
+                                       start ? start : "(null)");
+                            }
+    }
 
-   /* handle localhost as a special case */
-   if (!safe_strcmp("localhost", be->hostname))
-   {
-      g_free (be->hostname);
-      be->hostname = NULL;
-   }
 
-   /* ---------------------------------------------------------------- */
-   /* New login algorithm.  If we haven't been told that we'll
-    * need to be creating a database, then lets try to connect,
-    * and see if that succeeds.  If it fails, we'll tell gui
-    * to ask user if the DB needs to be created.
-    */
-   if (FALSE == create_new_db) 
-   {
-      be->connection = PQsetdbLogin (be->hostname, 
-                                     be->portno,
-                                     pg_options, /* trace/debug options */
-                                     pg_tty, /* file or tty for debug output */
-                                     be->dbName, 
-                                     be->username,  /* login */
-                                     password);  /* pwd */
+    /* handle localhost as a special case */
+    if (!safe_strcmp("localhost", be->hostname))
+    {
+        g_free (be->hostname);
+        be->hostname = NULL;
+    }
 
-      /* check the connection status */
-      if (CONNECTION_BAD == PQstatus(be->connection))
-      {
+    /* ---------------------------------------------------------------- */
+    /* New login algorithm.  If we haven't been told that we'll
+     * need to be creating a database, then lets try to connect,
+     * and see if that succeeds.  If it fails, we'll tell gui
+     * to ask user if the DB needs to be created.
+     */
+    if (FALSE == create_new_db)
+    {
+        be->connection = PQsetdbLogin (be->hostname,
+                                       be->portno,
+                                       pg_options, /* trace/debug options */
+                                       pg_tty, /* file or tty for debug output */
+                                       be->dbName,
+                                       be->username,  /* login */
+                                       password);  /* pwd */
 
-         PINFO("Connection to database '%s' failed:\n"
-               "\t%s", 
-               be->dbName ? be->dbName : "(null)",
-               PQerrorMessage(be->connection));
-   
-         PQfinish (be->connection);
-   
-         /* The connection may have failed either because the 
-          * database doesn't exist, or because there was a 
-          * network problem, or because the user supplied a 
-          * bad password or username. Try to tell these apart.
-          */
-         be->connection = PQsetdbLogin (be->hostname,
-                                  be->portno,
-                                  pg_options, /* trace/debug options */
-                                  pg_tty, /* file or tty for debug output */
-                                  "template1",
-                                  be->username,  /* login */
-                                  password);  /* pwd */
+        /* check the connection status */
+        if (CONNECTION_BAD == PQstatus(be->connection))
+        {
 
-         /* check the connection status */
-         if (CONNECTION_BAD == PQstatus(be->connection))
-         {
-            char * msg = PQerrorMessage(be->connection);
-            PWARN("Connection to database 'template1' failed:\n"
-                  "\t%s", msg);
-      
+            PINFO("Connection to database '%s' failed:\n"
+                  "\t%s",
+                  be->dbName ? be->dbName : "(null)",
+                  PQerrorMessage(be->connection));
+
             PQfinish (be->connection);
-            be->connection = NULL;
-      
-            /* I wish that postgres returned usable error codes. 
-             * Alas, it does not, so we just bomb out.
+
+            /* The connection may have failed either because the
+             * database doesn't exist, or because there was a
+             * network problem, or because the user supplied a
+             * bad password or username. Try to tell these apart.
              */
-            qof_backend_set_error (&be->be, ERR_BACKEND_CANT_CONNECT);
-            qof_backend_set_message(&be->be, _("From the Postgresql Server: %s"), msg);
-            return;
-         }
+            be->connection = PQsetdbLogin (be->hostname,
+                                           be->portno,
+                                           pg_options, /* trace/debug options */
+                                           pg_tty, /* file or tty for debug output */
+                                           "template1",
+                                           be->username,  /* login */
+                                           password);  /* pwd */
 
-         /* If we are here, then we've successfully connected to the
-          * server.  Now, check to see if database exists */
-         p = be->buff; *p = 0;
-         p = stpcpy (p, "SELECT datname FROM pg_database "
+            /* check the connection status */
+            if (CONNECTION_BAD == PQstatus(be->connection))
+            {
+                char * msg = PQerrorMessage(be->connection);
+                PWARN("Connection to database 'template1' failed:\n"
+                      "\t%s", msg);
+
+                PQfinish (be->connection);
+                be->connection = NULL;
+
+                /* I wish that postgres returned usable error codes.
+                 * Alas, it does not, so we just bomb out.
+                 */
+                qof_backend_set_error (&be->be, ERR_BACKEND_CANT_CONNECT);
+                qof_backend_set_message(&be->be, _("From the Postgresql Server: %s"), msg);
+                return;
+            }
+
+            /* If we are here, then we've successfully connected to the
+             * server.  Now, check to see if database exists */
+            p = be->buff;
+            *p = 0;
+            p = stpcpy (p, "SELECT datname FROM pg_database "
                         " WHERE datname='");
-         p = stpcpy (p, be->dbName);
-         p = stpcpy (p, "';");
+            p = stpcpy (p, be->dbName);
+            p = stpcpy (p, "';");
 
-         SEND_QUERY (be,be->buff, );
-         db_exists = GPOINTER_TO_INT(pgendGetResults(be, has_results_cb,
-                                                     GINT_TO_POINTER (FALSE)));
+            SEND_QUERY (be, be->buff, );
+            db_exists = GPOINTER_TO_INT(pgendGetResults(be, has_results_cb,
+                                        GINT_TO_POINTER (FALSE)));
 
-         PQfinish (be->connection);
-         be->connection = NULL;
+            PQfinish (be->connection);
+            be->connection = NULL;
 
-         if (db_exists)
-         {
-            /* Weird.  We couldn't connect to the database, but it 
-             * does seem to exist.  I presume that this is some 
-             * sort of access control problem. */
-            qof_backend_set_error (&be->be, ERR_BACKEND_PERM);
+            if (db_exists)
+            {
+                /* Weird.  We couldn't connect to the database, but it
+                 * does seem to exist.  I presume that this is some
+                 * sort of access control problem. */
+                qof_backend_set_error (&be->be, ERR_BACKEND_PERM);
+                return;
+            }
+
+            /* Let GUI know that we connected, but we couldn't find it. */
+            qof_backend_set_error (&be->be, ERR_BACKEND_NO_SUCH_DB);
             return;
-         }
+        }
 
-         /* Let GUI know that we connected, but we couldn't find it. */
-         qof_backend_set_error (&be->be, ERR_BACKEND_NO_SUCH_DB);
-         return;
-      }
+        /* Check to see if we have a database version that we can
+         * live with */
+        rc = pgendDBVersionIsCurrent (be);
+        if (rc < 0)
+        {
+            /* The server is newer than we are, or another error occured,
+             * we don't know how to talk to it.  The err code is already set. */
+            PQfinish (be->connection);
+            be->connection = NULL;
+            return;
+        }
+        if (rc > 0)
+        {
+            /* The server is older than we are; ask user if they want to
+             * upgrade the database contents. */
+            PQfinish (be->connection);
+            be->connection = NULL;
+            qof_backend_set_error (&be->be, ERR_SQL_DB_TOO_OLD);
+            return;
+        }
+    }
+    else
+    {
+        /* If we are here, then we've been asked to create the
+         * database.  Well, lets do that.  But first make sure
+         * it really doesn't exist */
 
-      /* Check to see if we have a database version that we can 
-       * live with */
-      rc = pgendDBVersionIsCurrent (be);
-      if (rc < 0)
-      {
-         /* The server is newer than we are, or another error occured,
-          * we don't know how to talk to it.  The err code is already set. */
-         PQfinish (be->connection);
-         be->connection = NULL;
-         return;
-      }
-      if (rc > 0)
-      {
-         /* The server is older than we are; ask user if they want to 
-          * upgrade the database contents. */
-         PQfinish (be->connection);
-         be->connection = NULL;
-         qof_backend_set_error (&be->be, ERR_SQL_DB_TOO_OLD);
-         return;
-      }
-   }
-   else 
-   {
-      /* If we are here, then we've been asked to create the
-       * database.  Well, lets do that.  But first make sure 
-       * it really doesn't exist */
+        be->connection = PQsetdbLogin (be->hostname,
+                                       be->portno,
+                                       pg_options, /* trace/debug options */
+                                       pg_tty, /* file or tty for debug output */
+                                       "template1",
+                                       be->username,  /* login */
+                                       password);  /* pwd */
 
-      be->connection = PQsetdbLogin (be->hostname,
-                                  be->portno,
-                                  pg_options, /* trace/debug options */
-                                  pg_tty, /* file or tty for debug output */
-                                  "template1",
-                                  be->username,  /* login */
-                                  password);  /* pwd */
+        /* check the connection status */
+        if (CONNECTION_BAD == PQstatus(be->connection))
+        {
+            PERR("Connection to database '%s' failed:\n"
+                 "\t%s",
+                 be->dbName ? be->dbName : "(null)",
+                 PQerrorMessage(be->connection));
 
-      /* check the connection status */
-      if (CONNECTION_BAD == PQstatus(be->connection))
-      {
-         PERR("Connection to database '%s' failed:\n"
-              "\t%s", 
-              be->dbName ? be->dbName : "(null)",
-              PQerrorMessage(be->connection));
-   
-         PQfinish (be->connection);
-         be->connection = NULL;
-   
-         /* I wish that postgres returned usable error codes. 
-          * Alas, it does not, so we just bomb out.
-          */
-         qof_backend_set_error (&be->be, ERR_BACKEND_CANT_CONNECT);
-         return;
-      }
-      
-      /* If we are here, then we've successfully connected to the
-       * server.  Now, check to see if database exists */
-      p = be->buff; *p = 0;
-      p = stpcpy (p, "SELECT datname FROM pg_database "
-                            " WHERE datname='");
-      p = stpcpy (p, be->dbName);
-      p = stpcpy (p, "';");
+            PQfinish (be->connection);
+            be->connection = NULL;
 
-      SEND_QUERY (be,be->buff, );
-      db_exists = GPOINTER_TO_INT (pgendGetResults (be, has_results_cb,
-                                                    GINT_TO_POINTER (FALSE)));
+            /* I wish that postgres returned usable error codes.
+             * Alas, it does not, so we just bomb out.
+             */
+            qof_backend_set_error (&be->be, ERR_BACKEND_CANT_CONNECT);
+            return;
+        }
 
-      if (FALSE == db_exists)
-      {
+        /* If we are here, then we've successfully connected to the
+         * server.  Now, check to see if database exists */
+        p = be->buff;
+        *p = 0;
+        p = stpcpy (p, "SELECT datname FROM pg_database "
+                    " WHERE datname='");
+        p = stpcpy (p, be->dbName);
+        p = stpcpy (p, "';");
+
+        SEND_QUERY (be, be->buff, );
+        db_exists = GPOINTER_TO_INT (pgendGetResults (be, has_results_cb,
+                                     GINT_TO_POINTER (FALSE)));
+
+        if (FALSE == db_exists)
+        {
 #if HAVE_LANGINFO_CODESET
-         char* encoding = nl_langinfo(CODESET);
+            char* encoding = nl_langinfo(CODESET);
 #else
-		 char* encoding = "SQL_ASCII";	 
+            char* encoding = "SQL_ASCII";
 #endif
-         if (!strcmp (encoding, "ANSI_X3.4-1968"))
-           encoding = "SQL_ASCII";
+            if (!strcmp (encoding, "ANSI_X3.4-1968"))
+                encoding = "SQL_ASCII";
 
-         /* create the database */
-         p = be->buff; *p =0;
-         p = stpcpy (p, "CREATE DATABASE ");
-         p = stpcpy (p, be->dbName);
-         p = stpcpy (p, " WITH ENCODING = '");
-	 p = stpcpy (p, encoding);
-         p = stpcpy (p, "';");
-         SEND_QUERY (be,be->buff, );
-         FINISH_QUERY(be->connection);
-         PQfinish (be->connection);
+            /* create the database */
+            p = be->buff;
+            *p = 0;
+            p = stpcpy (p, "CREATE DATABASE ");
+            p = stpcpy (p, be->dbName);
+            p = stpcpy (p, " WITH ENCODING = '");
+            p = stpcpy (p, encoding);
+            p = stpcpy (p, "';");
+            SEND_QUERY (be, be->buff, );
+            FINISH_QUERY(be->connection);
+            PQfinish (be->connection);
 
-         /* now connect to the newly created database */
-         be->connection = PQsetdbLogin (be->hostname, 
-                                  be->portno,
-                                  pg_options, /* trace/debug options */
-                                  pg_tty, /* file or tty for debug output */
-                                  be->dbName, 
-                                  be->username,  /* login */
-                                  password);  /* pwd */
+            /* now connect to the newly created database */
+            be->connection = PQsetdbLogin (be->hostname,
+                                           be->portno,
+                                           pg_options, /* trace/debug options */
+                                           pg_tty, /* file or tty for debug output */
+                                           be->dbName,
+                                           be->username,  /* login */
+                                           password);  /* pwd */
 
-         /* check the connection status */
-         if (CONNECTION_BAD == PQstatus(be->connection))
-         {
-            PERR("Can't connect to the newly created database '%s':\n"
-                 "\t%s", 
-                 be->dbName ? be->dbName : "(null)",
-                 PQerrorMessage(be->connection));
-            PQfinish (be->connection);
-            be->connection = NULL;
-            /* We just created the database! If we can't connect now, 
-             * the server is insane! */
-            qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);
-            return;
-         }
+            /* check the connection status */
+            if (CONNECTION_BAD == PQstatus(be->connection))
+            {
+                PERR("Can't connect to the newly created database '%s':\n"
+                     "\t%s",
+                     be->dbName ? be->dbName : "(null)",
+                     PQerrorMessage(be->connection));
+                PQfinish (be->connection);
+                be->connection = NULL;
+                /* We just created the database! If we can't connect now,
+                 * the server is insane! */
+                qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);
+                return;
+            }
 
-         /* Finally, create all the tables and indexes. */
-         pgend_create_db (be);
-      }
-      else 
-      {
-         gboolean gncaccount_exists;
+            /* Finally, create all the tables and indexes. */
+            pgend_create_db (be);
+        }
+        else
+        {
+            gboolean gncaccount_exists;
 
-         /* Database exists, although we were asked to create it.
-          * We interpret this to mean that either it's downlevel,
-          * and user wants us to upgrade it, or we are installing
-          * gnucash tables into an existing database. So do one or
-          * the other. */
+            /* Database exists, although we were asked to create it.
+             * We interpret this to mean that either it's downlevel,
+             * and user wants us to upgrade it, or we are installing
+             * gnucash tables into an existing database. So do one or
+             * the other. */
 
-         PQfinish (be->connection);
-
-         /* Connect to the database */
-         be->connection = PQsetdbLogin (be->hostname, 
-                                  be->portno,
-                                  pg_options, /* trace/debug options */
-                                  pg_tty, /* file or tty for debug output */
-                                  be->dbName, 
-                                  be->username,  /* login */
-                                  password);  /* pwd */
-         
-         /* check the connection status */
-         if (CONNECTION_BAD == PQstatus(be->connection))
-         {
-            PINFO("Can't connect to the database '%s':\n"
-                 "\t%s", 
-                 be->dbName ? be->dbName : "(null)",
-                 PQerrorMessage(be->connection));
             PQfinish (be->connection);
-            be->connection = NULL;
 
-            /* Well, if we are here, we were connecting just fine,
-             * just not to this database. Therefore, it must be a 
-             * permission problem.
-             */
-            qof_backend_set_error (&be->be, ERR_BACKEND_PERM);
-            return;
-         }
+            /* Connect to the database */
+            be->connection = PQsetdbLogin (be->hostname,
+                                           be->portno,
+                                           pg_options, /* trace/debug options */
+                                           pg_tty, /* file or tty for debug output */
+                                           be->dbName,
+                                           be->username,  /* login */
+                                           password);  /* pwd */
 
-         /* See if the gncaccount table exists. If it does not,
-          * create all the tables. We assume that there will always
-          * be a gncaccount table. */
-         p = "SELECT tablename FROM pg_tables WHERE tablename='gncaccount';";
-         SEND_QUERY (be,p, );
-         gncaccount_exists =
-           GPOINTER_TO_INT (pgendGetResults (be, has_results_cb, FALSE));
+            /* check the connection status */
+            if (CONNECTION_BAD == PQstatus(be->connection))
+            {
+                PINFO("Can't connect to the database '%s':\n"
+                      "\t%s",
+                      be->dbName ? be->dbName : "(null)",
+                      PQerrorMessage(be->connection));
+                PQfinish (be->connection);
+                be->connection = NULL;
 
-         if (!gncaccount_exists)
-         {
-           pgend_create_db (be);
-         }
-         else
-         {
-           rc = pgendDBVersionIsCurrent (be);
-           if (0 > rc)
-           {
-             /* The server is newer than we are, or another error
-              * occured, we don't know how to talk to it. The err
-              * code is already set. */
-             PQfinish (be->connection);
-             be->connection = NULL;
-             return;
-           }
-           if (0 < rc)
-           {
-             gboolean someones_still_on;
-             /* The server is older than we are; lets upgrade */
-             /* But first, make sure all users are logged off ... */
-             p = "BEGIN;\n"
-               "LOCK TABLE gncSession IN ACCESS EXCLUSIVE MODE;\n"
-               "SELECT time_off FROM gncSession WHERE time_off ='infinity';\n";
-             SEND_QUERY (be,p, );
-             someones_still_on =
-               GPOINTER_TO_INT (pgendGetResults (be, has_results_cb,
-                                                 GINT_TO_POINTER (FALSE)));
-             if (someones_still_on)
-             {
-               p = "COMMIT;\n";
-               SEND_QUERY (be,p, );
-               FINISH_QUERY(be->connection);
-               qof_backend_set_error (&be->be, ERR_SQL_DB_BUSY);
-               return;
-             }
-             p = "COMMIT;\n";
-             SEND_QUERY (be,p, );
-             FINISH_QUERY(be->connection);
-             pgendUpgradeDB (be);
-           }
-           else
-           {
-             /* Wierd. We were asked to create something that exists.
-              * This shouldn't really happen ... */
-             PWARN ("Asked to create the database %s,\n"
-                    "\tbut it already exists!\n"
-                    "\tThis shouldn't really happen.",
-                    be->dbName);
-           }
-         }
-      }
-   }
+                /* Well, if we are here, we were connecting just fine,
+                 * just not to this database. Therefore, it must be a
+                 * permission problem.
+                 */
+                qof_backend_set_error (&be->be, ERR_BACKEND_PERM);
+                return;
+            }
 
-   /* free url only after login completed */
-   g_free(url);
+            /* See if the gncaccount table exists. If it does not,
+             * create all the tables. We assume that there will always
+             * be a gncaccount table. */
+            p = "SELECT tablename FROM pg_tables WHERE tablename='gncaccount';";
+            SEND_QUERY (be, p, );
+            gncaccount_exists =
+                GPOINTER_TO_INT (pgendGetResults (be, has_results_cb, FALSE));
 
-   /* ---------------------------------------------------------------- */
+            if (!gncaccount_exists)
+            {
+                pgend_create_db (be);
+            }
+            else
+            {
+                rc = pgendDBVersionIsCurrent (be);
+                if (0 > rc)
+                {
+                    /* The server is newer than we are, or another error
+                     * occured, we don't know how to talk to it. The err
+                     * code is already set. */
+                    PQfinish (be->connection);
+                    be->connection = NULL;
+                    return;
+                }
+                if (0 < rc)
+                {
+                    gboolean someones_still_on;
+                    /* The server is older than we are; lets upgrade */
+                    /* But first, make sure all users are logged off ... */
+                    p = "BEGIN;\n"
+                        "LOCK TABLE gncSession IN ACCESS EXCLUSIVE MODE;\n"
+                        "SELECT time_off FROM gncSession WHERE time_off ='infinity';\n";
+                    SEND_QUERY (be, p, );
+                    someones_still_on =
+                        GPOINTER_TO_INT (pgendGetResults (be, has_results_cb,
+                                                          GINT_TO_POINTER (FALSE)));
+                    if (someones_still_on)
+                    {
+                        p = "COMMIT;\n";
+                        SEND_QUERY (be, p, );
+                        FINISH_QUERY(be->connection);
+                        qof_backend_set_error (&be->be, ERR_SQL_DB_BUSY);
+                        return;
+                    }
+                    p = "COMMIT;\n";
+                    SEND_QUERY (be, p, );
+                    FINISH_QUERY(be->connection);
+                    pgendUpgradeDB (be);
+                }
+                else
+                {
+                    /* Wierd. We were asked to create something that exists.
+                     * This shouldn't really happen ... */
+                    PWARN ("Asked to create the database %s,\n"
+                           "\tbut it already exists!\n"
+                           "\tThis shouldn't really happen.",
+                           be->dbName);
+                }
+            }
+        }
+    }
 
-   /* set the datestyle to something we can parse */
-   p = "SET DATESTYLE='ISO';";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    /* free url only after login completed */
+    g_free(url);
 
+    /* ---------------------------------------------------------------- */
 
-   /* OK, lets see if we can get a valid session */
-   rc = pgendSessionValidate (be, ignore_lock);
+    /* set the datestyle to something we can parse */
+    p = "SET DATESTYLE='ISO';";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   /* set up pointers for appropriate behaviour */
-   if (rc)
-   {
-      switch (be->session_mode)
-      {
-         case MODE_SINGLE_FILE:
+
+    /* OK, lets see if we can get a valid session */
+    rc = pgendSessionValidate (be, ignore_lock);
+
+    /* set up pointers for appropriate behaviour */
+    if (rc)
+    {
+        switch (be->session_mode)
+        {
+        case MODE_SINGLE_FILE:
             pgendEnable(be);
             be->be.load         = pgend_do_load_single;
             be->be.begin        = pgend_do_begin;
@@ -2269,7 +2354,7 @@
                    "there aren't any! We think it's safe to use.\n");
             break;
 
-         case MODE_SINGLE_UPDATE:
+        case MODE_SINGLE_UPDATE:
             pgendEnable(be);
             be->be.load         = pgend_do_load_single;
             be->be.begin        = pgend_do_begin;
@@ -2290,7 +2375,7 @@
                    "there aren't any! We think it's safe to use.\n");
             break;
 
-         case MODE_POLL:
+        case MODE_POLL:
             pgendEnable(be);
             be->be.load         = pgend_book_load_poll;
             be->be.begin		= pgend_do_begin;
@@ -2313,7 +2398,7 @@
                    "there aren't any! If something seems weird, let us know.\n");
             break;
 
-         case MODE_EVENT:
+        case MODE_EVENT:
             pgendEnable(be);
 
             pgendSessionGetPid (be);
@@ -2341,14 +2426,14 @@
 
             break;
 
-         default:
+        default:
             PERR ("bad mode specified");
             break;
-      }
-   }
+        }
+    }
 
-   LEAVE("be=%p, sessionid=%s", be,
-         sessionid ? sessionid : "(null)");
+    LEAVE("be=%p, sessionid=%s", be,
+          sessionid ? sessionid : "(null)");
 }
 
 /* ============================================================= */
@@ -2356,50 +2441,51 @@
 void
 pgendDisable (PGBackend *be)
 {
-   ENTER("be = %p", be);
-   if (0 > be->nest_count)
-   {
-      PERR ("too many nested enables");
-   }
-   be->nest_count ++;
-   PINFO("nest count=%d", be->nest_count);
-   if (1 < be->nest_count) {
-       LEAVE("be->nest_count > 1: %d", be->nest_count); 
-       return;
-   }
+    ENTER("be = %p", be);
+    if (0 > be->nest_count)
+    {
+        PERR ("too many nested enables");
+    }
+    be->nest_count ++;
+    PINFO("nest count=%d", be->nest_count);
+    if (1 < be->nest_count)
+    {
+        LEAVE("be->nest_count > 1: %d", be->nest_count);
+        return;
+    }
 
-   /* save hooks */
-   be->snr.load	                = be->be.load;
-   be->snr.session_end          = be->be.session_end;
-   be->snr.destroy_backend      = be->be.destroy_backend;
-   be->snr.begin	        = be->be.begin;
-   be->snr.commit 	        = be->be.commit;
-   be->snr.rollback	        = be->be.rollback;
-   be->snr.compile_query        = be->be.compile_query;
-   be->snr.run_query            = be->be.run_query;
-   be->snr.price_lookup         = be->be.price_lookup;
-   be->snr.sync                 = be->be.sync;
-   be->snr.export               = be->be.export;
-   be->snr.percentage           = be->be.percentage;
-   be->snr.events_pending       = be->be.events_pending;
-   be->snr.process_events       = be->be.process_events;
+    /* save hooks */
+    be->snr.load	                = be->be.load;
+    be->snr.session_end          = be->be.session_end;
+    be->snr.destroy_backend      = be->be.destroy_backend;
+    be->snr.begin	        = be->be.begin;
+    be->snr.commit 	        = be->be.commit;
+    be->snr.rollback	        = be->be.rollback;
+    be->snr.compile_query        = be->be.compile_query;
+    be->snr.run_query            = be->be.run_query;
+    be->snr.price_lookup         = be->be.price_lookup;
+    be->snr.sync                 = be->be.sync;
+    be->snr.export               = be->be.export;
+    be->snr.percentage           = be->be.percentage;
+    be->snr.events_pending       = be->be.events_pending;
+    be->snr.process_events       = be->be.process_events;
 
-   be->be.load                 = NULL;
-   be->be.session_end          = NULL;
-   be->be.destroy_backend      = NULL;
-   be->be.begin		       = NULL;
-   be->be.commit 	       = NULL;
-   be->be.rollback	       = NULL;
-   be->be.compile_query        = NULL;
-   be->be.run_query            = NULL;
-   be->be.price_lookup         = NULL;
-   be->be.sync                 = NULL;
-   be->be.export               = NULL;
-   be->be.percentage           = NULL;
-   be->be.events_pending       = NULL;
-   be->be.process_events       = NULL;
+    be->be.load                 = NULL;
+    be->be.session_end          = NULL;
+    be->be.destroy_backend      = NULL;
+    be->be.begin		       = NULL;
+    be->be.commit 	       = NULL;
+    be->be.rollback	       = NULL;
+    be->be.compile_query        = NULL;
+    be->be.run_query            = NULL;
+    be->be.price_lookup         = NULL;
+    be->be.sync                 = NULL;
+    be->be.export               = NULL;
+    be->be.percentage           = NULL;
+    be->be.events_pending       = NULL;
+    be->be.process_events       = NULL;
 
-   LEAVE(" ");
+    LEAVE(" ");
 }
 
 /* ============================================================= */
@@ -2408,147 +2494,148 @@
 pgendEnable (PGBackend *be)
 {
     ENTER(" ");
-   if (0 >= be->nest_count)
-   {
-      PERR ("too many nested disables");
-   }
-   be->nest_count --;
-   PINFO("nest count=%d", be->nest_count);
-   if (be->nest_count) return;
+    if (0 >= be->nest_count)
+    {
+        PERR ("too many nested disables");
+    }
+    be->nest_count --;
+    PINFO("nest count=%d", be->nest_count);
+    if (be->nest_count) return;
 
-   /* restore hooks */
-   be->be.load                 = be->snr.load;
-   be->be.session_end          = be->snr.session_end;
-   be->be.destroy_backend      = be->snr.destroy_backend;
-   be->be.begin  	       = be->snr.begin;
-   be->be.commit 	       = be->snr.commit;
-   be->be.rollback  	       = be->snr.rollback;
-   be->be.compile_query        = be->snr.compile_query;
-   be->be.run_query            = be->snr.run_query;
-   be->be.price_lookup         = be->snr.price_lookup;
-   be->be.sync                 = be->snr.sync;
-   be->be.export               = be->snr.export;
-   be->be.percentage           = be->snr.percentage;
-   be->be.events_pending       = be->snr.events_pending;
-   be->be.process_events       = be->snr.process_events;
+    /* restore hooks */
+    be->be.load                 = be->snr.load;
+    be->be.session_end          = be->snr.session_end;
+    be->be.destroy_backend      = be->snr.destroy_backend;
+    be->be.begin  	       = be->snr.begin;
+    be->be.commit 	       = be->snr.commit;
+    be->be.rollback  	       = be->snr.rollback;
+    be->be.compile_query        = be->snr.compile_query;
+    be->be.run_query            = be->snr.run_query;
+    be->be.price_lookup         = be->snr.price_lookup;
+    be->be.sync                 = be->snr.sync;
+    be->be.export               = be->snr.export;
+    be->be.percentage           = be->snr.percentage;
+    be->be.events_pending       = be->snr.events_pending;
+    be->be.process_events       = be->snr.process_events;
 
-   LEAVE(" ");
+    LEAVE(" ");
 }
 
 /* ============================================================= */
-/* The pgendInit() routine initializes the backend private 
+/* The pgendInit() routine initializes the backend private
  *    structures, mallocs any needed memory, etc.
  */
 
-static void 
+static void
 pgendInit (PGBackend *be)
 {
-   int i;
-   Timespec ts;
+    int i;
+    Timespec ts;
 
-   ENTER(" ");
-   
-   /* initialize global variable */
-   nullguid = *(guid_null());
+    ENTER(" ");
 
-   /* access mode */
-   be->session_mode = MODE_EVENT;
-   be->sessionGuid = NULL;
-   guid_to_string_buff (&nullguid, be->session_guid_str);
+    /* initialize global variable */
+    nullguid = *(guid_null());
 
-   /* generic backend handlers */
-   qof_backend_init((QofBackend*)be);
+    /* access mode */
+    be->session_mode = MODE_EVENT;
+    be->sessionGuid = NULL;
+    guid_to_string_buff (&nullguid, be->session_guid_str);
 
-   be->be.session_begin = pgend_session_begin;
-   be->be.session_end = pgend_session_end;
+    /* generic backend handlers */
+    qof_backend_init((QofBackend*)be);
 
-   be->nest_count = 0;
-   pgendDisable(be);
+    be->be.session_begin = pgend_session_begin;
+    be->be.session_end = pgend_session_end;
 
-   be->be.last_err = ERR_BACKEND_NO_ERR;
+    be->nest_count = 0;
+    pgendDisable(be);
 
-   /* postgres specific data */
-   be->hostname = NULL;
-   be->portno = NULL;
-   be->dbName = NULL;
-   be->username = NULL;
-   be->connection = NULL;
-   be->freshly_created_db = FALSE;
-   be->freshly_created_prdb = FALSE;
+    be->be.last_err = ERR_BACKEND_NO_ERR;
 
-   be->my_pid = 0;
-   be->do_account = 0;
-   be->do_book = 0;
-   be->do_checkpoint = 0;
-   be->do_price = 0;
-   be->do_session = 0;
-   be->do_transaction = 0;
+    /* postgres specific data */
+    be->hostname = NULL;
+    be->portno = NULL;
+    be->dbName = NULL;
+    be->username = NULL;
+    be->connection = NULL;
+    be->freshly_created_db = FALSE;
+    be->freshly_created_prdb = FALSE;
 
-   ts.tv_sec = time (0);
-   ts.tv_nsec = 0;
+    be->my_pid = 0;
+    be->do_account = 0;
+    be->do_book = 0;
+    be->do_checkpoint = 0;
+    be->do_price = 0;
+    be->do_session = 0;
+    be->do_transaction = 0;
 
-   be->last_account = ts;
-   be->last_price = ts;
-   be->last_transaction = ts;
+    ts.tv_sec = time (0);
+    ts.tv_nsec = 0;
 
-   be->version_check = (guint32) ts.tv_sec;
+    be->last_account = ts;
+    be->last_price = ts;
+    be->last_transaction = ts;
 
-   be->builder = sqlBuilder_new();
+    be->version_check = (guint32) ts.tv_sec;
 
-   be->buff = g_malloc (QBUFSIZE);
-   be->bufflen = QBUFSIZE;
-   be->nrows = 0;
+    be->builder = sqlBuilder_new();
 
+    be->buff = g_malloc (QBUFSIZE);
+    be->bufflen = QBUFSIZE;
+    be->nrows = 0;
+
 #define INIT_CACHE_SZ 1000
-   be->path_cache = (char **) g_malloc (INIT_CACHE_SZ * sizeof(char *));
-   be->path_cache_size = INIT_CACHE_SZ;
-   for (i=0; i< be->path_cache_size; i++) {
-      (be->path_cache)[i] = NULL;
-   }
-   be->ipath_max = 0;
+    be->path_cache = (char **) g_malloc (INIT_CACHE_SZ * sizeof(char *));
+    be->path_cache_size = INIT_CACHE_SZ;
+    for (i = 0; i < be->path_cache_size; i++)
+    {
+        (be->path_cache)[i] = NULL;
+    }
+    be->ipath_max = 0;
 
-   be->session = NULL;
-   be->book = NULL;
-   be->blist = NULL;
-   LEAVE(" ");
+    be->session = NULL;
+    be->book = NULL;
+    be->blist = NULL;
+    LEAVE(" ");
 }
 
 /* ============================================================= */
 
-QofBackend * 
+QofBackend *
 pgendNew (void)
 {
-   PGBackend *be;
+    PGBackend *be;
 
-   ENTER(" ");
-   be = g_new0 (PGBackend, 1);
-   pgendInit (be);
+    ENTER(" ");
+    be = g_new0 (PGBackend, 1);
+    pgendInit (be);
 
-   LEAVE(" ");
-   return (QofBackend *) be;
+    LEAVE(" ");
+    return (QofBackend *) be;
 }
 
 static void
 pg_provider_free (QofBackendProvider *prov)
 {
-        prov->provider_name = NULL;
-        prov->access_method = NULL;
-        g_free (prov);
+    prov->provider_name = NULL;
+    prov->access_method = NULL;
+    g_free (prov);
 }
 
 G_MODULE_EXPORT void
 qof_backend_module_init(void)
 {
-	QofBackendProvider *prov;
+    QofBackendProvider *prov;
 
-	prov = g_new0(QofBackendProvider, 1);
-	prov->provider_name = "The Postgres backend for GnuCash";
-	prov->access_method = "postgres";
-	prov->partial_book_supported = FALSE;
-	prov->backend_new = pgendNew;
-	prov->provider_free = pg_provider_free;
-	prov->check_data_type = NULL;
-	qof_backend_register_provider (prov);
+    prov = g_new0(QofBackendProvider, 1);
+    prov->provider_name = "The Postgres backend for GnuCash";
+    prov->access_method = "postgres";
+    prov->partial_book_supported = FALSE;
+    prov->backend_new = pgendNew;
+    prov->provider_free = pg_provider_free;
+    prov->check_data_type = NULL;
+    qof_backend_register_provider (prov);
 }
 
 /* ======================== END OF FILE ======================== */

Modified: gnucash/trunk/src/backend/postgres/PostgresBackend.h
===================================================================
--- gnucash/trunk/src/backend/postgres/PostgresBackend.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/PostgresBackend.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -19,7 +19,7 @@
  * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
 \********************************************************************/
 
-/* 
+/*
  * FILE:
  * PostgresBackend.h
  *
@@ -47,76 +47,78 @@
 
 typedef struct _pgend PGBackend;
 
-typedef enum {
-   MODE_NONE = 0,
-   MODE_SINGLE_FILE =1,
-   MODE_SINGLE_UPDATE,
-   MODE_POLL,
-   MODE_EVENT
+typedef enum
+{
+    MODE_NONE = 0,
+    MODE_SINGLE_FILE = 1,
+    MODE_SINGLE_UPDATE,
+    MODE_POLL,
+    MODE_EVENT
 } AccessMode;
 
 #define MAX_VERSION_AGE 10
 
 #include "qofbackend-p.h"
-struct _pgend {
-   QofBackend be;
+struct _pgend
+{
+    QofBackend be;
 
-   /* session mode */
-   AccessMode session_mode;
-   GUID *sessionGuid;
-   char session_guid_str[GUID_ENCODING_LENGTH+1];
+    /* session mode */
+    AccessMode session_mode;
+    GUID *sessionGuid;
+    char session_guid_str[GUID_ENCODING_LENGTH+1];
 
-   /* sql query compiler */
-   sqlBuilder *builder;
+    /* sql query compiler */
+    sqlBuilder *builder;
 
-   /* postgres-specific connection data */
-   char * hostname;
-   char * portno;
-   char * username;
-   char * dbName;
-   PGconn * connection;
-   gboolean freshly_created_db;
-   gboolean freshly_created_prdb;
+    /* postgres-specific connection data */
+    char * hostname;
+    char * portno;
+    char * username;
+    char * dbName;
+    PGconn * connection;
+    gboolean freshly_created_db;
+    gboolean freshly_created_prdb;
 
-   /* counter used to nest callback disables */
-   int nest_count;
-   /* callback hooks are saved in snr during disables */
-   QofBackend snr;    
+    /* counter used to nest callback disables */
+    int nest_count;
+    /* callback hooks are saved in snr during disables */
+    QofBackend snr;
 
-   /* my postgres backend pid, used for telling apart notifies */
-   int my_pid;
+    /* my postgres backend pid, used for telling apart notifies */
+    int my_pid;
 
-   /* notify counters */
-   int do_account;
-   int do_book;
-   int do_checkpoint;
-   int do_price;
-   int do_session;
-   int do_transaction;
+    /* notify counters */
+    int do_account;
+    int do_book;
+    int do_checkpoint;
+    int do_price;
+    int do_session;
+    int do_transaction;
 
-   /* notify dates */
-   Timespec last_account;
-   Timespec last_price;
-   Timespec last_transaction;
+    /* notify dates */
+    Timespec last_account;
+    Timespec last_price;
+    Timespec last_transaction;
 
-   guint32 version_check; /* data aging timestamp */
+    guint32 version_check; /* data aging timestamp */
 
-   /* scratch space for constructing queries */ 
-   int bufflen;
-   char *buff;
-   int nrows;  /* number of rows in query result */
+    /* scratch space for constructing queries */
+    int bufflen;
+    char *buff;
+    int nrows;  /* number of rows in query result */
 
-   /* kvp path cache */
-   char **path_cache;
-   int path_cache_size;
-   int ipath_max;
+    /* kvp path cache */
+    char **path_cache;
+    int path_cache_size;
+    int ipath_max;
 
-   /* engine data caches */
-   QofSession *session;
-   QofBook *book;  /* the currently open book -- XXX -- depricate ???*/
-   QofBookList *blist;  /* list of books in this db */
+    /* engine data caches */
+    QofSession *session;
+    QofBook *book;  /* the currently open book -- XXX -- depricate ???*/
+    QofBookList *blist;  /* list of books in this db */
 
-   GList *tmp_return;
+    GList *tmp_return;
 };
 
 /*

Modified: gnucash/trunk/src/backend/postgres/account.c
===================================================================
--- gnucash/trunk/src/backend/postgres/account.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/account.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -23,11 +23,11 @@
 #include "config.h"
 
 #include <glib.h>
-#include <stdlib.h>  
-#include <string.h>  
+#include <stdlib.h>
+#include <string.h>
 
-#include <libpq-fe.h>  
- 
+#include <libpq-fe.h>
+
 #include "AccountP.h"
 #include "qof.h"
 #include "gnc-commodity.h"
@@ -40,7 +40,7 @@
 #include "PostgresBackend.h"
 #include "price.h"
 
-static QofLogModule log_module = GNC_MOD_BACKEND; 
+static QofLogModule log_module = GNC_MOD_BACKEND;
 
 #include "putil.h"
 
@@ -52,89 +52,89 @@
 /* ============================================================= */
 
 /* ============================================================= */
-/* the pgendStoreAccount() routine stores an account to the 
- * database.  That is, the engine data is written out to the 
- * database.  It does not do any of the account children; nor 
- * does it handle any of the splits or transactions associated 
- * with the account.  It does, however, store the associated 
- * commodity. 
+/* the pgendStoreAccount() routine stores an account to the
+ * database.  That is, the engine data is written out to the
+ * database.  It does not do any of the account children; nor
+ * does it handle any of the splits or transactions associated
+ * with the account.  It does, however, store the associated
+ * commodity.
  *
  * If do_mark is set to TRUE, then this routine sets a mark
  * to terminate recursion.  That is,  it will only store the
- * account once; a second call on a marked account will simply 
+ * account once; a second call on a marked account will simply
  * return.  Be sure to clear the mark when done!
  *
  * If the do_check_version flag is set, then this routine
  * will compare the engine and sql db version numbrs, and
- * perform the store only if the engine version is equal 
+ * perform the store only if the engine version is equal
  * or newer than the sql version.
  *
- * This routine doesn't perform any locks, and shouldn't be 
+ * This routine doesn't perform any locks, and shouldn't be
  * used outside of locks,
  */
 
 static void
 pgendStoreAccountNoLock (PGBackend *be, Account *acct,
-                         gboolean do_mark, 
+                         gboolean do_mark,
                          gboolean do_check_version)
 {
-   const gnc_commodity *com;
-   guint32 a_idata;
+    const gnc_commodity *com;
+    guint32 a_idata;
 
-   if (!be || !acct) return;
-   if ((FALSE == do_mark) && (!qof_instance_get_dirty_flag(acct)))
-     return;
+    if (!be || !acct) return;
+    if ((FALSE == do_mark) && (!qof_instance_get_dirty_flag(acct)))
+        return;
 
-   ENTER ("acct=%p, mark=%d", acct, do_mark);
+    ENTER ("acct=%p, mark=%d", acct, do_mark);
 
-   if (do_mark) 
-   { 
-      /* Check to see if we've processed this account recently.
-       * If so, then return.  The goal here is to avoid excess
-       * hits to the database, leading to poor performance.
-       * Note that this marking makes this routine unsafe to use 
-       * outside a lock (since we never clear the mark)
-       */
-      if (xaccAccountGetMark (acct)) return;
-      xaccAccountSetMark (acct, 1);
-   }
+    if (do_mark)
+    {
+        /* Check to see if we've processed this account recently.
+         * If so, then return.  The goal here is to avoid excess
+         * hits to the database, leading to poor performance.
+         * Note that this marking makes this routine unsafe to use
+         * outside a lock (since we never clear the mark)
+         */
+        if (xaccAccountGetMark (acct)) return;
+        xaccAccountSetMark (acct, 1);
+    }
 
-   if (do_check_version)
-   {
-     if (0 < pgendAccountCompareVersion (be, acct)) return;
-   }
-  /* be sure to update the version !! */
-   qof_instance_increment_version(acct, be->version_check);
+    if (do_check_version)
+    {
+        if (0 < pgendAccountCompareVersion (be, acct)) return;
+    }
+    /* be sure to update the version !! */
+    qof_instance_increment_version(acct, be->version_check);
 
-   a_idata = qof_instance_get_idata(acct);
-   if ((0 == a_idata) &&
-       (FALSE == kvp_frame_is_empty (xaccAccountGetSlots(acct))))
-   {
-      a_idata = pgendNewGUIDidx(be);
-      qof_instance_set_idata(acct, a_idata);
-   }
+    a_idata = qof_instance_get_idata(acct);
+    if ((0 == a_idata) &&
+            (FALSE == kvp_frame_is_empty (xaccAccountGetSlots(acct))))
+    {
+        a_idata = pgendNewGUIDidx(be);
+        qof_instance_set_idata(acct, a_idata);
+    }
 
-   pgendPutOneAccountOnly (be, acct);
+    pgendPutOneAccountOnly (be, acct);
 
-   /* make sure the account's commodity is in the commodity table */
+    /* make sure the account's commodity is in the commodity table */
 
-   /* XXX hack alert FIXME -- it would be more efficient to do 
-    * this elsewhere, and not here. Furthermore, with this method
-    * the transaction currencies must be stored in the same way,
-    * as the transactions are traversed individually, and that
-    * is even more inefficient.
-    *
-    * See StoreAllPrices for an example of how to do this. 
-    */
-   com = xaccAccountGetCommodity (acct);
-   pgendPutOneCommodityOnly (be, (gnc_commodity *) com);
+    /* XXX hack alert FIXME -- it would be more efficient to do
+     * this elsewhere, and not here. Furthermore, with this method
+     * the transaction currencies must be stored in the same way,
+     * as the transactions are traversed individually, and that
+     * is even more inefficient.
+     *
+     * See StoreAllPrices for an example of how to do this.
+     */
+    com = xaccAccountGetCommodity (acct);
+    pgendPutOneCommodityOnly (be, (gnc_commodity *) com);
 
-   if (a_idata)
-   {
-      pgendKVPDelete (be, a_idata);
-      pgendKVPStore (be, a_idata, acct->inst.kvp_data);
-   }
-   LEAVE(" ");
+    if (a_idata)
+    {
+        pgendKVPDelete (be, a_idata);
+        pgendKVPStore (be, a_idata, acct->inst.kvp_data);
+    }
+    LEAVE(" ");
 }
 
 /* ============================================================= */
@@ -144,60 +144,60 @@
  * commodities associated with the accounts.  It does *not* store
  * any of the transactions.
  *
- * Note that it checks the version numbers, and only stores 
- * those accounts whose version number is equal or newer than 
+ * Note that it checks the version numbers, and only stores
+ * those accounts whose version number is equal or newer than
  * what's in the DB.
  *
  * The NoLock version doesn't lock up the tables.
  */
 
 void
-pgendStoreAccountTreeNoLock (PGBackend *be, Account *root, 
-                       gboolean do_mark, gboolean do_check_version)
+pgendStoreAccountTreeNoLock (PGBackend *be, Account *root,
+                             gboolean do_mark, gboolean do_check_version)
 {
-   GList *descendants, *node;
+    GList *descendants, *node;
 
-   if (!be || !root) return;
-   ENTER("root=%p mark=%d", root, do_mark);
+    if (!be || !root) return;
+    ENTER("root=%p mark=%d", root, do_mark);
 
-   /* walk the account tree, and store subaccounts */
-   pgendStoreAccountNoLock (be, root, do_mark, do_check_version);
-   descendants = gnc_account_get_descendants (root);
-   for (node=descendants; node; node=node->next) 
-      pgendStoreAccountNoLock (be, node->data, do_mark, do_check_version);
-   g_list_free(descendants);
-   LEAVE(" ");
+    /* walk the account tree, and store subaccounts */
+    pgendStoreAccountNoLock (be, root, do_mark, do_check_version);
+    descendants = gnc_account_get_descendants (root);
+    for (node = descendants; node; node = node->next)
+        pgendStoreAccountNoLock (be, node->data, do_mark, do_check_version);
+    g_list_free(descendants);
+    LEAVE(" ");
 }
 
 
 void
 pgendStoreAccountTree (PGBackend *be, Account *root)
 {
-   char *p;
-   ENTER ("be=%p, root=%p", be, root);
-   if (!be || !root) return;
+    char *p;
+    ENTER ("be=%p, root=%p", be, root);
+    if (!be || !root) return;
 
-   /* lock it up so that we store atomically */
-   p = "BEGIN;\n"
-       "LOCK TABLE gncAccount IN EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncCommodity IN EXCLUSIVE MODE;\n";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    /* lock it up so that we store atomically */
+    p = "BEGIN;\n"
+        "LOCK TABLE gncAccount IN EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncCommodity IN EXCLUSIVE MODE;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   /* Clear the account marks; this is used to avoid visiting
-    * the same account more than once. */
-   xaccClearMarkDown (root, 0);
+    /* Clear the account marks; this is used to avoid visiting
+     * the same account more than once. */
+    xaccClearMarkDown (root, 0);
 
-   pgendStoreAccountTreeNoLock (be, root, TRUE, TRUE);
+    pgendStoreAccountTreeNoLock (be, root, TRUE, TRUE);
 
-   /* reset the write flags again */
-   xaccClearMarkDown (root, 0);
+    /* reset the write flags again */
+    xaccClearMarkDown (root, 0);
 
-   p = "COMMIT;\n"
-       "NOTIFY gncAccount;";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
-   LEAVE(" ");
+    p = "COMMIT;\n"
+        "NOTIFY gncAccount;";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+    LEAVE(" ");
 }
 
 /* ============================================================= */
@@ -210,23 +210,23 @@
 static void
 restore_cb (Account *acc, void * cb_data)
 {
-   PGBackend *be = (PGBackend *) cb_data;
-   guint32 a_idata = qof_instance_get_idata(acc);
-   if (0 == a_idata) return;
-   acc->inst.kvp_data = pgendKVPFetch (be, a_idata, acc->inst.kvp_data);
+    PGBackend *be = (PGBackend *) cb_data;
+    guint32 a_idata = qof_instance_get_idata(acc);
+    if (0 == a_idata) return;
+    acc->inst.kvp_data = pgendKVPFetch (be, a_idata, acc->inst.kvp_data);
 }
 
-static void 
+static void
 pgendGetAllAccountKVP (PGBackend *be, Account *root)
 {
-   if (!root) return;
+    if (!root) return;
 
-   restore_cb(root, NULL);
-   gnc_account_foreach_descendant(root, restore_cb, be);
+    restore_cb(root, NULL);
+    gnc_account_foreach_descendant(root, restore_cb, be);
 }
 
 /* ============================================================= */
-/* The pgendGetAllAccounts() routine restores the account hierarchy 
+/* The pgendGetAllAccounts() routine restores the account hierarchy
  * of *all* accounts in the DB.  Each account is stuffed into
  * its corresponding book.
  *
@@ -236,238 +236,238 @@
 
 typedef struct
 {
-  Account * account;
+    Account * account;
 
-  char * commodity_string; /* If non-NULL, need to load commodity */
-  gboolean need_parent;    /* If TRUE, need to load parent */
-  GUID parent_guid;        /* GUID of parent */
+    char * commodity_string; /* If non-NULL, need to load commodity */
+    gboolean need_parent;    /* If TRUE, need to load parent */
+    GUID parent_guid;        /* GUID of parent */
 } AccountResolveInfo;
 
 typedef struct
 {
-  QofBook * book;
-  GList * resolve_info;
+    QofBook * book;
+    GList * resolve_info;
 } GetAccountData;
 
 static AccountResolveInfo *
 get_resolve_info (AccountResolveInfo * ri)
 {
-  if (ri) return ri;
-  return g_new0 (AccountResolveInfo, 1);
+    if (ri) return ri;
+    return g_new0 (AccountResolveInfo, 1);
 }
 
 static gpointer
 get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   GetAccountData * gad = data;
-   QofBook * book = gad->book;
-   Account *parent;
-   Account *acc;
-   GUID acct_guid;
-   char * commodity_string;
-   gnc_commodity * commodity;
-   AccountResolveInfo *ri = NULL;
+    GetAccountData * gad = data;
+    QofBook * book = gad->book;
+    Account *parent;
+    Account *acc;
+    GUID acct_guid;
+    char * commodity_string;
+    gnc_commodity * commodity;
+    AccountResolveInfo *ri = NULL;
 
-   PINFO ("account GUID=%s", DB_GET_VAL("accountGUID",j));
+    PINFO ("account GUID=%s", DB_GET_VAL("accountGUID", j));
 
-   FIND_BOOK (book);
+    FIND_BOOK (book);
 
-   /* Next, lets see if we've already got this account */
-   acct_guid = nullguid;  /* just in case the read fails ... */
-   string_to_guid (DB_GET_VAL("accountGUID",j), &acct_guid);
+    /* Next, lets see if we've already got this account */
+    acct_guid = nullguid;  /* just in case the read fails ... */
+    string_to_guid (DB_GET_VAL("accountGUID", j), &acct_guid);
 
-   acc = xaccAccountLookup (&acct_guid, book);
-   if (!acc)
-   {
-      acc = xaccMallocAccount(book);
-      xaccAccountBeginEdit(acc);
-      xaccAccountSetGUID(acc, &acct_guid);
-   }
-   else
-   {
-      xaccAccountBeginEdit(acc);
-   }
+    acc = xaccAccountLookup (&acct_guid, book);
+    if (!acc)
+    {
+        acc = xaccMallocAccount(book);
+        xaccAccountBeginEdit(acc);
+        xaccAccountSetGUID(acc, &acct_guid);
+    }
+    else
+    {
+        xaccAccountBeginEdit(acc);
+    }
 
-   commodity_string = DB_GET_VAL("commodity",j);
-   commodity = gnc_string_to_commodity (commodity_string, book);
-   if (!commodity)
-   {
-     ri = get_resolve_info (ri);
+    commodity_string = DB_GET_VAL("commodity", j);
+    commodity = gnc_string_to_commodity (commodity_string, book);
+    if (!commodity)
+    {
+        ri = get_resolve_info (ri);
 
-     ri->account = acc;
-     ri->commodity_string = g_strdup (commodity_string);
-   }
+        ri->account = acc;
+        ri->commodity_string = g_strdup (commodity_string);
+    }
 
-   xaccAccountSetName(acc, DB_GET_VAL("accountName",j));
-   xaccAccountSetDescription(acc, DB_GET_VAL("description",j));
-   xaccAccountSetCode(acc, DB_GET_VAL("accountCode",j));
-   xaccAccountSetType(acc, xaccAccountStringToEnum(DB_GET_VAL("type",j)));
-   if (commodity)
-     xaccAccountSetCommodity(acc, commodity);
-   qof_instance_set_version(acc, atoi(DB_GET_VAL("version",j)));
-   qof_instance_set_idata(acc, atoi(DB_GET_VAL("iguid",j)));
+    xaccAccountSetName(acc, DB_GET_VAL("accountName", j));
+    xaccAccountSetDescription(acc, DB_GET_VAL("description", j));
+    xaccAccountSetCode(acc, DB_GET_VAL("accountCode", j));
+    xaccAccountSetType(acc, xaccAccountStringToEnum(DB_GET_VAL("type", j)));
+    if (commodity)
+        xaccAccountSetCommodity(acc, commodity);
+    qof_instance_set_version(acc, atoi(DB_GET_VAL("version", j)));
+    qof_instance_set_idata(acc, atoi(DB_GET_VAL("iguid", j)));
 
-   /* try to find the parent account */
-   PINFO ("parent GUID=%s", DB_GET_VAL("parentGUID",j));
-   acct_guid = nullguid;  /* just in case the read fails ... */
-   string_to_guid (DB_GET_VAL("parentGUID",j), &acct_guid);
-   if (guid_equal(guid_null(), &acct_guid)) 
-   {
-      /* if the parent guid is null, then this
-       * account belongs in the top level */
-      gnc_account_append_child (gnc_book_get_root_account(book), acc);
-   }
-   else
-   {
-      /* if we haven't restored the parent account, create
-       * a resolution node for it */
-      parent = xaccAccountLookup (&acct_guid, book);
-      if (!parent)
-      {
-         ri = get_resolve_info (ri);
+    /* try to find the parent account */
+    PINFO ("parent GUID=%s", DB_GET_VAL("parentGUID", j));
+    acct_guid = nullguid;  /* just in case the read fails ... */
+    string_to_guid (DB_GET_VAL("parentGUID", j), &acct_guid);
+    if (guid_equal(guid_null(), &acct_guid))
+    {
+        /* if the parent guid is null, then this
+         * account belongs in the top level */
+        gnc_account_append_child (gnc_book_get_root_account(book), acc);
+    }
+    else
+    {
+        /* if we haven't restored the parent account, create
+         * a resolution node for it */
+        parent = xaccAccountLookup (&acct_guid, book);
+        if (!parent)
+        {
+            ri = get_resolve_info (ri);
 
-         ri->account = acc;
-         ri->need_parent = TRUE;
-         ri->parent_guid = acct_guid;
-      }
-      else
-      {
-         xaccAccountBeginEdit(parent);
-         gnc_account_append_child(parent, acc);
-         xaccAccountCommitEdit(parent);
-      }
-   }
+            ri->account = acc;
+            ri->need_parent = TRUE;
+            ri->parent_guid = acct_guid;
+        }
+        else
+        {
+            xaccAccountBeginEdit(parent);
+            gnc_account_append_child(parent, acc);
+            xaccAccountCommitEdit(parent);
+        }
+    }
 
-   xaccAccountCommitEdit(acc);
+    xaccAccountCommitEdit(acc);
 
-   if (ri)
-     gad->resolve_info = g_list_prepend (gad->resolve_info, ri);
+    if (ri)
+        gad->resolve_info = g_list_prepend (gad->resolve_info, ri);
 
-   return data;
+    return data;
 }
 
 static void
 pgendGetAccounts (PGBackend *be, QofBook *book)
 {
-  GetAccountData gad;
+    GetAccountData gad;
 
-  gad.book = book ? book : be->book;
-  gad.resolve_info = NULL;
+    gad.book = book ? book : be->book;
+    gad.resolve_info = NULL;
 
-  pgendGetResults (be, get_account_cb, &gad);
+    pgendGetResults (be, get_account_cb, &gad);
 
-  while (gad.resolve_info)
-  {
-    AccountResolveInfo *ri = gad.resolve_info->data;
+    while (gad.resolve_info)
+    {
+        AccountResolveInfo *ri = gad.resolve_info->data;
 
-    gad.resolve_info = g_list_remove (gad.resolve_info, ri);
+        gad.resolve_info = g_list_remove (gad.resolve_info, ri);
 
-    xaccAccountBeginEdit (ri->account);
+        xaccAccountBeginEdit (ri->account);
 
-    if (ri->commodity_string)
-    {
-      gnc_commodity * commodity;
+        if (ri->commodity_string)
+        {
+            gnc_commodity * commodity;
 
-      pgendGetCommodity (be, ri->commodity_string);
-      commodity = gnc_string_to_commodity (ri->commodity_string,
-                                           gnc_account_get_book(ri->account));
+            pgendGetCommodity (be, ri->commodity_string);
+            commodity = gnc_string_to_commodity (ri->commodity_string,
+                                                 gnc_account_get_book(ri->account));
 
-      if (commodity)
-      {
-        xaccAccountSetCommodity (ri->account, commodity);
-      }
-      else
-      {
-        PERR ("Can't find commodity %s", ri->commodity_string);
-      }
+            if (commodity)
+            {
+                xaccAccountSetCommodity (ri->account, commodity);
+            }
+            else
+            {
+                PERR ("Can't find commodity %s", ri->commodity_string);
+            }
 
-      g_free (ri->commodity_string);
-      ri->commodity_string = NULL;
-    }
+            g_free (ri->commodity_string);
+            ri->commodity_string = NULL;
+        }
 
-    if (ri->need_parent)
-    {
-      Account * parent;
+        if (ri->need_parent)
+        {
+            Account * parent;
 
-      /* parent could have been pulled in after node was inserted */
-      parent = xaccAccountLookup (&ri->parent_guid, gad.book);
+            /* parent could have been pulled in after node was inserted */
+            parent = xaccAccountLookup (&ri->parent_guid, gad.book);
 
-      if (!parent)
-        parent = pgendCopyAccountToEngine (be, &ri->parent_guid);
+            if (!parent)
+                parent = pgendCopyAccountToEngine (be, &ri->parent_guid);
 
-      if (parent)
-      {
-        xaccAccountBeginEdit(parent);
-        gnc_account_append_child(parent, ri->account);
-        xaccAccountCommitEdit(parent);
-      }
-      else
-      {
-        PERR ("no such account: %s", guid_to_string (&ri->parent_guid));
-      }
-    }
+            if (parent)
+            {
+                xaccAccountBeginEdit(parent);
+                gnc_account_append_child(parent, ri->account);
+                xaccAccountCommitEdit(parent);
+            }
+            else
+            {
+                PERR ("no such account: %s", guid_to_string (&ri->parent_guid));
+            }
+        }
 
-    xaccAccountCommitEdit (ri->account);
+        xaccAccountCommitEdit (ri->account);
 
-    g_free (ri);
-  }
+        g_free (ri);
+    }
 }
 
 void
 pgendGetAllAccounts (PGBackend *be)
 {
-   QofBookList *node;
-   char * bufp;
+    QofBookList *node;
+    char * bufp;
 
-   ENTER ("be=%p", be);
-   if (!be) return;
+    ENTER ("be=%p", be);
+    if (!be) return;
 
-   /* get all the books in the database */
-   pgendGetAllBooks (be, be->blist);
+    /* get all the books in the database */
+    pgendGetAllBooks (be, be->blist);
 
-   /* Make sure commodities table is up to date */
-   pgendGetAllCommodities (be);
+    /* Make sure commodities table is up to date */
+    pgendGetAllCommodities (be);
 
-   /* Get them ALL */
-   bufp = "SELECT * FROM gncAccount;";
-   SEND_QUERY (be, bufp, );
-   pgendGetAccounts (be, NULL);
+    /* Get them ALL */
+    bufp = "SELECT * FROM gncAccount;";
+    SEND_QUERY (be, bufp, );
+    pgendGetAccounts (be, NULL);
 
-   for (node=be->blist; node; node=node->next)
-   {
-      QofBook *book = node->data;
-      Account *root = gnc_book_get_root_account(book);
-      pgendGetAllAccountKVP (be, root);
-   }
+    for (node = be->blist; node; node = node->next)
+    {
+        QofBook *book = node->data;
+        Account *root = gnc_book_get_root_account(book);
+        pgendGetAllAccountKVP (be, root);
+    }
 
-   LEAVE (" ");
+    LEAVE (" ");
 }
 
 void
 pgendGetAllAccountsInBook (PGBackend *be, QofBook *book)
 {
-   char *p, buff[400];
-   Account *root;
+    char *p, buff[400];
+    Account *root;
 
-   ENTER ("be=%p", be);
-   if (!be || !book) return;
+    ENTER ("be=%p", be);
+    if (!be || !book) return;
 
-   /* first, make sure commodities table is up to date */
-   pgendGetAllCommodities (be);
+    /* first, make sure commodities table is up to date */
+    pgendGetAllCommodities (be);
 
-   /* Get everything for this book */
+    /* Get everything for this book */
 
-   p = buff;
-   p = stpcpy (p, "SELECT * FROM gncAccount WHERE bookGuid='");
-   p = guid_to_string_buff (qof_book_get_guid(book), p);
-   p = stpcpy (p, "';");
-   SEND_QUERY (be, buff, );
-   pgendGetAccounts (be, book);
+    p = buff;
+    p = stpcpy (p, "SELECT * FROM gncAccount WHERE bookGuid='");
+    p = guid_to_string_buff (qof_book_get_guid(book), p);
+    p = stpcpy (p, "';");
+    SEND_QUERY (be, buff, );
+    pgendGetAccounts (be, book);
 
-   root = gnc_book_get_root_account(book);
-   pgendGetAllAccountKVP (be, root);
+    root = gnc_book_get_root_account(book);
+    pgendGetAllAccountKVP (be, root);
 
-   LEAVE (" ");
+    LEAVE (" ");
 }
 
 
@@ -476,74 +476,74 @@
 Account *
 pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid)
 {
-   char *pbuff;
-   Account *acc = NULL;
-   int engine_data_is_newer = 0;
-   guint32 a_idata;
+    char *pbuff;
+    Account *acc = NULL;
+    int engine_data_is_newer = 0;
+    guint32 a_idata;
 
-   ENTER ("be=%p", be);
-   if (!be || !acct_guid) return 0;
+    ENTER ("be=%p", be);
+    if (!be || !acct_guid) return 0;
 
-   /* disable callbacks into the backend, and events to GUI */
-   qof_event_suspend();
-   pgendDisable(be);
+    /* disable callbacks into the backend, and events to GUI */
+    qof_event_suspend();
+    pgendDisable(be);
 
-   /* First, see if we already have such an account */
-   acc = pgendAccountLookup (be, acct_guid);
+    /* First, see if we already have such an account */
+    acc = pgendAccountLookup (be, acct_guid);
 
-   if (!acc)
-   {
-      engine_data_is_newer = -1;
-   }
-   else
-   {
-      /* save some performance, don't go to the
-       * backend if the data is recent. */
-      guint32 value = qof_instance_get_version_check(acc);
-      if (MAX_VERSION_AGE >= be->version_check - value) 
-      {
-         PINFO ("fresh data, skip check");
-         engine_data_is_newer = 0;
-      }
-      else
-      {
-         engine_data_is_newer = - pgendAccountCompareVersion (be, acc);
-      }
-   }
+    if (!acc)
+    {
+        engine_data_is_newer = -1;
+    }
+    else
+    {
+        /* save some performance, don't go to the
+         * backend if the data is recent. */
+        guint32 value = qof_instance_get_version_check(acc);
+        if (MAX_VERSION_AGE >= be->version_check - value)
+        {
+            PINFO ("fresh data, skip check");
+            engine_data_is_newer = 0;
+        }
+        else
+        {
+            engine_data_is_newer = - pgendAccountCompareVersion (be, acc);
+        }
+    }
 
-   if (0 > engine_data_is_newer)
-   { 
-      /* build the sql query to get the account */
-      pbuff = be->buff;
-      pbuff[0] = 0;
-      pbuff = stpcpy (pbuff,
-                      "SELECT * FROM gncAccount WHERE accountGuid='");
-      pbuff = guid_to_string_buff(acct_guid, pbuff);
-      pbuff = stpcpy (pbuff, "';");
+    if (0 > engine_data_is_newer)
+    {
+        /* build the sql query to get the account */
+        pbuff = be->buff;
+        pbuff[0] = 0;
+        pbuff = stpcpy (pbuff,
+                        "SELECT * FROM gncAccount WHERE accountGuid='");
+        pbuff = guid_to_string_buff(acct_guid, pbuff);
+        pbuff = stpcpy (pbuff, "';");
 
-      SEND_QUERY (be,be->buff, 0);
-      pgendGetAccounts (be, NULL);
-      acc = pgendAccountLookup (be, acct_guid);
+        SEND_QUERY (be, be->buff, 0);
+        pgendGetAccounts (be, NULL);
+        acc = pgendAccountLookup (be, acct_guid);
 
-      /* restore any kvp data associated with the transaction and splits */
-      if (acc)
-      {
-         a_idata = qof_instance_get_idata(acc);
-         if (a_idata)
-         {
-            acc->inst.kvp_data = pgendKVPFetch (be, a_idata, acc->inst.kvp_data);
-         }
+        /* restore any kvp data associated with the transaction and splits */
+        if (acc)
+        {
+            a_idata = qof_instance_get_idata(acc);
+            if (a_idata)
+            {
+                acc->inst.kvp_data = pgendKVPFetch (be, a_idata, acc->inst.kvp_data);
+            }
 
-         qof_instance_set_version_check(acc, be->version_check);
-      }
-   }
+            qof_instance_set_version_check(acc, be->version_check);
+        }
+    }
 
-   /* re-enable events to the backend and GUI */
-   pgendEnable(be);
-   qof_event_resume();
+    /* re-enable events to the backend and GUI */
+    pgendEnable(be);
+    qof_event_resume();
 
-   LEAVE (" ");
-   return acc;
+    LEAVE (" ");
+    return acc;
 }
 
 /* ============================================================= */
@@ -553,81 +553,83 @@
 /* ============================================================= */
 
 void
-pgend_account_commit_edit (QofBackend * bend, 
+pgend_account_commit_edit (QofBackend * bend,
                            Account * acct)
 {
-   char *p;
-   QofBackendError err;
-   PGBackend *be = (PGBackend *)bend;
+    char *p;
+    QofBackendError err;
+    PGBackend *be = (PGBackend *)bend;
 
-   ENTER ("be=%p, acct=%p", be, acct);
-   if (!be || !acct) return;
+    ENTER ("be=%p, acct=%p", be, acct);
+    if (!be || !acct) return;
 
-   if (!qof_instance_get_dirty_flag(acct))
-   {
-      LEAVE ("account not written because not dirty");
-      return;
-   }
+    if (!qof_instance_get_dirty_flag(acct))
+    {
+        LEAVE ("account not written because not dirty");
+        return;
+    }
 
-   /* lock it up so that we query and store atomically */
-   /* its not at all clear to me that this isn't rife with deadlocks. */
-   p = "BEGIN;\n"
-       "LOCK TABLE gncAccount IN EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncCommodity IN EXCLUSIVE MODE;\n";
+    /* lock it up so that we query and store atomically */
+    /* its not at all clear to me that this isn't rife with deadlocks. */
+    p = "BEGIN;\n"
+        "LOCK TABLE gncAccount IN EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncCommodity IN EXCLUSIVE MODE;\n";
 
-   SEND_QUERY (be,p,);
-   FINISH_QUERY(be->connection);
+    SEND_QUERY (be, p,);
+    FINISH_QUERY(be->connection);
 
-   /* check to see that the engine version is equal or newer than 
-    * whats in the database.  It its not, then some other user has 
-    * made changes, and we must roll back. */
-   if (0 < pgendAccountCompareVersion (be, acct))
-   {
-      qof_instance_set_destroying(acct, FALSE);
-      p = "ROLLBACK;";
-      SEND_QUERY (be,p,);
-      FINISH_QUERY(be->connection);
+    /* check to see that the engine version is equal or newer than
+     * whats in the database.  It its not, then some other user has
+     * made changes, and we must roll back. */
+    if (0 < pgendAccountCompareVersion (be, acct))
+    {
+        qof_instance_set_destroying(acct, FALSE);
+        p = "ROLLBACK;";
+        SEND_QUERY (be, p,);
+        FINISH_QUERY(be->connection);
 
-      /* hack alert -- we should restore the account data from the 
-       * sql back end at this point ! !!! */
-      PWARN(" account data in engine is newer\n"
-            " account must be rolled back.  This function\n"
-            " is not completely implemented !! \n");
-      qof_backend_set_error (&be->be, ERR_BACKEND_MODIFIED);
-      LEAVE ("rolled back");
-      return;
-   }
-   /* be sure to update the version !! */
-   qof_instance_increment_version(acct, be->version_check);
+        /* hack alert -- we should restore the account data from the
+         * sql back end at this point ! !!! */
+        PWARN(" account data in engine is newer\n"
+              " account must be rolled back.  This function\n"
+              " is not completely implemented !! \n");
+        qof_backend_set_error (&be->be, ERR_BACKEND_MODIFIED);
+        LEAVE ("rolled back");
+        return;
+    }
+    /* be sure to update the version !! */
+    qof_instance_increment_version(acct, be->version_check);
 
-   if (qof_instance_get_destroying(acct))
-   {
-      const GUID *guid = xaccAccountGetGUID(acct);
-      pgendKVPDelete (be, qof_instance_get_idata(acct));
+    if (qof_instance_get_destroying(acct))
+    {
+        const GUID *guid = xaccAccountGetGUID(acct);
+        pgendKVPDelete (be, qof_instance_get_idata(acct));
 
-      p = be->buff; *p = 0;
-      p = stpcpy (p, "DELETE FROM gncAccount WHERE accountGuid='");
-      p = guid_to_string_buff (guid, p);
-      p = stpcpy (p, "';");
-      err = sendQuery (be,be->buff);
-      if (err == ERR_BACKEND_NO_ERR) {
-          err = finishQuery(be);
-	  if (err > 0) /* if the number of rows deleted is 0 */
-              pgendStoreAuditAccount (be, acct, SQL_DELETE);
-      }
-   }
-   else
-   {
-      pgendStoreAccountNoLock (be, acct, FALSE, FALSE);
-   }
+        p = be->buff;
+        *p = 0;
+        p = stpcpy (p, "DELETE FROM gncAccount WHERE accountGuid='");
+        p = guid_to_string_buff (guid, p);
+        p = stpcpy (p, "';");
+        err = sendQuery (be, be->buff);
+        if (err == ERR_BACKEND_NO_ERR)
+        {
+            err = finishQuery(be);
+            if (err > 0) /* if the number of rows deleted is 0 */
+                pgendStoreAuditAccount (be, acct, SQL_DELETE);
+        }
+    }
+    else
+    {
+        pgendStoreAccountNoLock (be, acct, FALSE, FALSE);
+    }
 
-   p = "COMMIT;\n"
-       "NOTIFY gncAccount;";
-   SEND_QUERY (be,p,);
-   FINISH_QUERY(be->connection);
+    p = "COMMIT;\n"
+        "NOTIFY gncAccount;";
+    SEND_QUERY (be, p,);
+    FINISH_QUERY(be->connection);
 
-   LEAVE ("commited");
-   return;
+    LEAVE ("commited");
+    return;
 }
 
 /* ======================== END OF FILE ======================== */

Modified: gnucash/trunk/src/backend/postgres/account.h
===================================================================
--- gnucash/trunk/src/backend/postgres/account.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/account.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -35,7 +35,7 @@
 
 void pgendStoreAccountTree (PGBackend *be, Account *root);
 void pgendStoreAccountTreeNoLock (PGBackend *be, Account *root,
-                       gboolean do_mark, gboolean do_check_version);
+                                  gboolean do_mark, gboolean do_check_version);
 Account * pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid);
 
 void pgend_account_commit_edit (QofBackend * bend, Account * acct);

Modified: gnucash/trunk/src/backend/postgres/book.c
===================================================================
--- gnucash/trunk/src/backend/postgres/book.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/book.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -23,11 +23,11 @@
 #include "config.h"
 
 #include <glib.h>
-#include <stdlib.h>  
-#include <string.h>  
+#include <stdlib.h>
+#include <string.h>
 
-#include <libpq-fe.h>  
- 
+#include <libpq-fe.h>
+
 #include "qof.h"
 #include "book.h"
 #include "gnc-pricedb.h"
@@ -39,7 +39,7 @@
 
 #include "putil.h"
 
-static QofLogModule log_module = GNC_MOD_BACKEND; 
+static QofLogModule log_module = GNC_MOD_BACKEND;
 
 /* ============================================================= */
 /* ============================================================= */
@@ -49,73 +49,73 @@
 /* ============================================================= */
 
 /* ============================================================= */
-/* The pgendStoreBook() routine stores everything in the book 
- * to the database.  That is, the engine data is written out to the 
- * database.  
+/* The pgendStoreBook() routine stores everything in the book
+ * to the database.  That is, the engine data is written out to the
+ * database.
  *
  * If do_mark is set to TRUE, then this routine sets a mark
  * to terminate recursion.  That is,  it will only store the
- * account once; a second call on a marked account will simply 
+ * account once; a second call on a marked account will simply
  * return.  Be sure to clear the mark when done!
  *
  * If the do_check_version flag is set, then this routine
  * will compare the engine and sql db version numbrs, and
- * perform the store only if the engine version is equal 
+ * perform the store only if the engine version is equal
  * or newer than the sql version.
  *
  */
 
 void
 pgendStoreBookNoLock (PGBackend *be, QofBook *book,
-                         gboolean do_check_version)
+                      gboolean do_check_version)
 {
-   guint32 idata;
-   if (!be || !book) return;
+    guint32 idata;
+    if (!be || !book) return;
 
-   ENTER ("book=%p", book);
+    ENTER ("book=%p", book);
 
-   if (do_check_version)
-   {
-     if (0 < pgendBookCompareVersion (be, book)) return;
-   }
-   qof_book_set_version(book, (qof_book_get_version(book) +1));  /* be sure to update the version !! */
+    if (do_check_version)
+    {
+        if (0 < pgendBookCompareVersion (be, book)) return;
+    }
+    qof_book_set_version(book, (qof_book_get_version(book) + 1)); /* be sure to update the version !! */
 
-   if ((0 == qof_instance_get_idata(book)) &&
-       (FALSE == kvp_frame_is_empty (qof_book_get_slots(book))))
-   {
-      qof_instance_set_idata(book, pgendNewGUIDidx(be));
-   }
+    if ((0 == qof_instance_get_idata(book)) &&
+            (FALSE == kvp_frame_is_empty (qof_book_get_slots(book))))
+    {
+        qof_instance_set_idata(book, pgendNewGUIDidx(be));
+    }
 
-   pgendPutOneBookOnly (be, book);
-   idata = qof_instance_get_idata(book);
-   if ( idata > 0)
-   {
-      pgendKVPDelete (be, idata);
-      pgendKVPStore (be, idata, qof_instance_get_slots((QofInstance*)book));
-   }
-   LEAVE(" ");
+    pgendPutOneBookOnly (be, book);
+    idata = qof_instance_get_idata(book);
+    if ( idata > 0)
+    {
+        pgendKVPDelete (be, idata);
+        pgendKVPStore (be, idata, qof_instance_get_slots((QofInstance*)book));
+    }
+    LEAVE(" ");
 }
 
 void
 pgendStoreBook (PGBackend *be, QofBook *book)
 {
-   char *p;
-   ENTER ("be=%p, book=%p", be, book);
-   if (!be || !book) return;
+    char *p;
+    ENTER ("be=%p, book=%p", be, book);
+    if (!be || !book) return;
 
-   /* lock it up so that we store atomically */
-   p = "BEGIN;\n"
-       "LOCK TABLE gncBook IN EXCLUSIVE MODE;\n";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    /* lock it up so that we store atomically */
+    p = "BEGIN;\n"
+        "LOCK TABLE gncBook IN EXCLUSIVE MODE;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   pgendStoreBookNoLock (be, book, TRUE);
+    pgendStoreBookNoLock (be, book, TRUE);
 
-   p = "COMMIT;\n"
-       "NOTIFY gncBook;";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
-   LEAVE(" ");
+    p = "COMMIT;\n"
+        "NOTIFY gncBook;";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+    LEAVE(" ");
 }
 
 
@@ -131,59 +131,59 @@
 static gpointer
 get_one_book_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   QofBook *book = (QofBook *) data;
-   GUID guid;
+    QofBook *book = (QofBook *) data;
+    GUID guid;
 
-   /* first, lets see if we've already got this one */
-   PINFO ("book GUID=%s", DB_GET_VAL("bookGuid",j));
-   guid = nullguid;  /* just in case the read fails ... */
-   string_to_guid (DB_GET_VAL("bookGuid",j), &guid);
+    /* first, lets see if we've already got this one */
+    PINFO ("book GUID=%s", DB_GET_VAL("bookGuid", j));
+    guid = nullguid;  /* just in case the read fails ... */
+    string_to_guid (DB_GET_VAL("bookGuid", j), &guid);
 
-   qof_instance_set_guid (QOF_INSTANCE(book), &guid);
+    qof_instance_set_guid (QOF_INSTANCE(book), &guid);
 
-   if((DB_GET_VAL("book_open",j))[0] == 'n')
-   {
-   		qof_book_mark_closed(book);
-   }
-   qof_book_set_version(book, atoi(DB_GET_VAL("version",j)));
-   qof_instance_set_idata(book, atoi(DB_GET_VAL("iguid",j)));
+    if ((DB_GET_VAL("book_open", j))[0] == 'n')
+    {
+        qof_book_mark_closed(book);
+    }
+    qof_book_set_version(book, atoi(DB_GET_VAL("version", j)));
+    qof_instance_set_idata(book, atoi(DB_GET_VAL("iguid", j)));
 
-   return book;
+    return book;
 }
 
 static void pg_kvp_helper (const char* key, KvpValue *value, gpointer data)
 {
-	QofBook *book = (QofBook*)data;
-	kvp_frame_set_slot_nc(qof_instance_get_slots((QofInstance*)book),
-		key, value);
+    QofBook *book = (QofBook*)data;
+    kvp_frame_set_slot_nc(qof_instance_get_slots((QofInstance*)book),
+                          key, value);
 }
 
 void
 pgendBookRestore (PGBackend *be, QofBook *book)
 {
-   char * bufp;
+    char * bufp;
 
-   ENTER ("be=%p", be);
-   if (!be) return;
+    ENTER ("be=%p", be);
+    if (!be) return;
 
-   /* For right now, get only the currently open book 
-    * In theory, we should pass a guid into this routine, 
-    * and fetch books based on that. 
-    */
-   bufp = "SELECT * FROM gncBook WHERE book_open='y';";
-   SEND_QUERY (be, bufp, );
-   pgendGetResults (be, get_one_book_cb, book);
+    /* For right now, get only the currently open book
+     * In theory, we should pass a guid into this routine,
+     * and fetch books based on that.
+     */
+    bufp = "SELECT * FROM gncBook WHERE book_open='y';";
+    SEND_QUERY (be, bufp, );
+    pgendGetResults (be, get_one_book_cb, book);
 
-   if (0 != qof_instance_get_idata(book)) 
-   {
-	  KvpFrame *pg_frame;
-	  
-	  pg_frame = pgendKVPFetch (be, qof_instance_get_idata(book), 
-	   	qof_instance_get_slots((QofInstance*)book));
-	  kvp_frame_for_each_slot(pg_frame, pg_kvp_helper, book);	   
-   }
+    if (0 != qof_instance_get_idata(book))
+    {
+        KvpFrame *pg_frame;
 
-   LEAVE (" ");
+        pg_frame = pgendKVPFetch (be, qof_instance_get_idata(book),
+                                  qof_instance_get_slots((QofInstance*)book));
+        kvp_frame_for_each_slot(pg_frame, pg_kvp_helper, book);
+    }
+
+    LEAVE (" ");
 }
 
 /* ============================================================= */
@@ -194,100 +194,100 @@
 static gpointer
 get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   QofBookList *blist = (QofBookList *) data;
-   QofBookList *node;
-   QofBook *book;
-   GUID guid;
+    QofBookList *blist = (QofBookList *) data;
+    QofBookList *node;
+    QofBook *book;
+    GUID guid;
 
-   PINFO ("book GUID=%s", DB_GET_VAL("bookGUID",j));
-   guid = nullguid;  /* just in case the read fails ... */
-   string_to_guid (DB_GET_VAL("bookGUID",j), &guid);
+    PINFO ("book GUID=%s", DB_GET_VAL("bookGUID", j));
+    guid = nullguid;  /* just in case the read fails ... */
+    string_to_guid (DB_GET_VAL("bookGUID", j), &guid);
 
-   /* first, lets see if we've already got this one */
-   book = NULL;
-   for (node=blist; node; node=node->next)
-   {
-      book = node->data;
-      if (guid_equal (qof_entity_get_guid(QOF_INSTANCE(book)), &guid)) break;
-      book = NULL;
-   }
-   
-   if (!book) 
-   {
-      book = qof_book_new();
-      qof_instance_set_guid (QOF_INSTANCE(book), &guid);
-   }
+    /* first, lets see if we've already got this one */
+    book = NULL;
+    for (node = blist; node; node = node->next)
+    {
+        book = node->data;
+        if (guid_equal (qof_entity_get_guid(QOF_INSTANCE(book)), &guid)) break;
+        book = NULL;
+    }
 
-   if((DB_GET_VAL("book_open",j))[0] == 'n')
-   {
-	   qof_book_mark_closed(book);
-   }
+    if (!book)
+    {
+        book = qof_book_new();
+        qof_instance_set_guid (QOF_INSTANCE(book), &guid);
+    }
+
+    if ((DB_GET_VAL("book_open", j))[0] == 'n')
+    {
+        qof_book_mark_closed(book);
+    }
 //   book->book_open = (DB_GET_VAL("book_open",j))[0];
-   qof_book_set_version(book, atoi(DB_GET_VAL("version",j)));
-   qof_instance_set_idata(book, atoi(DB_GET_VAL("iguid",j)));
+    qof_book_set_version(book, atoi(DB_GET_VAL("version", j)));
+    qof_instance_set_idata(book, atoi(DB_GET_VAL("iguid", j)));
 
-   return blist;
+    return blist;
 }
 
 QofBookList *
 pgendGetAllBooks (PGBackend *be, QofBookList *blist)
 {
-   QofBookList *node;
-   char * bufp;
+    QofBookList *node;
+    char * bufp;
 
-   ENTER ("be=%p", be);
-   if (!be) return NULL;
+    ENTER ("be=%p", be);
+    if (!be) return NULL;
 
-   /* Get them ALL */
-   bufp = "SELECT * FROM gncBook;";
-   SEND_QUERY (be, bufp, NULL);
-   blist = pgendGetResults (be, get_book_cb, blist);
+    /* Get them ALL */
+    bufp = "SELECT * FROM gncBook;";
+    SEND_QUERY (be, bufp, NULL);
+    blist = pgendGetResults (be, get_book_cb, blist);
 
-   /* get the KVP data for each book too */
-   for (node=blist; node; node=node->next)
-   {
-      QofBook *book = node->data;
-      if (0 != qof_instance_get_idata(book)) 
-      {
-	  	KvpFrame *pg_frame;
-	  
-		  pg_frame = pgendKVPFetch (be, qof_instance_get_idata(book), 
-		   	qof_instance_get_slots((QofInstance*)book));
-		  kvp_frame_for_each_slot(pg_frame, pg_kvp_helper, book);	   
-      }
-/*      if (0 != qof_instance_get_idata(book)) 
-      {
-         book->inst.kvp_data = pgendKVPFetch(be, qof_instance_get_idata(book),
-                                             book->inst.kvp_data);
-      }*/
-   }
+    /* get the KVP data for each book too */
+    for (node = blist; node; node = node->next)
+    {
+        QofBook *book = node->data;
+        if (0 != qof_instance_get_idata(book))
+        {
+            KvpFrame *pg_frame;
 
-   LEAVE (" ");
-   return blist;
+            pg_frame = pgendKVPFetch (be, qof_instance_get_idata(book),
+                                      qof_instance_get_slots((QofInstance*)book));
+            kvp_frame_for_each_slot(pg_frame, pg_kvp_helper, book);
+        }
+        /*      if (0 != qof_instance_get_idata(book))
+              {
+                 book->inst.kvp_data = pgendKVPFetch(be, qof_instance_get_idata(book),
+                                                     book->inst.kvp_data);
+              }*/
+    }
+
+    LEAVE (" ");
+    return blist;
 }
 
 /* ============================================================= */
 
-void 
+void
 pgend_book_transfer_begin(QofBackend *bend, QofBook *newbook)
 {
-   PGBackend *be = (PGBackend *) bend;
+    PGBackend *be = (PGBackend *) bend;
 
-   ENTER (" ");
+    ENTER (" ");
 
-   /* first, store the new book */
-   pgendStoreBook (be, newbook);
+    /* first, store the new book */
+    pgendStoreBook (be, newbook);
 
-   LEAVE (" ");
+    LEAVE (" ");
 }
 
-void 
+void
 pgend_book_transfer_commit(QofBackend *bend, QofBook *newbook)
 {
-   /* PGBackend *be = (PGBackend *) bend; */
-   ENTER (" ");
+    /* PGBackend *be = (PGBackend *) bend; */
+    ENTER (" ");
 
-   LEAVE (" ");
+    LEAVE (" ");
 }
 
 /* ======================== END OF FILE ======================== */

Modified: gnucash/trunk/src/backend/postgres/builder.c
===================================================================
--- gnucash/trunk/src/backend/postgres/builder.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/builder.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -28,7 +28,7 @@
  * generic postgres backend query builder
  * compiles data types into sql queries
  *
- * Note: Postgres documentation states that the 
+ * Note: Postgres documentation states that the
  * maximum length of a query is 8192 bytes, and that
  * longer queries are ignored ...
  *
@@ -45,29 +45,30 @@
 #include "builder.h"
 #include "gnc-engine.h"
 
-static QofLogModule log_module = GNC_MOD_BACKEND; 
+static QofLogModule log_module = GNC_MOD_BACKEND;
 
 /* ================================================ */
 
-struct _builder {
-   sqlBuild_QType qtype;
+struct _builder
+{
+    sqlBuild_QType qtype;
 
-   /* pointers the the tail end of two different assembly areas */
-   char * ptag;
-   char * pval;
+    /* pointers the the tail end of two different assembly areas */
+    char * ptag;
+    char * pval;
 
-   /* sql needs commas to separate values */
-   short  tag_need_comma;
-   short  val_need_comma;
-   short  where_need_and;
+    /* sql needs commas to separate values */
+    short  tag_need_comma;
+    short  val_need_comma;
+    short  where_need_and;
 
-   /* pointers to the start of two different assembly areas. */
-   char * tag_base;
-   char * val_base;
-   size_t buflen;
+    /* pointers to the start of two different assembly areas. */
+    char * tag_base;
+    char * val_base;
+    size_t buflen;
 
-   /* pointer to temp memory used for escaping arguments */
-   sqlEscape *escape;
+    /* pointer to temp memory used for escaping arguments */
+    sqlEscape *escape;
 };
 
 /* ================================================ */
@@ -77,28 +78,28 @@
 sqlBuilder *
 sqlBuilder_new (void)
 {
-   sqlBuilder *b = g_new (sqlBuilder, 1);
+    sqlBuilder *b = g_new (sqlBuilder, 1);
 
-   b->qtype = SQL_INSERT;
+    b->qtype = SQL_INSERT;
 
-   b->tag_base = g_malloc (INITIAL_BUFSZ);
-   b->val_base = g_malloc (INITIAL_BUFSZ);
-   b->buflen = INITIAL_BUFSZ;
+    b->tag_base = g_malloc (INITIAL_BUFSZ);
+    b->val_base = g_malloc (INITIAL_BUFSZ);
+    b->buflen = INITIAL_BUFSZ;
 
-   b->ptag = b->tag_base;
-   b->pval = b->val_base;
+    b->ptag = b->tag_base;
+    b->pval = b->val_base;
 
-   /* null terminated strings */
-   *(b->ptag) = 0x0;
-   *(b->pval) = 0x0;
+    /* null terminated strings */
+    *(b->ptag) = 0x0;
+    *(b->pval) = 0x0;
 
-   b->tag_need_comma = 0;
-   b->val_need_comma = 0;
-   b->where_need_and = 0;
+    b->tag_need_comma = 0;
+    b->val_need_comma = 0;
+    b->where_need_and = 0;
 
-   /* the escape area */
-   b->escape = sqlEscape_new ();
-   return (b);
+    /* the escape area */
+    b->escape = sqlEscape_new ();
+    return (b);
 }
 
 /* ================================================ */
@@ -106,11 +107,14 @@
 void
 sqlBuilder_destroy (sqlBuilder *b)
 {
-   if (!b) return;
-   g_free (b->tag_base);   b->tag_base = NULL;
-   g_free (b->val_base);   b->val_base = NULL;
-   sqlEscape_destroy (b->escape);     b->escape = NULL;
-   g_free (b);
+    if (!b) return;
+    g_free (b->tag_base);
+    b->tag_base = NULL;
+    g_free (b->val_base);
+    b->val_base = NULL;
+    sqlEscape_destroy (b->escape);
+    b->escape = NULL;
+    g_free (b);
 }
 
 /* ================================================ */
@@ -118,55 +122,55 @@
 void
 sqlBuild_Table (sqlBuilder *b, const char *tablename, sqlBuild_QType qt)
 {
-   if (!b || !tablename) return;
-   b->qtype = qt;
+    if (!b || !tablename) return;
+    b->qtype = qt;
 
-   b->ptag = b->tag_base;
-   b->pval = b->val_base;
+    b->ptag = b->tag_base;
+    b->pval = b->val_base;
 
-   /* null terminated strings */
-   *(b->ptag) = 0x0;
-   *(b->pval) = 0x0;
+    /* null terminated strings */
+    *(b->ptag) = 0x0;
+    *(b->pval) = 0x0;
 
-   b->tag_need_comma = 0;
-   b->val_need_comma = 0;
-   b->where_need_and = 0;
+    b->tag_need_comma = 0;
+    b->val_need_comma = 0;
+    b->where_need_and = 0;
 
-   switch (qt) 
-   {
-      case SQL_INSERT:
-         b->ptag = stpcpy(b->ptag, "INSERT INTO ");
-         b->ptag = stpcpy(b->ptag, tablename);
-         b->ptag = stpcpy(b->ptag, " (");
+    switch (qt)
+    {
+    case SQL_INSERT:
+        b->ptag = stpcpy(b->ptag, "INSERT INTO ");
+        b->ptag = stpcpy(b->ptag, tablename);
+        b->ptag = stpcpy(b->ptag, " (");
 
-         b->pval = stpcpy(b->pval, ") VALUES (");
-         break;
+        b->pval = stpcpy(b->pval, ") VALUES (");
+        break;
 
-      case SQL_UPDATE:
-         b->ptag = stpcpy(b->ptag, "UPDATE ");
-         b->ptag = stpcpy(b->ptag, tablename);
-         b->ptag = stpcpy(b->ptag, " SET ");
+    case SQL_UPDATE:
+        b->ptag = stpcpy(b->ptag, "UPDATE ");
+        b->ptag = stpcpy(b->ptag, tablename);
+        b->ptag = stpcpy(b->ptag, " SET ");
 
-         b->pval = stpcpy(b->pval, " WHERE ");
-         break;
+        b->pval = stpcpy(b->pval, " WHERE ");
+        break;
 
-      case SQL_SELECT:
-         b->ptag = stpcpy(b->ptag, "SELECT ");
+    case SQL_SELECT:
+        b->ptag = stpcpy(b->ptag, "SELECT ");
 
-         b->pval = stpcpy(b->pval, " FROM ");
-         b->pval = stpcpy(b->pval, tablename);
-         b->pval = stpcpy(b->pval, " WHERE ");
-         break;
+        b->pval = stpcpy(b->pval, " FROM ");
+        b->pval = stpcpy(b->pval, tablename);
+        b->pval = stpcpy(b->pval, " WHERE ");
+        break;
 
-      case SQL_DELETE:
-         b->ptag = stpcpy(b->ptag, "DELETE ");
+    case SQL_DELETE:
+        b->ptag = stpcpy(b->ptag, "DELETE ");
 
-         b->pval = stpcpy(b->pval, " FROM ");
-         b->pval = stpcpy(b->pval, tablename);
-         b->pval = stpcpy(b->pval, " WHERE ");
-         break;
+        b->pval = stpcpy(b->pval, " FROM ");
+        b->pval = stpcpy(b->pval, tablename);
+        b->pval = stpcpy(b->pval, " WHERE ");
+        break;
 
-   };
+    };
 
 }
 
@@ -176,44 +180,44 @@
 void
 sqlBuild_Set_Str (sqlBuilder *b, const char *tag, const char *val)
 {
-   if (!b || !tag) return;
-   if (!val) val= "";
+    if (!b || !tag) return;
+    if (!val) val = "";
 
-   val = sqlEscapeString (b->escape, val);
+    val = sqlEscapeString (b->escape, val);
 
-   if (b->tag_need_comma) b->ptag = stpcpy(b->ptag, ", ");
-   b->tag_need_comma = 1;
+    if (b->tag_need_comma) b->ptag = stpcpy(b->ptag, ", ");
+    b->tag_need_comma = 1;
 
-   switch (b->qtype) 
-   {
-      case SQL_INSERT:
-         b->ptag = stpcpy(b->ptag, tag);
+    switch (b->qtype)
+    {
+    case SQL_INSERT:
+        b->ptag = stpcpy(b->ptag, tag);
 
-         if (b->val_need_comma) b->pval = stpcpy(b->pval, ", ");
-         b->val_need_comma = 1;
-         b->pval = stpcpy(b->pval, "'");
-         b->pval = stpcpy(b->pval, val);
-         b->pval = stpcpy(b->pval, "'");
-         break;
+        if (b->val_need_comma) b->pval = stpcpy(b->pval, ", ");
+        b->val_need_comma = 1;
+        b->pval = stpcpy(b->pval, "'");
+        b->pval = stpcpy(b->pval, val);
+        b->pval = stpcpy(b->pval, "'");
+        break;
 
-      case SQL_UPDATE:
-         b->ptag = stpcpy(b->ptag, tag);
-         b->ptag = stpcpy(b->ptag, "='");
-         b->ptag = stpcpy(b->ptag, val);
-         b->ptag = stpcpy(b->ptag, "' ");
-         break;
+    case SQL_UPDATE:
+        b->ptag = stpcpy(b->ptag, tag);
+        b->ptag = stpcpy(b->ptag, "='");
+        b->ptag = stpcpy(b->ptag, val);
+        b->ptag = stpcpy(b->ptag, "' ");
+        break;
 
-      case SQL_SELECT:
-         b->ptag = stpcpy(b->ptag, tag);
-         break;
+    case SQL_SELECT:
+        b->ptag = stpcpy(b->ptag, tag);
+        break;
 
-      case SQL_DELETE:
-         break;
+    case SQL_DELETE:
+        break;
 
-      default:
-         PERR ("mustn't happen");
-   };
-   
+    default:
+        PERR ("mustn't happen");
+    };
+
 }
 
 /* ================================================ */
@@ -221,10 +225,10 @@
 void
 sqlBuild_Set_Char (sqlBuilder *b, const char *tag, char val)
 {
-  char buf[2];
-  buf[0] = val;
-  buf[1] = 0x0;
-  sqlBuild_Set_Str (b, tag, buf);
+    char buf[2];
+    buf[0] = val;
+    buf[1] = 0x0;
+    sqlBuild_Set_Str (b, tag, buf);
 }
 
 /* ================================================ */
@@ -232,14 +236,17 @@
 void
 sqlBuild_Set_GUID (sqlBuilder *b, const char *tag, const GUID *val)
 {
-  if (val) {
-     char guid_str[GUID_ENCODING_LENGTH+1];
-     guid_to_string_buff(val, guid_str);
-     sqlBuild_Set_Str (b, tag, guid_str);
-  } else {
-     /* if a SELECT statement is being built, then val may be null */
-     sqlBuild_Set_Str (b, tag, "");
-  }
+    if (val)
+    {
+        char guid_str[GUID_ENCODING_LENGTH+1];
+        guid_to_string_buff(val, guid_str);
+        sqlBuild_Set_Str (b, tag, guid_str);
+    }
+    else
+    {
+        /* if a SELECT statement is being built, then val may be null */
+        sqlBuild_Set_Str (b, tag, "");
+    }
 }
 
 /* ================================================ */
@@ -247,9 +254,9 @@
 void
 sqlBuild_Set_Date (sqlBuilder *b, const char *tag, Timespec ts)
 {
-  char buf[120];
-  gnc_timespec_to_iso8601_buff (ts, buf);
-  sqlBuild_Set_Str (b, tag, buf);
+    char buf[120];
+    gnc_timespec_to_iso8601_buff (ts, buf);
+    sqlBuild_Set_Str (b, tag, buf);
 }
 
 /* ================================================ */
@@ -257,9 +264,9 @@
 void
 sqlBuild_Set_Double (sqlBuilder *b, const char *tag, double flt)
 {
-  char buf[120];
-  snprintf (buf, 120, SQL_DBL_FMT, flt);
-  sqlBuild_Set_Str (b, tag, buf);
+    char buf[120];
+    snprintf (buf, 120, SQL_DBL_FMT, flt);
+    sqlBuild_Set_Str (b, tag, buf);
 }
 
 /* ================================================ */
@@ -267,39 +274,39 @@
 void
 sqlBuild_Set_Int64 (sqlBuilder *b, const char *tag, gint64 nval)
 {
-   char val[100];
-   if (!b || !tag) return;
+    char val[100];
+    if (!b || !tag) return;
 
-   snprintf (val, 100, "%" G_GINT64_FORMAT, nval);
-   if (b->tag_need_comma) b->ptag = stpcpy(b->ptag, ", ");
-   b->tag_need_comma = 1;
+    snprintf (val, 100, "%" G_GINT64_FORMAT, nval);
+    if (b->tag_need_comma) b->ptag = stpcpy(b->ptag, ", ");
+    b->tag_need_comma = 1;
 
-   switch (b->qtype) 
-   {
-      case SQL_INSERT:
-         b->ptag = stpcpy(b->ptag, tag);
+    switch (b->qtype)
+    {
+    case SQL_INSERT:
+        b->ptag = stpcpy(b->ptag, tag);
 
-         if (b->val_need_comma) b->pval = stpcpy(b->pval, ", ");
-         b->val_need_comma = 1;
-         b->pval = stpcpy(b->pval, val);
-         break;
+        if (b->val_need_comma) b->pval = stpcpy(b->pval, ", ");
+        b->val_need_comma = 1;
+        b->pval = stpcpy(b->pval, val);
+        break;
 
-      case SQL_UPDATE:
-         b->ptag = stpcpy(b->ptag, tag);
-         b->ptag = stpcpy(b->ptag, "=");
-         b->ptag = stpcpy(b->ptag, val);
-         break;
+    case SQL_UPDATE:
+        b->ptag = stpcpy(b->ptag, tag);
+        b->ptag = stpcpy(b->ptag, "=");
+        b->ptag = stpcpy(b->ptag, val);
+        break;
 
-      case SQL_SELECT:
-         b->ptag = stpcpy(b->ptag, tag);
-         break;
+    case SQL_SELECT:
+        b->ptag = stpcpy(b->ptag, tag);
+        break;
 
-      case SQL_DELETE:
-         break;
+    case SQL_DELETE:
+        break;
 
-      default:
-         PERR ("mustn't happen");
-   };
+    default:
+        PERR ("mustn't happen");
+    };
 }
 
 /* ================================================ */
@@ -307,7 +314,7 @@
 void
 sqlBuild_Set_Int32 (sqlBuilder *b, const char *tag, gint32 nval)
 {
-   sqlBuild_Set_Int64 (b, tag, (gint64) nval);
+    sqlBuild_Set_Int64 (b, tag, (gint64) nval);
 }
 
 /* ================================================ */
@@ -315,33 +322,33 @@
 void
 sqlBuild_Where_Str (sqlBuilder *b, const char *tag, const char *val)
 {
-   if (!b || !tag || !val) return;
+    if (!b || !tag || !val) return;
 
-   switch (b->qtype) 
-   {
-      case SQL_INSERT:
-         /* ther is no where clasue, so we do the set as a utility */
-         sqlBuild_Set_Str (b, tag, val);
-         break;
+    switch (b->qtype)
+    {
+    case SQL_INSERT:
+        /* ther is no where clasue, so we do the set as a utility */
+        sqlBuild_Set_Str (b, tag, val);
+        break;
 
-      case SQL_UPDATE:
-      case SQL_SELECT:
-      case SQL_DELETE:
-         val = sqlEscapeString (b->escape, val);
+    case SQL_UPDATE:
+    case SQL_SELECT:
+    case SQL_DELETE:
+        val = sqlEscapeString (b->escape, val);
 
-         if (b->where_need_and) b->pval = stpcpy(b->pval, " AND ");
-         b->where_need_and = 1;
+        if (b->where_need_and) b->pval = stpcpy(b->pval, " AND ");
+        b->where_need_and = 1;
 
-         b->pval = stpcpy(b->pval, tag);
-         b->pval = stpcpy(b->pval, "='");
-         b->pval = stpcpy(b->pval, val);
-         b->pval = stpcpy(b->pval, "'");
+        b->pval = stpcpy(b->pval, tag);
+        b->pval = stpcpy(b->pval, "='");
+        b->pval = stpcpy(b->pval, val);
+        b->pval = stpcpy(b->pval, "'");
 
-         break;
+        break;
 
-      default:
-         PERR ("mustn't happen");
-   };
+    default:
+        PERR ("mustn't happen");
+    };
 }
 
 /* ================================================ */
@@ -349,9 +356,9 @@
 void
 sqlBuild_Where_GUID (sqlBuilder *b, const char *tag, const GUID *val)
 {
-  char guid_str[GUID_ENCODING_LENGTH+1];
-  guid_to_string_buff(val, guid_str);
-  sqlBuild_Where_Str (b, tag, guid_str);
+    char guid_str[GUID_ENCODING_LENGTH+1];
+    guid_to_string_buff(val, guid_str);
+    sqlBuild_Where_Str (b, tag, guid_str);
 }
 
 /* ================================================ */
@@ -359,9 +366,9 @@
 void
 sqlBuild_Where_Int32 (sqlBuilder *b, const char *tag, gint32 val)
 {
-  char str[40];
-  snprintf (str, 40, "%d", val);
-  sqlBuild_Where_Str (b, tag, str);
+    char str[40];
+    snprintf (str, 40, "%d", val);
+    sqlBuild_Where_Str (b, tag, str);
 }
 
 /* ================================================ */
@@ -369,28 +376,28 @@
 const char *
 sqlBuild_Query (sqlBuilder *b)
 {
-   if (!b) return NULL;
+    if (!b) return NULL;
 
-   switch (b->qtype) 
-   {
-      case SQL_INSERT:
-         b->ptag = stpcpy(b->ptag, b->val_base);
-         b->ptag = stpcpy(b->ptag, ");");
-         break;
+    switch (b->qtype)
+    {
+    case SQL_INSERT:
+        b->ptag = stpcpy(b->ptag, b->val_base);
+        b->ptag = stpcpy(b->ptag, ");");
+        break;
 
-      case SQL_UPDATE:
-      case SQL_SELECT:
-      case SQL_DELETE:
-         b->ptag = stpcpy(b->ptag, b->val_base);
-         b->ptag = stpcpy(b->ptag, ";");
-         break;
+    case SQL_UPDATE:
+    case SQL_SELECT:
+    case SQL_DELETE:
+        b->ptag = stpcpy(b->ptag, b->val_base);
+        b->ptag = stpcpy(b->ptag, ";");
+        break;
 
-      default:
-         PERR ("mustn't happen");
-   };
-   
-   PINFO ("%s\n", b->tag_base);
-   return b->tag_base;
+    default:
+        PERR ("mustn't happen");
+    };
+
+    PINFO ("%s\n", b->tag_base);
+    return b->tag_base;
 }
 
 /* ================ END OF FILE ==================== */

Modified: gnucash/trunk/src/backend/postgres/builder.h
===================================================================
--- gnucash/trunk/src/backend/postgres/builder.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/builder.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -26,12 +26,12 @@
  *
  * FUNCTION:
  * Generic SQL query builder.  This class can be sued to construct
- * a basic sql query statement (of the type 'select', 'update' or 
- * 'insert') by simply making C calls indicating the table and the 
+ * a basic sql query statement (of the type 'select', 'update' or
+ * 'insert') by simply making C calls indicating the table and the
  * fields to query.
  *
  * Its fairly limited in the range of sql syntax that it supports,
- * but on the other hand, the code here is/should be general enough 
+ * but on the other hand, the code here is/should be general enough
  * to work with  any SQL implementation.
  *
  * HISTORY:
@@ -45,11 +45,12 @@
 
 #define SQL_DBL_FMT "%24.18g"
 
-typedef enum {
-   SQL_UPDATE = 'm',  /* m == modify */
-   SQL_INSERT = 'a',  /* a == add */
-   SQL_SELECT = 'q',  /* q == query */
-   SQL_DELETE = 'd'   /* d == drop, delete */
+typedef enum
+{
+    SQL_UPDATE = 'm',  /* m == modify */
+    SQL_INSERT = 'a',  /* a == add */
+    SQL_SELECT = 'q',  /* q == query */
+    SQL_DELETE = 'd'   /* d == drop, delete */
 } sqlBuild_QType;
 
 typedef struct _builder sqlBuilder;
@@ -57,11 +58,11 @@
 sqlBuilder * sqlBuilder_new(void);
 void sqlBuilder_destroy (sqlBuilder *);
 
-/* The sqlBuild_Table() routine starts building a new SQL query 
+/* The sqlBuild_Table() routine starts building a new SQL query
  *    on table 'tablename'.  Any previously started query is erased.
  *
- *    When building 'select' type statments, crude table joins are 
- *    supported: the 'tablename' can in fact be a comma-separated list 
+ *    When building 'select' type statments, crude table joins are
+ *    supported: the 'tablename' can in fact be a comma-separated list
  *    of tables.  This field is copied directly as follows:
  *    "SELECT ... FROM tablename WHERE ..." so anything valid in that
  *    position is tolerated.
@@ -93,14 +94,14 @@
 void sqlBuild_Where_Int32 (sqlBuilder *b, const char *tag, gint32 val);
 
 
-/* The sqlBuild_Query() routine returns a valid SQL query 
- *    statement that reflects the set of build calls just made.   
- *    This string is freed when sqlBuilder_destroy() is called, 
+/* The sqlBuild_Query() routine returns a valid SQL query
+ *    statement that reflects the set of build calls just made.
+ *    This string is freed when sqlBuilder_destroy() is called,
  *    so make a copy if you need it.
  *
- *    This resulting query string is probably general enough to 
- *    work with almost any SQL db, I beleive.     
- */   
+ *    This resulting query string is probably general enough to
+ *    work with almost any SQL db, I beleive.
+ */
 const char *sqlBuild_Query (sqlBuilder *b);
 
 

Modified: gnucash/trunk/src/backend/postgres/checkpoint.c
===================================================================
--- gnucash/trunk/src/backend/postgres/checkpoint.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/checkpoint.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -20,7 +20,7 @@
  * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
 \********************************************************************/
 
-/* 
+/*
  * FILE:
  * checkpoint.c
  *
@@ -30,17 +30,17 @@
  *
  * HISTORY:
  * Copyright (c) 2000, 2001 Linas Vepstas
- * 
+ *
  */
 
 #include "config.h"
 #include <glib.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>  
-#include <sys/types.h>  
+#include <string.h>
+#include <sys/types.h>
 
-#include <libpq-fe.h>  
+#include <libpq-fe.h>
 
 #include "Account.h"
 #include "AccountP.h"
@@ -53,7 +53,7 @@
 
 #include "putil.h"
 
-static QofLogModule log_module = GNC_MOD_BACKEND; 
+static QofLogModule log_module = GNC_MOD_BACKEND;
 
 /* ============================================================= */
 /* include autogenerated code */
@@ -67,167 +67,176 @@
 static void
 pgendAccountRecomputeAllCheckpoints (PGBackend *be, const GUID *acct_guid)
 {
-   Timespec this_ts, next_ts;
+    Timespec this_ts, next_ts;
 #ifndef HAVE_GLIB29
-   GMemChunk *chunk;
+    GMemChunk *chunk;
 #endif
-   GList *node, *checkpoints = NULL;
-   PGresult *result;
-   Checkpoint *bp;
-   char *p;
-   int i;
-   int nck;
-   Account *acc;
-   const char *commodity_name, *guid_string;
+    GList *node, *checkpoints = NULL;
+    PGresult *result;
+    Checkpoint *bp;
+    char *p;
+    int i;
+    int nck;
+    Account *acc;
+    const char *commodity_name, *guid_string;
 
-   if (!be) return;
-   ENTER("be=%p", be);
+    if (!be) return;
+    ENTER("be=%p", be);
 
-   guid_string = guid_to_string (acct_guid);
-   acc = pgendAccountLookup (be, acct_guid);
-   commodity_name =
-     gnc_commodity_get_unique_name (xaccAccountGetCommodity(acc));
+    guid_string = guid_to_string (acct_guid);
+    acc = pgendAccountLookup (be, acct_guid);
+    commodity_name =
+        gnc_commodity_get_unique_name (xaccAccountGetCommodity(acc));
 
 #ifndef HAVE_GLIB29
-   chunk = g_mem_chunk_create (Checkpoint, 300, G_ALLOC_ONLY);
+    chunk = g_mem_chunk_create (Checkpoint, 300, G_ALLOC_ONLY);
 #endif
 
-   /* prevent others from inserting any splits while we recompute 
-    * the checkpoints. (hack alert -verify that this is the correct
-    * lock) */
-   p = "BEGIN WORK;\n"
-       "LOCK TABLE gncCheckpoint IN ACCESS EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncSplit IN SHARE MODE;\n";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    /* prevent others from inserting any splits while we recompute
+     * the checkpoints. (hack alert -verify that this is the correct
+     * lock) */
+    p = "BEGIN WORK;\n"
+        "LOCK TABLE gncCheckpoint IN ACCESS EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncSplit IN SHARE MODE;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   /* Blow all the old checkpoints for this account out of the water.
-    * This should help ensure against accidental corruption.
-    */
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "DELETE FROM gncCheckpoint WHERE accountGuid='");
-   p = guid_to_string_buff (acct_guid, p);
-   p = stpcpy (p, "';");
-   SEND_QUERY (be,be->buff, );
-   FINISH_QUERY(be->connection);
+    /* Blow all the old checkpoints for this account out of the water.
+     * This should help ensure against accidental corruption.
+     */
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "DELETE FROM gncCheckpoint WHERE accountGuid='");
+    p = guid_to_string_buff (acct_guid, p);
+    p = stpcpy (p, "';");
+    SEND_QUERY (be, be->buff, );
+    FINISH_QUERY(be->connection);
 
-   /* malloc a new checkpoint, set it to the dawn of unix time ... */
+    /* malloc a new checkpoint, set it to the dawn of unix time ... */
 #ifdef HAVE_GLIB29
-   bp = g_slice_alloc0 (sizeof(Checkpoint));
+    bp = g_slice_alloc0 (sizeof(Checkpoint));
 #else
-   bp = g_chunk_new0 (Checkpoint, chunk);
+    bp = g_chunk_new0 (Checkpoint, chunk);
 #endif
-   checkpoints = g_list_prepend (checkpoints, bp);
-   this_ts = gnc_iso8601_to_timespec_gmt (CK_EARLIEST_DATE);
-   bp->date_start = this_ts;
-   bp->account_guid = acct_guid;
-   bp->commodity = commodity_name;
+    checkpoints = g_list_prepend (checkpoints, bp);
+    this_ts = gnc_iso8601_to_timespec_gmt (CK_EARLIEST_DATE);
+    bp->date_start = this_ts;
+    bp->account_guid = acct_guid;
+    bp->commodity = commodity_name;
 
-   /* loop over entries, creating a set of evenly-spaced checkpoints */
-   nck = MIN_CHECKPOINT_COUNT;
-   while (1)
-   {
-      p = be->buff; *p = 0;
-      p = stpcpy (p, "SELECT gncTransaction.date_posted"
-                     "    FROM gncTransaction, gncSplit"
-                     "    WHERE"
-                     "        gncSplit.transguid = gncTransaction.transguid AND"
-                     "        gncSplit.accountguid='");
-      p = stpcpy (p, guid_string);
-      p = stpcpy (p, "'"
-                     "    ORDER BY gncTransaction.date_posted ASC"
-                     "    LIMIT 2 OFFSET ");
-      p += sprintf (p, "%d", nck);
-      p = stpcpy (p, ";");
-      SEND_QUERY (be,be->buff, );
+    /* loop over entries, creating a set of evenly-spaced checkpoints */
+    nck = MIN_CHECKPOINT_COUNT;
+    while (1)
+    {
+        p = be->buff;
+        *p = 0;
+        p = stpcpy (p, "SELECT gncTransaction.date_posted"
+                    "    FROM gncTransaction, gncSplit"
+                    "    WHERE"
+                    "        gncSplit.transguid = gncTransaction.transguid AND"
+                    "        gncSplit.accountguid='");
+        p = stpcpy (p, guid_string);
+        p = stpcpy (p, "'"
+                    "    ORDER BY gncTransaction.date_posted ASC"
+                    "    LIMIT 2 OFFSET ");
+        p += sprintf (p, "%d", nck);
+        p = stpcpy (p, ";");
+        SEND_QUERY (be, be->buff, );
 
-      i=0; 
-      do {
-         GET_RESULTS (be->connection, result);
-         {
-            int jrows;
-            int ncols = PQnfields (result);
-            jrows = PQntuples (result);
-            PINFO ("query result %d has %d rows and %d cols",
-               i, jrows, ncols);
+        i = 0;
+        do
+        {
+            GET_RESULTS (be->connection, result);
+            {
+                int jrows;
+                int ncols = PQnfields (result);
+                jrows = PQntuples (result);
+                PINFO ("query result %d has %d rows and %d cols",
+                       i, jrows, ncols);
 
-            if (0 == jrows) {
-                FINISH_QUERY(be->connection);
-                goto done; 
+                if (0 == jrows)
+                {
+                    FINISH_QUERY(be->connection);
+                    goto done;
+                }
+
+                if (0 == i) this_ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted", 0));
+                if (2 == jrows)
+                {
+                    next_ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted", 1));
+                }
+                else if (1 == i)
+                {
+                    next_ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted", 0));
+                }
+                PQclear (result);
+                i++;
             }
+        }
+        while (result);
 
-            if (0 == i) this_ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted",0));
-            if (2 == jrows) {
-               next_ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted",1));
-            } else if (1 == i) {
-               next_ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted",0));
-            } 
-            PQclear (result);
-            i++;
-         }
-      } while (result);
+        /* lets see if its time to start a new checkpoint */
+        /* look for splits that occur at least ten seconds apart */
+        this_ts.tv_sec += 10;
+        if (timespec_cmp (&this_ts, &next_ts) < 0)
+        {
+            /* Set checkpoint five seconds back. This is safe,
+             * because we looked for a 10 second gap above */
+            this_ts.tv_sec -= 5;
+            bp->date_end = this_ts;
 
-      /* lets see if its time to start a new checkpoint */
-      /* look for splits that occur at least ten seconds apart */
-      this_ts.tv_sec += 10;
-      if (timespec_cmp (&this_ts, &next_ts) < 0)
-      {
-         /* Set checkpoint five seconds back. This is safe,
-          * because we looked for a 10 second gap above */
-         this_ts.tv_sec -= 5;
-         bp->date_end = this_ts;
-
-         /* and build a new checkpoint */
+            /* and build a new checkpoint */
 #ifdef HAVE_GLIB29
-	 bp = g_slice_alloc0 (sizeof(Checkpoint));
+            bp = g_slice_alloc0 (sizeof(Checkpoint));
 #else
-	 bp = g_chunk_new0 (Checkpoint, chunk);
+            bp = g_chunk_new0 (Checkpoint, chunk);
 #endif
-         checkpoints = g_list_prepend (checkpoints, bp);
-         bp->date_start = this_ts;
-         bp->account_guid = acct_guid;
-         bp->commodity = commodity_name;
-         nck += MIN_CHECKPOINT_COUNT;
-      }
-      else 
-      {
-         /* step one at a time until we find at least a ten-second gap */
-         nck += 1;
-      }
-   }
+            checkpoints = g_list_prepend (checkpoints, bp);
+            bp->date_start = this_ts;
+            bp->account_guid = acct_guid;
+            bp->commodity = commodity_name;
+            nck += MIN_CHECKPOINT_COUNT;
+        }
+        else
+        {
+            /* step one at a time until we find at least a ten-second gap */
+            nck += 1;
+        }
+    }
 
 done:
 
-   /* set the timestamp on the final checkpoint into the distant future */
-   this_ts = gnc_iso8601_to_timespec_gmt (CK_LAST_DATE);
-   bp->date_end = this_ts;
+    /* set the timestamp on the final checkpoint into the distant future */
+    this_ts = gnc_iso8601_to_timespec_gmt (CK_LAST_DATE);
+    bp->date_end = this_ts;
 
-   /* now store the checkpoints */
-   for (node = checkpoints; node; node = node->next)
-   {
-      bp = (Checkpoint *) node->data;
-      pgendStoreOneCheckpointOnly (be, bp, SQL_INSERT);
-   }
+    /* now store the checkpoints */
+    for (node = checkpoints; node; node = node->next)
+    {
+        bp = (Checkpoint *) node->data;
+        pgendStoreOneCheckpointOnly (be, bp, SQL_INSERT);
+    }
 
-   g_list_free (checkpoints);
+    g_list_free (checkpoints);
 #ifndef HAVE_GLIB29
-   g_mem_chunk_destroy (chunk);
+    g_mem_chunk_destroy (chunk);
 #endif
 
-   /* finally, let the sql server do the heavy lifting of computing the 
-    * subtotal balances */
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "UPDATE gncCheckpoint SET "
-          "   balance            = (gncsubtotalbalance        (accountGuid, date_start, date_end )),"
-          "   cleared_balance    = (gncsubtotalclearedbalance (accountGuid, date_start, date_end )),"
-          "   reconciled_balance = (gncsubtotalreconedbalance (accountGuid, date_start, date_end )) "
-          " WHERE accountGuid='");
-   p = stpcpy (p, guid_string);
-   p = stpcpy (p, "';\n");
-   p = stpcpy (p, "COMMIT WORK;\n"
-                  "NOTIFY gncCheckpoint;\n");
-   SEND_QUERY (be,be->buff, );
-   FINISH_QUERY(be->connection);
+    /* finally, let the sql server do the heavy lifting of computing the
+     * subtotal balances */
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "UPDATE gncCheckpoint SET "
+                "   balance            = (gncsubtotalbalance        (accountGuid, date_start, date_end )),"
+                "   cleared_balance    = (gncsubtotalclearedbalance (accountGuid, date_start, date_end )),"
+                "   reconciled_balance = (gncsubtotalreconedbalance (accountGuid, date_start, date_end )) "
+                " WHERE accountGuid='");
+    p = stpcpy (p, guid_string);
+    p = stpcpy (p, "';\n");
+    p = stpcpy (p, "COMMIT WORK;\n"
+                "NOTIFY gncCheckpoint;\n");
+    SEND_QUERY (be, be->buff, );
+    FINISH_QUERY(be->connection);
 }
 
 /* ============================================================= */
@@ -236,17 +245,17 @@
 void
 pgendAccountTreeRecomputeAllCheckpoints (PGBackend *be, Account *parent)
 {
-   GList *acclist, *node;
+    GList *acclist, *node;
 
-   pgendAccountRecomputeAllCheckpoints (be, xaccAccountGetGUID(parent));
+    pgendAccountRecomputeAllCheckpoints (be, xaccAccountGetGUID(parent));
 
-   acclist = gnc_account_get_descendants(parent);
-   for (node = acclist; node; node=node->next)
-   {
-      Account *acc = (Account *) node->data;
-      pgendAccountRecomputeAllCheckpoints (be, xaccAccountGetGUID(acc));
-   }
-   g_list_free (acclist);
+    acclist = gnc_account_get_descendants(parent);
+    for (node = acclist; node; node = node->next)
+    {
+        Account *acc = (Account *) node->data;
+        pgendAccountRecomputeAllCheckpoints (be, xaccAccountGetGUID(acc));
+    }
+    g_list_free (acclist);
 }
 
 /* ============================================================= */
@@ -255,30 +264,31 @@
 void
 pgendAccountRecomputeOneCheckpoint (PGBackend *be, Account *acc, Timespec ts)
 {
-   char *p, dbuf[80];
+    char *p, dbuf[80];
 
-   gnc_timespec_to_iso8601_buff (ts, dbuf);
+    gnc_timespec_to_iso8601_buff (ts, dbuf);
 
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "BEGIN WORK;\n"
-                  "LOCK TABLE gncCheckpoint IN ACCESS EXCLUSIVE MODE;\n"
-                  "LOCK TABLE gncSplit IN SHARE MODE;\n"
-                  "UPDATE gncCheckpoint SET "
-          "   balance            = (gncsubtotalbalance        (accountGuid, date_start, date_end )),"
-          "   cleared_balance    = (gncsubtotalclearedbalance (accountGuid, date_start, date_end )),"
-          "   reconciled_balance = (gncsubtotalreconedbalance (accountGuid, date_start, date_end )) "
-          " WHERE accountGuid='");
-   p = guid_to_string_buff (xaccAccountGetGUID(acc), p);
-   p = stpcpy (p, "' AND date_start <= '");
-   p = stpcpy (p, dbuf);
-   p = stpcpy (p, "' AND date_end > '");
-   p = stpcpy (p, dbuf);
-   p = stpcpy (p, "';\n");
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "BEGIN WORK;\n"
+                "LOCK TABLE gncCheckpoint IN ACCESS EXCLUSIVE MODE;\n"
+                "LOCK TABLE gncSplit IN SHARE MODE;\n"
+                "UPDATE gncCheckpoint SET "
+                "   balance            = (gncsubtotalbalance        (accountGuid, date_start, date_end )),"
+                "   cleared_balance    = (gncsubtotalclearedbalance (accountGuid, date_start, date_end )),"
+                "   reconciled_balance = (gncsubtotalreconedbalance (accountGuid, date_start, date_end )) "
+                " WHERE accountGuid='");
+    p = guid_to_string_buff (xaccAccountGetGUID(acc), p);
+    p = stpcpy (p, "' AND date_start <= '");
+    p = stpcpy (p, dbuf);
+    p = stpcpy (p, "' AND date_end > '");
+    p = stpcpy (p, dbuf);
+    p = stpcpy (p, "';\n");
 
-   p = stpcpy (p, "COMMIT WORK;\n"
-                  "NOTIFY gncCheckpoint;\n");
-   SEND_QUERY (be,be->buff, );
-   FINISH_QUERY(be->connection);
+    p = stpcpy (p, "COMMIT WORK;\n"
+                "NOTIFY gncCheckpoint;\n");
+    SEND_QUERY (be, be->buff, );
+    FINISH_QUERY(be->connection);
 }
 
 /* ============================================================= */
@@ -287,105 +297,108 @@
 void
 pgendTransactionRecomputeCheckpoints (PGBackend *be, Transaction *trans)
 {
-   char *p;
+    char *p;
 
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "BEGIN WORK;\n"
-                  "LOCK TABLE gncCheckpoint IN ACCESS EXCLUSIVE MODE;\n"
-                  "LOCK TABLE gncTransaction IN SHARE MODE;\n"
-                  "LOCK TABLE gncSplit IN SHARE MODE;\n"
-                  "UPDATE gncCheckpoint SET "
-   "  balance            = (gncsubtotalbalance        (gncSplit.accountGuid, date_start, date_end )),"
-   "  cleared_balance    = (gncsubtotalclearedbalance (gncSplit.accountGuid, date_start, date_end )),"
-   "  reconciled_balance = (gncsubtotalreconedbalance (gncSplit.accountGuid, date_start, date_end )) "
-   " WHERE gncSplit.transGuid = '");
-   p = guid_to_string_buff (xaccTransGetGUID(trans), p);
-   p = stpcpy (p, "' AND gncTransaction.transGuid = gncSplit.transGuid "
-                  "  AND gncCheckpoint.accountGuid = gncSplit.accountGuid "
-                  "  AND date_start <= gncTransaction.date_posted "
-                  "  AND date_end > gncTransaction.date_posted;\n"
-                  "COMMIT WORK;\n"
-                  "NOTIFY gncCheckpoint;\n");
-   SEND_QUERY (be,be->buff, );
-   FINISH_QUERY(be->connection);
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "BEGIN WORK;\n"
+                "LOCK TABLE gncCheckpoint IN ACCESS EXCLUSIVE MODE;\n"
+                "LOCK TABLE gncTransaction IN SHARE MODE;\n"
+                "LOCK TABLE gncSplit IN SHARE MODE;\n"
+                "UPDATE gncCheckpoint SET "
+                "  balance            = (gncsubtotalbalance        (gncSplit.accountGuid, date_start, date_end )),"
+                "  cleared_balance    = (gncsubtotalclearedbalance (gncSplit.accountGuid, date_start, date_end )),"
+                "  reconciled_balance = (gncsubtotalreconedbalance (gncSplit.accountGuid, date_start, date_end )) "
+                " WHERE gncSplit.transGuid = '");
+    p = guid_to_string_buff (xaccTransGetGUID(trans), p);
+    p = stpcpy (p, "' AND gncTransaction.transGuid = gncSplit.transGuid "
+                "  AND gncCheckpoint.accountGuid = gncSplit.accountGuid "
+                "  AND date_start <= gncTransaction.date_posted "
+                "  AND date_end > gncTransaction.date_posted;\n"
+                "COMMIT WORK;\n"
+                "NOTIFY gncCheckpoint;\n");
+    SEND_QUERY (be, be->buff, );
+    FINISH_QUERY(be->connection);
 }
 
 /* ============================================================= */
-/* get checkpoint value for the account 
+/* get checkpoint value for the account
  * We find the checkpoint which matches the account and commodity,
- * for the first date immediately preceeding the date.  
+ * for the first date immediately preceeding the date.
  * Then we fill in the balance fields for the returned query.
  */
 
-static gpointer 
+static gpointer
 get_checkpoint_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   Checkpoint *chk = (Checkpoint *) data;
-   chk->balance = strtoll(DB_GET_VAL("baln", j), NULL, 0);
-   chk->cleared_balance = strtoll(DB_GET_VAL("cleared_baln", j), NULL, 0);
-   chk->reconciled_balance = strtoll(DB_GET_VAL("reconed_baln", j), NULL, 0);
-   return data;
+    Checkpoint *chk = (Checkpoint *) data;
+    chk->balance = strtoll(DB_GET_VAL("baln", j), NULL, 0);
+    chk->cleared_balance = strtoll(DB_GET_VAL("cleared_baln", j), NULL, 0);
+    chk->reconciled_balance = strtoll(DB_GET_VAL("reconed_baln", j), NULL, 0);
+    return data;
 }
 
-static gpointer 
+static gpointer
 get_checkpoint_date_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   Checkpoint *chk = (Checkpoint *) data;
-   chk->date_start = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_start", j));
-   return data;
+    Checkpoint *chk = (Checkpoint *) data;
+    chk->date_start = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_start", j));
+    return data;
 }
 
 static void
 pgendAccountGetCheckpoint (PGBackend *be, Checkpoint *chk)
 {
-   sqlEscape *escape;
-   char guid_str[80], end_str[80];
-   char * p;
+    sqlEscape *escape;
+    char guid_str[80], end_str[80];
+    char * p;
 
-   if (!be || !chk) return;
-   ENTER("be=%p", be);
+    if (!be || !chk) return;
+    ENTER("be=%p", be);
 
-   escape = sqlEscape_new ();
+    escape = sqlEscape_new ();
 
-   guid_to_string_buff (chk->account_guid, guid_str);
-   gnc_timespec_to_iso8601_buff (chk->date_end, end_str);
+    guid_to_string_buff (chk->account_guid, guid_str);
+    gnc_timespec_to_iso8601_buff (chk->date_end, end_str);
 
-   /* sum up the total of all the checpoints before this date */
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "SELECT sum(balance) AS baln, "
-                  "       sum(cleared_balance) AS cleared_baln, "
-                  "       sum(reconciled_balance) AS reconed_baln "
-                  "    FROM gncCheckpoint "
-                  "    WHERE accountGuid='");
-   p = stpcpy (p, guid_str);
-   p = stpcpy (p, "'   AND commodity='");
-   p = stpcpy (p, sqlEscapeString (escape, chk->commodity));
-   p = stpcpy (p, "'   AND date_end <'");
-   p = stpcpy (p, end_str);
-   p = stpcpy (p, "';");
-   SEND_QUERY (be,be->buff, );
+    /* sum up the total of all the checpoints before this date */
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "SELECT sum(balance) AS baln, "
+                "       sum(cleared_balance) AS cleared_baln, "
+                "       sum(reconciled_balance) AS reconed_baln "
+                "    FROM gncCheckpoint "
+                "    WHERE accountGuid='");
+    p = stpcpy (p, guid_str);
+    p = stpcpy (p, "'   AND commodity='");
+    p = stpcpy (p, sqlEscapeString (escape, chk->commodity));
+    p = stpcpy (p, "'   AND date_end <'");
+    p = stpcpy (p, end_str);
+    p = stpcpy (p, "';");
+    SEND_QUERY (be, be->buff, );
 
-   sqlEscape_destroy (escape);
-   escape = NULL;
+    sqlEscape_destroy (escape);
+    escape = NULL;
 
-   pgendGetResults (be, get_checkpoint_cb, chk);
+    pgendGetResults (be, get_checkpoint_cb, chk);
 
-   /* now get the ending date of the last checkpoint,
-    * aka the starting date of the next checkpoint */
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "SELECT date_start FROM gncCheckpoint "
-                  "    WHERE accountGuid='");
-   p = stpcpy (p, guid_str);
-   p = stpcpy (p, "'   AND date_start < '");
-   p = stpcpy (p, end_str);
-   p = stpcpy (p, "'   ORDER BY date_start DESC LIMIT 1;");
-   SEND_QUERY (be,be->buff, );
+    /* now get the ending date of the last checkpoint,
+     * aka the starting date of the next checkpoint */
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "SELECT date_start FROM gncCheckpoint "
+                "    WHERE accountGuid='");
+    p = stpcpy (p, guid_str);
+    p = stpcpy (p, "'   AND date_start < '");
+    p = stpcpy (p, end_str);
+    p = stpcpy (p, "'   ORDER BY date_start DESC LIMIT 1;");
+    SEND_QUERY (be, be->buff, );
 
-   /* provide default value, in case there are no checkpoints */
-   chk->date_start = gnc_iso8601_to_timespec_gmt (CK_EARLIEST_DATE);
-   pgendGetResults (be, get_checkpoint_date_cb, chk);
+    /* provide default value, in case there are no checkpoints */
+    chk->date_start = gnc_iso8601_to_timespec_gmt (CK_EARLIEST_DATE);
+    pgendGetResults (be, get_checkpoint_date_cb, chk);
 
-   LEAVE("be=%p", be);
+    LEAVE("be=%p", be);
 }
 
 /* ============================================================= */
@@ -394,45 +407,46 @@
 static void
 pgendAccountGetPartialBalance (PGBackend *be, Checkpoint *chk)
 {
-   char guid_str[80], start_str[80], end_str[80];
-   char * p;
+    char guid_str[80], start_str[80], end_str[80];
+    char * p;
 
-   if (!be || !chk) return;
-   ENTER("be=%p", be);
+    if (!be || !chk) return;
+    ENTER("be=%p", be);
 
-   guid_to_string_buff (chk->account_guid, guid_str);
-   gnc_timespec_to_iso8601_buff (chk->date_start, start_str);
-   gnc_timespec_to_iso8601_buff (chk->date_end, end_str);
-   
-   /* create the query we need */
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "SELECT gncSubtotalBalance ('");
-   p = stpcpy (p, guid_str);
-   p = stpcpy (p, "', '");
-   p = stpcpy (p, start_str);
-   p = stpcpy (p, "', '");
-   p = stpcpy (p, end_str);
-   p = stpcpy (p, "') AS baln, "
-                  " gncSubtotalClearedBalance ('");
-   p = stpcpy (p, guid_str);
-   p = stpcpy (p, "', '");
-   p = stpcpy (p, start_str);
-   p = stpcpy (p, "', '");
-   p = stpcpy (p, end_str);
-   p = stpcpy (p, "') AS cleared_baln, "
-                  " gncSubtotalReconedBalance ('");
-   p = stpcpy (p, guid_str);
-   p = stpcpy (p, "', '");
-   p = stpcpy (p, start_str);
-   p = stpcpy (p, "', '");
-   p = stpcpy (p, end_str);
-   p = stpcpy (p, "') AS reconed_baln;");
+    guid_to_string_buff (chk->account_guid, guid_str);
+    gnc_timespec_to_iso8601_buff (chk->date_start, start_str);
+    gnc_timespec_to_iso8601_buff (chk->date_end, end_str);
 
-   SEND_QUERY (be,be->buff, );
+    /* create the query we need */
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "SELECT gncSubtotalBalance ('");
+    p = stpcpy (p, guid_str);
+    p = stpcpy (p, "', '");
+    p = stpcpy (p, start_str);
+    p = stpcpy (p, "', '");
+    p = stpcpy (p, end_str);
+    p = stpcpy (p, "') AS baln, "
+                " gncSubtotalClearedBalance ('");
+    p = stpcpy (p, guid_str);
+    p = stpcpy (p, "', '");
+    p = stpcpy (p, start_str);
+    p = stpcpy (p, "', '");
+    p = stpcpy (p, end_str);
+    p = stpcpy (p, "') AS cleared_baln, "
+                " gncSubtotalReconedBalance ('");
+    p = stpcpy (p, guid_str);
+    p = stpcpy (p, "', '");
+    p = stpcpy (p, start_str);
+    p = stpcpy (p, "', '");
+    p = stpcpy (p, end_str);
+    p = stpcpy (p, "') AS reconed_baln;");
 
-   pgendGetResults (be, get_checkpoint_cb, chk);
+    SEND_QUERY (be, be->buff, );
 
-   LEAVE("be=%p", be);
+    pgendGetResults (be, get_checkpoint_cb, chk);
+
+    LEAVE("be=%p", be);
 }
 
 /* ============================================================= */
@@ -441,98 +455,98 @@
 void
 pgendAccountGetBalance (PGBackend *be, Account *acc, Timespec as_of_date)
 {
-   Checkpoint chk;
-   const gnc_commodity *com;
-   gint64 b, cl_b, rec_b, deno;
-   gnc_numeric baln;
-   gnc_numeric cleared_baln;
-   gnc_numeric reconciled_baln;
+    Checkpoint chk;
+    const gnc_commodity *com;
+    gint64 b, cl_b, rec_b, deno;
+    gnc_numeric baln;
+    gnc_numeric cleared_baln;
+    gnc_numeric reconciled_baln;
 
-   if (!be || !acc) return;
-   ENTER("be=%p", be);
+    if (!be || !acc) return;
+    ENTER("be=%p", be);
 
-   /* setup what we will match for */
-   chk.date_end = as_of_date;
+    /* setup what we will match for */
+    chk.date_end = as_of_date;
 
-   com = xaccAccountGetCommodity(acc);
-   if (!com)
-   {
+    com = xaccAccountGetCommodity(acc);
+    if (!com)
+    {
         PERR("account %s has no commodity",
              guid_to_string (xaccAccountGetGUID (acc)));
         return;
-   }
+    }
 
-   chk.commodity = gnc_commodity_get_unique_name(com);
-   chk.account_guid = xaccAccountGetGUID (acc);
-   chk.balance = 0;
-   chk.cleared_balance = 0;
-   chk.reconciled_balance = 0;
+    chk.commodity = gnc_commodity_get_unique_name(com);
+    chk.account_guid = xaccAccountGetGUID (acc);
+    chk.balance = 0;
+    chk.cleared_balance = 0;
+    chk.reconciled_balance = 0;
 
-   /* get the checkpoint */
-   pgendAccountGetCheckpoint (be, &chk);
+    /* get the checkpoint */
+    pgendAccountGetCheckpoint (be, &chk);
 
-   b = chk.balance;
-   cl_b = chk.cleared_balance;
-   rec_b = chk.reconciled_balance;
-   deno = gnc_commodity_get_fraction (com);
+    b = chk.balance;
+    cl_b = chk.cleared_balance;
+    rec_b = chk.reconciled_balance;
+    deno = gnc_commodity_get_fraction (com);
 
-   {
-      char buf[80];
-      gnc_timespec_to_iso8601_buff (chk.date_start, buf);
-      DEBUG("%s balance to %s baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT " clr=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT " rcn=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, 
-            xaccAccountGetDescription (acc), buf,
-            b, deno, cl_b, deno, rec_b, deno);
-   }
+    {
+        char buf[80];
+        gnc_timespec_to_iso8601_buff (chk.date_start, buf);
+        DEBUG("%s balance to %s baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT " clr=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT " rcn=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
+              xaccAccountGetDescription (acc), buf,
+              b, deno, cl_b, deno, rec_b, deno);
+    }
 
-   /* add up loose entries since the checkpoint */
-   pgendAccountGetPartialBalance (be, &chk);
+    /* add up loose entries since the checkpoint */
+    pgendAccountGetPartialBalance (be, &chk);
 
-   b += chk.balance;
-   cl_b += chk.cleared_balance;
-   rec_b += chk.reconciled_balance;
+    b += chk.balance;
+    cl_b += chk.cleared_balance;
+    rec_b += chk.reconciled_balance;
 
-   /* set the account balances */
-   baln = gnc_numeric_create (b, deno);
-   cleared_baln = gnc_numeric_create (cl_b, deno);
-   reconciled_baln = gnc_numeric_create (rec_b, deno);
+    /* set the account balances */
+    baln = gnc_numeric_create (b, deno);
+    cleared_baln = gnc_numeric_create (cl_b, deno);
+    reconciled_baln = gnc_numeric_create (rec_b, deno);
 
-   g_object_set(acc,
-                "start-balance", &baln,
-                "start-cleared-balance", &cleared_baln,
-                "start-reconcoled-balance", &reconciled_baln,
-                NULL);
+    g_object_set(acc,
+                 "start-balance", &baln,
+                 "start-cleared-balance", &cleared_baln,
+                 "start-reconcoled-balance", &reconciled_baln,
+                 NULL);
 
-   {
+    {
         char buf[80];
         gnc_timespec_to_iso8601_buff (as_of_date, buf);
-        LEAVE("be=%p %s %s baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT " clr=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT " rcn=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, be, 
+        LEAVE("be=%p %s %s baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT " clr=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT " rcn=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, be,
               xaccAccountGetDescription (acc), buf,
               b, deno, cl_b, deno, rec_b, deno);
-   }
+    }
 }
 
 /* ============================================================= */
 /* get checkpoint value for all accounts */
 
 void
-pgendAccountTreeGetAllBalances (PGBackend *be, Account *root, 
-                          Timespec as_of_date)
+pgendAccountTreeGetAllBalances (PGBackend *be, Account *root,
+                                Timespec as_of_date)
 {
-   GList *acclist, *node;
+    GList *acclist, *node;
 
-   if (!be || !root) return;
-   ENTER("be=%p", be);
+    if (!be || !root) return;
+    ENTER("be=%p", be);
 
-   /* loop over all accounts */
-   acclist = gnc_account_get_descendants (root);
-   for (node=acclist; node; node=node->next)
-   {
-      Account *acc = (Account *) node->data;
-      pgendAccountGetBalance (be, acc, as_of_date);
-   }
+    /* loop over all accounts */
+    acclist = gnc_account_get_descendants (root);
+    for (node = acclist; node; node = node->next)
+    {
+        Account *acc = (Account *) node->data;
+        pgendAccountGetBalance (be, acc, as_of_date);
+    }
 
-   g_list_free (acclist);
-   LEAVE("be=%p", be);
+    g_list_free (acclist);
+    LEAVE("be=%p", be);
 }
 
 /* ======================== END OF FILE ======================== */

Modified: gnucash/trunk/src/backend/postgres/checkpoint.h
===================================================================
--- gnucash/trunk/src/backend/postgres/checkpoint.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/checkpoint.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -19,7 +19,7 @@
  * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
 \********************************************************************/
 
-/* 
+/*
  * FILE:
  * checkpoint.h
  *
@@ -43,28 +43,29 @@
 /* -------------------------------------------------------- */
 /* The balance checkpoint structure is used to store partial,
  * running balances.  The balances are correct for the checkpoint
- * date shown.  The commodity indicates what commodity the 
- * balances are valued in (they need not be in the same 
+ * date shown.  The commodity indicates what commodity the
+ * balances are valued in (they need not be in the same
  * commodity as the account)
  */
 
 /* the MIN_CHECKPOINT_COUNT value is the number of splits that
  * each checkpoint will handle, on avergage.  30 seems like a good
- * number.  The number of splits in a checkpoint will vary; 
- * checkpoints can only occur in between entry dates, so a 
- * bunch of entries with the same date will go into the same 
+ * number.  The number of splits in a checkpoint will vary;
+ * checkpoints can only occur in between entry dates, so a
+ * bunch of entries with the same date will go into the same
  * checkpoint (and there might be an arbitrarily large number of these)
  */
 #define MIN_CHECKPOINT_COUNT 30
 
-typedef struct _checkpoint {
-   const GUID *account_guid;
-   const char * commodity;
-   Timespec date_start;
-   Timespec date_end;
-   gint64 balance;
-   gint64 cleared_balance;
-   gint64 reconciled_balance;
+typedef struct _checkpoint
+{
+    const GUID *account_guid;
+    const char * commodity;
+    Timespec date_start;
+    Timespec date_end;
+    gint64 balance;
+    gint64 cleared_balance;
+    gint64 reconciled_balance;
 } Checkpoint;
 
 /* -------------------------------------------------------- */
@@ -82,7 +83,7 @@
 void pgendAccountTreeGetAllBalances (PGBackend *, Account *, Timespec as_of_date);
 
 /* The pgendAccountGetBalance() routine goes to the sql database and finds the
- *    balance as of the 'as_of_date' argument. It sets the starting balance for 
+ *    balance as of the 'as_of_date' argument. It sets the starting balance for
  *    this account based on that value.
  */
 void pgendAccountGetBalance (PGBackend *, Account *, Timespec as_of_date);

Modified: gnucash/trunk/src/backend/postgres/demo.c
===================================================================
--- gnucash/trunk/src/backend/postgres/demo.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/demo.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -2,73 +2,76 @@
 #include <stdio.h>
 #include <pgsql/libpq-fe.h>
 
-main () 
+main ()
 {
-   FILE *fh;
-   PGconn *conn;
-   int i, row, col, rc, nrows, ncols;
-   char * dbName = "gnc_bogus";
-   PGresult *result;
+    FILE *fh;
+    PGconn *conn;
+    int i, row, col, rc, nrows, ncols;
+    char * dbName = "gnc_bogus";
+    PGresult *result;
 
-   conn = PQsetdbLogin (NULL, NULL, NULL, NULL, dbName, NULL, NULL);
+    conn = PQsetdbLogin (NULL, NULL, NULL, NULL, dbName, NULL, NULL);
 
-   if (CONNECTION_BAD == PQstatus(conn))
-   {
-      printf("Fatal Error: Connection to database '%s' failed:\n",
-             dbName ? dbName : "(null)");
-      printf("\t%s", PQerrorMessage(conn));
-      PQfinish (conn);
-      exit (1);
-   }
+    if (CONNECTION_BAD == PQstatus(conn))
+    {
+        printf("Fatal Error: Connection to database '%s' failed:\n",
+               dbName ? dbName : "(null)");
+        printf("\t%s", PQerrorMessage(conn));
+        PQfinish (conn);
+        exit (1);
+    }
 
-   fh = fopen("/tmp/pgsql.trace","w");
-   PQtrace(conn, fh);
+    fh = fopen("/tmp/pgsql.trace", "w");
+    PQtrace(conn, fh);
 
-   rc = PQsendQuery (conn, "SELECT * FROM gncAccount;");
-   if (!rc) 
-   {
-      printf("Fatal Error: send query failed:\n");
-      printf("\t%s", PQerrorMessage(conn));
-      PQfinish (conn);
-      exit (1);
-   }
+    rc = PQsendQuery (conn, "SELECT * FROM gncAccount;");
+    if (!rc)
+    {
+        printf("Fatal Error: send query failed:\n");
+        printf("\t%s", PQerrorMessage(conn));
+        PQfinish (conn);
+        exit (1);
+    }
 
 
-   i = 0;
-   do {
-      ExecStatusType status;
-      int iacc, idesc;
+    i = 0;
+    do
+    {
+        ExecStatusType status;
+        int iacc, idesc;
 
-      result = PQgetResult(conn);
-      if (!result) break;
- 
-      status = PQresultStatus(result);
-      
-      if ((PGRES_COMMAND_OK != status) && 
-          (PGRES_TUPLES_OK  != status)) 
-      {
-         printf ("Error: failed to get result to query\n");
-         PQclear(result);
-         PQfinish (conn);
-         exit (2);
-      }
-      nrows = PQntuples (result);
-      ncols = PQnfields(result);
-      printf ("Info: query result %d has %d rows and %d cols\n", 
-              i, nrows, ncols);
+        result = PQgetResult(conn);
+        if (!result) break;
 
-      iacc = PQfnumber (result, "accountName");
-      idesc = PQfnumber (result, "description");
+        status = PQresultStatus(result);
 
-     printf ("accountName ===   description\n");
-      for (row=0; row<nrows; row++) {
-          printf ("%s ==== %s\n",
-                  PQgetvalue(result, row, iacc),
-                  PQgetvalue(result, row, idesc));
-      }
+        if ((PGRES_COMMAND_OK != status) &&
+                (PGRES_TUPLES_OK  != status))
+        {
+            printf ("Error: failed to get result to query\n");
+            PQclear(result);
+            PQfinish (conn);
+            exit (2);
+        }
+        nrows = PQntuples (result);
+        ncols = PQnfields(result);
+        printf ("Info: query result %d has %d rows and %d cols\n",
+                i, nrows, ncols);
 
-      i++;
-   } while (result);
+        iacc = PQfnumber (result, "accountName");
+        idesc = PQfnumber (result, "description");
 
-   PQfinish (conn);
+        printf ("accountName ===   description\n");
+        for (row = 0; row < nrows; row++)
+        {
+            printf ("%s ==== %s\n",
+                    PQgetvalue(result, row, iacc),
+                    PQgetvalue(result, row, idesc));
+        }
+
+        i++;
+    }
+    while (result);
+
+    PQfinish (conn);
 }

Modified: gnucash/trunk/src/backend/postgres/escape.c
===================================================================
--- gnucash/trunk/src/backend/postgres/escape.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/escape.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -35,90 +35,97 @@
 #include "gnc-engine.h"
 #include "escape.h"
 
-static QofLogModule log_module = GNC_MOD_BACKEND; 
+static QofLogModule log_module = GNC_MOD_BACKEND;
 
 /* ================================================ */
 
-struct _escape {
-   /* pointer to memory used for escaping arguments */
-   char * escape;
-   size_t esc_buflen;
+struct _escape
+{
+    /* pointer to memory used for escaping arguments */
+    char * escape;
+    size_t esc_buflen;
 };
 
 /* ================================================ */
-/* escape single-quote marks and backslashes so that the 
- * database SQL parser doesn't puke on the query string 
+/* escape single-quote marks and backslashes so that the
+ * database SQL parser doesn't puke on the query string
  */
 
 const char *
 sqlEscapeString (sqlEscape *b, const char *str)
 {
-   const char *p, *src_head;
-   char *dst_tail;
-   size_t len, slen;
+    const char *p, *src_head;
+    char *dst_tail;
+    size_t len, slen;
 
-   ENTER("str = %s", str);
-   
-   if (!b || !str) { LEAVE("(null) args"); return NULL; }
+    ENTER("str = %s", str);
 
-   /* if a string is escaped twice, just return the first */
-   if (b->escape == str) {
-       LEAVE("%s: already escaped", str);
-       return str;
-   }
+    if (!b || !str)
+    {
+        LEAVE("(null) args");
+        return NULL;
+    }
 
-   /* if nothing to escape, just return */
-   len = strlen (str);
-   slen = strcspn (str, "\\\'");
-   if (len == slen) {
-       LEAVE("nothing to escape");
-       return str;
-   }
+    /* if a string is escaped twice, just return the first */
+    if (b->escape == str)
+    {
+        LEAVE("%s: already escaped", str);
+        return str;
+    }
 
-   /* count to see how much space we'll need */
-   p = str + slen + 1;
-   while (*p)
-   {
-      len ++;
-      p += 1 + strcspn (p, "\\\'");
-   }
+    /* if nothing to escape, just return */
+    len = strlen (str);
+    slen = strcspn (str, "\\\'");
+    if (len == slen)
+    {
+        LEAVE("nothing to escape");
+        return str;
+    }
 
-   /* get more space, if needed */
-   if (len >= b->esc_buflen)
-   {
-      b->escape = g_realloc(b->escape, len+100);
-      b->esc_buflen = len+100;
-   }
+    /* count to see how much space we'll need */
+    p = str + slen + 1;
+    while (*p)
+    {
+        len ++;
+        p += 1 + strcspn (p, "\\\'");
+    }
 
-   /* copy and escape */
-   src_head = (char *) str;
-   dst_tail = b->escape;
-   p = src_head + strcspn (src_head, "\\\'");
-   while (*p)
-   {
-      size_t cp_len = p - src_head;
+    /* get more space, if needed */
+    if (len >= b->esc_buflen)
+    {
+        b->escape = g_realloc(b->escape, len + 100);
+        b->esc_buflen = len + 100;
+    }
 
-      strncpy (dst_tail, src_head, cp_len);
-      dst_tail += cp_len;
-      *dst_tail = '\\';
-      dst_tail ++;
-      *dst_tail = *p;
-      dst_tail ++;
+    /* copy and escape */
+    src_head = (char *) str;
+    dst_tail = b->escape;
+    p = src_head + strcspn (src_head, "\\\'");
+    while (*p)
+    {
+        size_t cp_len = p - src_head;
 
-      src_head = p+1;
-      p = src_head + strcspn (src_head, "\\\'");
-   }
-   if (p != src_head)
-   {
-      size_t cp_len = p - src_head;
+        strncpy (dst_tail, src_head, cp_len);
+        dst_tail += cp_len;
+        *dst_tail = '\\';
+        dst_tail ++;
+        *dst_tail = *p;
+        dst_tail ++;
 
-      strncpy (dst_tail, src_head, cp_len);
-      dst_tail += cp_len;
-   }
-   *dst_tail = 0;
+        src_head = p + 1;
+        p = src_head + strcspn (src_head, "\\\'");
+    }
+    if (p != src_head)
+    {
+        size_t cp_len = p - src_head;
 
-   LEAVE("b->escape = %s", b->escape);
-   return b->escape;
+        strncpy (dst_tail, src_head, cp_len);
+        dst_tail += cp_len;
+    }
+    *dst_tail = 0;
+
+    LEAVE("b->escape = %s", b->escape);
+    return b->escape;
 }
 
 /* ================================================ */
@@ -128,11 +135,11 @@
 sqlEscape *
 sqlEscape_new (void)
 {
-   sqlEscape *b = g_new (sqlEscape, 1);
+    sqlEscape *b = g_new (sqlEscape, 1);
 
-   b->escape = g_malloc (INITIAL_BUFSZ);
-   b->esc_buflen = INITIAL_BUFSZ;
-   return (b);
+    b->escape = g_malloc (INITIAL_BUFSZ);
+    b->esc_buflen = INITIAL_BUFSZ;
+    return (b);
 }
 
 /* ================================================ */
@@ -141,10 +148,15 @@
 sqlEscape_destroy (sqlEscape *b)
 {
     ENTER(" ");
-   if (!b) { LEAVE("b is (null)"); return; }
-   g_free (b->escape);     b->escape = NULL;
-   g_free (b);
-   LEAVE(" ");
+    if (!b)
+    {
+        LEAVE("b is (null)");
+        return;
+    }
+    g_free (b->escape);
+    b->escape = NULL;
+    g_free (b);
+    LEAVE(" ");
 }
 
 /* ================ END OF FILE ==================== */

Modified: gnucash/trunk/src/backend/postgres/events.c
===================================================================
--- gnucash/trunk/src/backend/postgres/events.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/events.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -22,8 +22,8 @@
 
 #include "config.h"
 
-#include <libpq-fe.h>  
-#include <stdlib.h>  
+#include <libpq-fe.h>
+#include <stdlib.h>
 
 #include "events.h"
 #include "gnc-engine.h"
@@ -45,170 +45,188 @@
 gboolean
 pgendEventsPending (QofBackend *bend)
 {
-   PGBackend *be = (PGBackend *) bend;
-   PGnotify *note;
-   int rc;
+    PGBackend *be = (PGBackend *) bend;
+    PGnotify *note;
+    int rc;
 
-   if (!be) return FALSE;
-   ENTER ("mypid=%d", be->my_pid);
+    if (!be) return FALSE;
+    ENTER ("mypid=%d", be->my_pid);
 
-   /* No need to handle events in single-modes */
-   if ((MODE_SINGLE_UPDATE == be->session_mode) ||
-       (MODE_SINGLE_FILE == be->session_mode))
-   {
-      return FALSE;
-   }
+    /* No need to handle events in single-modes */
+    if ((MODE_SINGLE_UPDATE == be->session_mode) ||
+            (MODE_SINGLE_FILE == be->session_mode))
+    {
+        return FALSE;
+    }
 
-   /* consolidate multiple event notifications */
-   rc = PQconsumeInput (be->connection);
-   if (1 != rc) 
-   {
-      PERR ("consume input failed: %s", PQerrorMessage(be->connection));
-   }
+    /* consolidate multiple event notifications */
+    rc = PQconsumeInput (be->connection);
+    if (1 != rc)
+    {
+        PERR ("consume input failed: %s", PQerrorMessage(be->connection));
+    }
 
-   note = PQnotifies (be->connection);
-   while (note)
-   {
-      /* ignore notifies from myself */
-      if (note->be_pid == be->my_pid)
-      {
-         PINFO ("this event from myself: %s from pid=%d", note->relname, note->be_pid);
-         free (note);
-         note = PQnotifies (be->connection);
-         continue;
-      }
+    note = PQnotifies (be->connection);
+    while (note)
+    {
+        /* ignore notifies from myself */
+        if (note->be_pid == be->my_pid)
+        {
+            PINFO ("this event from myself: %s from pid=%d", note->relname, note->be_pid);
+            free (note);
+            note = PQnotifies (be->connection);
+            continue;
+        }
 
-      PINFO ("notify event %s from pid=%d", note->relname, note->be_pid);
+        PINFO ("notify event %s from pid=%d", note->relname, note->be_pid);
 
-      if (0 == strcasecmp ("gncTransaction", note->relname))
-      {
-         be->do_transaction ++;
-      } 
-      else
-      if (0 == strcasecmp ("gncCheckpoint", note->relname))
-      {
-         be->do_checkpoint ++;
-      } 
-      else
-      if (0 == strcasecmp ("gncPrice", note->relname))
-      {
-         be->do_price ++;
-      } 
-      else
-      if (0 == strcasecmp ("gncAccount", note->relname))
-      {
-         be->do_account ++;
-      } 
-      else
-      if (0 == strcasecmp ("gncBook", note->relname))
-      {
-         be->do_book ++;
-      } 
-      else
-      if (0 == strcasecmp ("gncSession", note->relname))
-      {
-         be->do_session ++;
-      } 
-      else
-      {
-         PERR ("unexpected notify %s", note->relname);
-      }
+        if (0 == strcasecmp ("gncTransaction", note->relname))
+        {
+            be->do_transaction ++;
+        }
+        else if (0 == strcasecmp ("gncCheckpoint", note->relname))
+        {
+            be->do_checkpoint ++;
+        }
+        else if (0 == strcasecmp ("gncPrice", note->relname))
+        {
+            be->do_price ++;
+        }
+        else if (0 == strcasecmp ("gncAccount", note->relname))
+        {
+            be->do_account ++;
+        }
+        else if (0 == strcasecmp ("gncBook", note->relname))
+        {
+            be->do_book ++;
+        }
+        else if (0 == strcasecmp ("gncSession", note->relname))
+        {
+            be->do_session ++;
+        }
+        else
+        {
+            PERR ("unexpected notify %s", note->relname);
+        }
 
-      /* get the next one */
-      free (note);
-      note = PQnotifies (be->connection);
-   } 
+        /* get the next one */
+        free (note);
+        note = PQnotifies (be->connection);
+    }
 
-   /* for now, we ignore session and checkpoint events */
-   if (be->do_transaction + be->do_price + be->do_account) return TRUE;
-   return FALSE;
+    /* for now, we ignore session and checkpoint events */
+    if (be->do_transaction + be->do_price + be->do_account) return TRUE;
+    return FALSE;
 }
 
 /* ============================================================= */
 
-typedef struct _event {
-   Timespec stamp;
-   QofEventId type;
-   GUID guid;
-   QofIdType obj_type;
-} Event; 
+typedef struct _event
+{
+    Timespec stamp;
+    QofEventId type;
+    GUID guid;
+    QofIdType obj_type;
+} Event;
 
 
 static gpointer
 get_event_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   GList *node, *list = (GList *) data;
-   char *guid_str;
-   Event *ev = NULL;
-   GUID guid;
-   Timespec ts;
-   QofEventId type;
-   char change = (DB_GET_VAL("change",j))[0];
-   char objtype = (DB_GET_VAL("objtype",j))[0];
-   QofIdType obj_type = GNC_ID_NONE;
+    GList *node, *list = (GList *) data;
+    char *guid_str;
+    Event *ev = NULL;
+    GUID guid;
+    Timespec ts;
+    QofEventId type;
+    char change = (DB_GET_VAL("change", j))[0];
+    char objtype = (DB_GET_VAL("objtype", j))[0];
+    QofIdType obj_type = GNC_ID_NONE;
 
-   guid_str = DB_GET_VAL("guid",j);
-   PINFO ("event %c for %s", change, guid_str);
+    guid_str = DB_GET_VAL("guid", j);
+    PINFO ("event %c for %s", change, guid_str);
 
-   /* convert from SQL type to engine type */
-   switch (change)
-   {
-      case 'a': type = QOF_EVENT_CREATE; break;
-      case 'm': type = QOF_EVENT_MODIFY; break;
-      case 'd': type = QOF_EVENT_DESTROY; break;
-      default:
-         PERR ("unknown change type %c for guid=%s", change, guid_str);
-         return data;
-   }
-   switch (objtype)
-   {
-      case 'a': obj_type = GNC_ID_ACCOUNT; break;
-      case 'b': obj_type = GNC_ID_BOOK; break;
-      case 'c': obj_type = GNC_ID_NONE; break;  /* should be commodity */
-      case 'e': obj_type = GNC_ID_SPLIT; break;
-      case 'p': obj_type = GNC_ID_PRICE; break;
-      case 't': obj_type = GNC_ID_TRANS; break;
-      case 'x': obj_type = GNC_ID_NONE; break;
-      case ' ': obj_type = GNC_ID_NONE; break;
-      case 'k': /* we are not expecting kvp's in here */
-      default:
-         PERR ("unexpected class type %c for guid=%s", objtype, guid_str);
-         return data;
-   }
+    /* convert from SQL type to engine type */
+    switch (change)
+    {
+    case 'a':
+        type = QOF_EVENT_CREATE;
+        break;
+    case 'm':
+        type = QOF_EVENT_MODIFY;
+        break;
+    case 'd':
+        type = QOF_EVENT_DESTROY;
+        break;
+    default:
+        PERR ("unknown change type %c for guid=%s", change, guid_str);
+        return data;
+    }
+    switch (objtype)
+    {
+    case 'a':
+        obj_type = GNC_ID_ACCOUNT;
+        break;
+    case 'b':
+        obj_type = GNC_ID_BOOK;
+        break;
+    case 'c':
+        obj_type = GNC_ID_NONE;
+        break;  /* should be commodity */
+    case 'e':
+        obj_type = GNC_ID_SPLIT;
+        break;
+    case 'p':
+        obj_type = GNC_ID_PRICE;
+        break;
+    case 't':
+        obj_type = GNC_ID_TRANS;
+        break;
+    case 'x':
+        obj_type = GNC_ID_NONE;
+        break;
+    case ' ':
+        obj_type = GNC_ID_NONE;
+        break;
+    case 'k': /* we are not expecting kvp's in here */
+    default:
+        PERR ("unexpected class type %c for guid=%s", objtype, guid_str);
+        return data;
+    }
 
-   string_to_guid (guid_str, &guid);
-   ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_changed",j));
+    string_to_guid (guid_str, &guid);
+    ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_changed", j));
 
-   /* Compress multiple events for the same object.  In other
-    * words, keep only the last event for this object.
-    */
-   for (node=list; node; node=node->next)
-   {
-      ev = (Event *) node->data;
-      if (guid_equal (&(ev->guid), &guid)) 
-      {
-         if (0 >= timespec_cmp (&(ev->stamp), &ts)) 
-         {
-            ev->type = type;
-            ev->guid = guid;
-            ev->stamp = ts;
-            ev->obj_type = obj_type;
-         }
-         return (gpointer) list;
-      }
-   }
+    /* Compress multiple events for the same object.  In other
+     * words, keep only the last event for this object.
+     */
+    for (node = list; node; node = node->next)
+    {
+        ev = (Event *) node->data;
+        if (guid_equal (&(ev->guid), &guid))
+        {
+            if (0 >= timespec_cmp (&(ev->stamp), &ts))
+            {
+                ev->type = type;
+                ev->guid = guid;
+                ev->stamp = ts;
+                ev->obj_type = obj_type;
+            }
+            return (gpointer) list;
+        }
+    }
 
-   ev = g_new (Event, 1);
+    ev = g_new (Event, 1);
 
-   ev->type = type;
-   ev->guid = guid;
-   ev->stamp = ts;
-   ev->obj_type = obj_type;
+    ev->type = type;
+    ev->guid = guid;
+    ev->stamp = ts;
+    ev->obj_type = obj_type;
 
-   /* add it to our list */
-   list = g_list_prepend (list, ev);
+    /* add it to our list */
+    list = g_list_prepend (list, ev);
 
-   return (gpointer) list;
+    return (gpointer) list;
 }
 
 #define GET_EVENTS(guid_name,table, timestamp)	                    \
@@ -230,204 +248,208 @@
 gboolean
 pgendProcessEvents (QofBackend *bend)
 {
-   PGBackend *be = (PGBackend *) bend;
-   GList *node, *pending = NULL;
+    PGBackend *be = (PGBackend *) bend;
+    GList *node, *pending = NULL;
 
-   if (!be) return FALSE;
+    if (!be) return FALSE;
 
-   ENTER (" ");
+    ENTER (" ");
 
-   /* Get all recent events from the SQL db. */
-   if (be->do_account)
-   {
-      GET_EVENTS (accountGuid, gncAccountTrail, be->last_account);
-   }
-   if (be->do_price)
-   {
-      GET_EVENTS (priceGuid, gncPriceTrail, be->last_price);
-   }
-   if (be->do_transaction)
-   {
-      GET_EVENTS (transGuid, gncTransactionTrail, be->last_transaction);
+    /* Get all recent events from the SQL db. */
+    if (be->do_account)
+    {
+        GET_EVENTS (accountGuid, gncAccountTrail, be->last_account);
+    }
+    if (be->do_price)
+    {
+        GET_EVENTS (priceGuid, gncPriceTrail, be->last_price);
+    }
+    if (be->do_transaction)
+    {
+        GET_EVENTS (transGuid, gncTransactionTrail, be->last_transaction);
 
-      /* gnc_cm_event_handler() doesn't really want to see any split guids */
-      // GET_EVENTS (splitGuid, gncSplitTrail, be->last_transaction);
-   }
+        /* gnc_cm_event_handler() doesn't really want to see any split guids */
+        // GET_EVENTS (splitGuid, gncSplitTrail, be->last_transaction);
+    }
 
-   /* Loop over each item, updating the engine, and dispatching events */
-   for (node = pending; node; node = node->next)
-   {
-      Event *ev = (Event *) node->data;
-      QofIdType local_obj_type;
-      QofInstance *ent;
+    /* Loop over each item, updating the engine, and dispatching events */
+    for (node = pending; node; node = node->next)
+    {
+        Event *ev = (Event *) node->data;
+        QofIdType local_obj_type;
+        QofInstance *ent;
 
-      ent = NULL;
-      /* lets see if the local cache has this item in it */
-      local_obj_type = pgendGUIDType (be, &(ev->guid));
-      if ((local_obj_type != GNC_ID_NONE) && 
-          (safe_strcmp (local_obj_type, ev->obj_type)))
-      {
-         PERR ("ouch! object type mismatch, local=%s, event=%s",
-               local_obj_type, ev->obj_type);
-         g_free (ev);
-         continue;
-      }
+        ent = NULL;
+        /* lets see if the local cache has this item in it */
+        local_obj_type = pgendGUIDType (be, &(ev->guid));
+        if ((local_obj_type != GNC_ID_NONE) &&
+                (safe_strcmp (local_obj_type, ev->obj_type)))
+        {
+            PERR ("ouch! object type mismatch, local=%s, event=%s",
+                  local_obj_type, ev->obj_type);
+            g_free (ev);
+            continue;
+        }
 
-      if (!safe_strcmp (ev->obj_type, GNC_ID_ACCOUNT))
-      {
-         if (0 < timespec_cmp(&(ev->stamp), &(be->last_account))) 
-         {
-            be->last_account = ev->stamp;
-         }
-         switch (ev->type)
-         {
+        if (!safe_strcmp (ev->obj_type, GNC_ID_ACCOUNT))
+        {
+            if (0 < timespec_cmp(&(ev->stamp), &(be->last_account)))
+            {
+                be->last_account = ev->stamp;
+            }
+            switch (ev->type)
+            {
             default:
-               PERR ("account: cant' happen !!!!!!!");
-               break;
+                PERR ("account: cant' happen !!!!!!!");
+                break;
             case QOF_EVENT_CREATE:
-            case QOF_EVENT_MODIFY: {
-               Account *acc;
+            case QOF_EVENT_MODIFY:
+            {
+                Account *acc;
 
-               /* if the remote user created an account, mirror it here */
-               acc = pgendCopyAccountToEngine (be, &(ev->guid));
-               ent = QOF_INSTANCE(acc);
-               break;
+                /* if the remote user created an account, mirror it here */
+                acc = pgendCopyAccountToEngine (be, &(ev->guid));
+                ent = QOF_INSTANCE(acc);
+                break;
             }
-            case QOF_EVENT_DESTROY: {
-               Account * acc = pgendAccountLookup (be, &(ev->guid));
-               xaccAccountBeginEdit (acc);
-               xaccAccountDestroy (acc);
-               ent = QOF_INSTANCE(acc);
-               break;
+            case QOF_EVENT_DESTROY:
+            {
+                Account * acc = pgendAccountLookup (be, &(ev->guid));
+                xaccAccountBeginEdit (acc);
+                xaccAccountDestroy (acc);
+                ent = QOF_INSTANCE(acc);
+                break;
             }
-         }
-      }
-      else 
-      if (!safe_strcmp (ev->obj_type, GNC_ID_TRANS))
-      {
-         if (0 < timespec_cmp(&(ev->stamp), &(be->last_transaction))) 
-          {
-            be->last_transaction = ev->stamp;
-         }
-         switch (ev->type)
-         {
+            }
+        }
+        else if (!safe_strcmp (ev->obj_type, GNC_ID_TRANS))
+        {
+            if (0 < timespec_cmp(&(ev->stamp), &(be->last_transaction)))
+            {
+                be->last_transaction = ev->stamp;
+            }
+            switch (ev->type)
+            {
             default:
-               PERR ("transaction: cant' happen !!!!!!!");
-               break;
-            case QOF_EVENT_CREATE: {
-               Transaction *trans;
-               /* don't mirror transaction creations. If a register needs
-                * it, it will do a query. */
-               trans = pgendTransLookup (be, &(ev->guid));
-               ent = QOF_INSTANCE(trans);
-               PINFO ("create transaction");
-               break;
-			}
-            case QOF_EVENT_MODIFY: {
-               Transaction *trans;
-               trans = pgendTransLookup (be, &(ev->guid));
-               pgendCopyTransactionToEngine (be, &(ev->guid));
-               ent = QOF_INSTANCE(trans);
-               break;
-			}
-            case QOF_EVENT_DESTROY: {
-               Transaction *trans = pgendTransLookup (be, &(ev->guid));
-               xaccTransBeginEdit (trans);
-               /* mark trans for freeing */
-               xaccTransDestroy (trans);
-               xaccTransCommitEdit (trans);
-               ent = QOF_INSTANCE(trans);
-               break;
+                PERR ("transaction: cant' happen !!!!!!!");
+                break;
+            case QOF_EVENT_CREATE:
+            {
+                Transaction *trans;
+                /* don't mirror transaction creations. If a register needs
+                 * it, it will do a query. */
+                trans = pgendTransLookup (be, &(ev->guid));
+                ent = QOF_INSTANCE(trans);
+                PINFO ("create transaction");
+                break;
             }
-         }
-      }
-      else 
-      if (!safe_strcmp (ev->obj_type, GNC_ID_SPLIT))
-      {
-         if (0 < timespec_cmp(&(ev->stamp), &(be->last_transaction)))
-         {
-            be->last_transaction = ev->stamp;
-         }
-      }
-      else 
-      if (!safe_strcmp (ev->obj_type, GNC_ID_PRICE))
-      {
-         if (0 < timespec_cmp(&(ev->stamp), &(be->last_price)))
-         {
-            be->last_price = ev->stamp;
-         }
-      }
-      else
-      {
-         PERR ("unknown guid type %s", ev->obj_type);
-      }
-   
-      /* test the local type again, since we created/modified/destroyed
-       * the guid above */
-      if (GNC_ID_NONE == local_obj_type)
-      {
-         local_obj_type = pgendGUIDType (be, &(ev->guid));
-         if (GNC_ID_NONE != local_obj_type)
-         {
-	       qof_event_gen(ent, QOF_EVENT_CREATE, NULL);
-         }
-      }
-      else 
-      {
-         local_obj_type = pgendGUIDType (be, &(ev->guid));
-         if (GNC_ID_NONE != local_obj_type)
-         {
-	       qof_event_gen(ent, QOF_EVENT_MODIFY, NULL);
-         }
-         else
-         {
-	       qof_event_gen(ent, QOF_EVENT_DESTROY, NULL);
-         }
-      }
-   
-      g_free (ev);
-   }
-   g_list_free (pending);
+            case QOF_EVENT_MODIFY:
+            {
+                Transaction *trans;
+                trans = pgendTransLookup (be, &(ev->guid));
+                pgendCopyTransactionToEngine (be, &(ev->guid));
+                ent = QOF_INSTANCE(trans);
+                break;
+            }
+            case QOF_EVENT_DESTROY:
+            {
+                Transaction *trans = pgendTransLookup (be, &(ev->guid));
+                xaccTransBeginEdit (trans);
+                /* mark trans for freeing */
+                xaccTransDestroy (trans);
+                xaccTransCommitEdit (trans);
+                ent = QOF_INSTANCE(trans);
+                break;
+            }
+            }
+        }
+        else if (!safe_strcmp (ev->obj_type, GNC_ID_SPLIT))
+        {
+            if (0 < timespec_cmp(&(ev->stamp), &(be->last_transaction)))
+            {
+                be->last_transaction = ev->stamp;
+            }
+        }
+        else if (!safe_strcmp (ev->obj_type, GNC_ID_PRICE))
+        {
+            if (0 < timespec_cmp(&(ev->stamp), &(be->last_price)))
+            {
+                be->last_price = ev->stamp;
+            }
+        }
+        else
+        {
+            PERR ("unknown guid type %s", ev->obj_type);
+        }
 
-   be->do_account = 0;
-   be->do_checkpoint = 0;
-   be->do_price = 0;
-   be->do_session = 0;
-   be->do_transaction = 0;
-   return FALSE;
+        /* test the local type again, since we created/modified/destroyed
+         * the guid above */
+        if (GNC_ID_NONE == local_obj_type)
+        {
+            local_obj_type = pgendGUIDType (be, &(ev->guid));
+            if (GNC_ID_NONE != local_obj_type)
+            {
+                qof_event_gen(ent, QOF_EVENT_CREATE, NULL);
+            }
+        }
+        else
+        {
+            local_obj_type = pgendGUIDType (be, &(ev->guid));
+            if (GNC_ID_NONE != local_obj_type)
+            {
+                qof_event_gen(ent, QOF_EVENT_MODIFY, NULL);
+            }
+            else
+            {
+                qof_event_gen(ent, QOF_EVENT_DESTROY, NULL);
+            }
+        }
+
+        g_free (ev);
+    }
+    g_list_free (pending);
+
+    be->do_account = 0;
+    be->do_checkpoint = 0;
+    be->do_price = 0;
+    be->do_session = 0;
+    be->do_transaction = 0;
+    return FALSE;
 }
 
 
 /* ============================================================= */
 /* find the backend pid */
 
-void 
+void
 pgendSessionGetPid (PGBackend *be)
 {
-   PGnotify *note;
-   char *p;
-   long int r;
+    PGnotify *note;
+    char *p;
+    long int r;
 
-   r = random ();
-   
-   p = be->buff; *p=0;
-   sprintf (p, "LISTEN \"%ld\";\n NOTIFY \"%ld\";", r, r);
-   SEND_QUERY (be, be->buff, );
-   FINISH_QUERY(be->connection);
-   note = PQnotifies (be->connection);
-   if (!note)
-   {
-      PERR ("didn't receive notification");
-      return;
-   }
+    r = random ();
 
-   be->my_pid = note->be_pid;
-   PINFO ("postgres backend pid =%d", be->my_pid);
+    p = be->buff;
+    *p = 0;
+    sprintf (p, "LISTEN \"%ld\";\n NOTIFY \"%ld\";", r, r);
+    SEND_QUERY (be, be->buff, );
+    FINISH_QUERY(be->connection);
+    note = PQnotifies (be->connection);
+    if (!note)
+    {
+        PERR ("didn't receive notification");
+        return;
+    }
 
-   p = be->buff; *p=0;
-   sprintf (p, "UNLISTEN \"%ld\";", r);
-   SEND_QUERY (be, be->buff, );
-   FINISH_QUERY(be->connection);
+    be->my_pid = note->be_pid;
+    PINFO ("postgres backend pid =%d", be->my_pid);
+
+    p = be->buff;
+    *p = 0;
+    sprintf (p, "UNLISTEN \"%ld\";", r);
+    SEND_QUERY (be, be->buff, );
+    FINISH_QUERY(be->connection);
 }
 
 /* ============================================================= */
@@ -435,35 +457,35 @@
 static gpointer
 get_latest_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   Timespec latest;
+    Timespec latest;
 
-   /* get event timestamp */
-   latest = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_changed",j));
-   latest.tv_sec ++;  /* ignore old, pre-logon events */
+    /* get event timestamp */
+    latest = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_changed", j));
+    latest.tv_sec ++;  /* ignore old, pre-logon events */
 
-   be->last_account = latest;
-   be->last_price = latest;
-   be->last_transaction = latest;
+    be->last_account = latest;
+    be->last_price = latest;
+    be->last_transaction = latest;
 
-   return data;
+    return data;
 }
 
-void 
+void
 pgendSessionSetupNotifies (PGBackend *be)
 {
-   char *p;
+    char *p;
 
-   /* Get latest times from the database; this to avoid clock 
-    * skew between database and this local process */
-   p = "SELECT date_changed FROM gncAuditTrail* ORDER BY date_changed DESC LIMIT 1;";
-   SEND_QUERY (be, p, );
-   pgendGetResults (be, get_latest_cb, NULL);
+    /* Get latest times from the database; this to avoid clock
+     * skew between database and this local process */
+    p = "SELECT date_changed FROM gncAuditTrail* ORDER BY date_changed DESC LIMIT 1;";
+    SEND_QUERY (be, p, );
+    pgendGetResults (be, get_latest_cb, NULL);
 
-   p = "LISTEN gncSession;\nLISTEN gncAccount;\n"
-       "LISTEN gncPrice;\nLISTEN gncTransaction;\n"
-       "LISTEN gncCheckpoint;\nLISTEN gncBook;\n";
-   SEND_QUERY (be, p, );
-   FINISH_QUERY(be->connection);
+    p = "LISTEN gncSession;\nLISTEN gncAccount;\n"
+        "LISTEN gncPrice;\nLISTEN gncTransaction;\n"
+        "LISTEN gncCheckpoint;\nLISTEN gncBook;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 }
 
 /* ======================== END OF FILE ======================== */

Modified: gnucash/trunk/src/backend/postgres/events.h
===================================================================
--- gnucash/trunk/src/backend/postgres/events.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/events.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -19,7 +19,7 @@
  * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
 \********************************************************************/
 
-/* 
+/*
  * FILE:
  * events.h
  *

Modified: gnucash/trunk/src/backend/postgres/gncquery.c
===================================================================
--- gnucash/trunk/src/backend/postgres/gncquery.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/gncquery.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -26,9 +26,9 @@
  *
  * FUNCTION:
  * Convert gnucash engine Query (a la Query.h) into an SQL Query
- * 
- * The gnc engine query consists of doubly nested list of 
- * query terms.  The inner list consists of terms that need to be 
+ *
+ * The gnc engine query consists of doubly nested list of
+ * query terms.  The inner list consists of terms that need to be
  * AND'ed together; the outer list OR's together the inner lists.
  *
  * HISTORY:
@@ -43,7 +43,7 @@
 #include "Account.h"
 #include "Transaction.h"
 #include "gnc-engine.h"
-/** \todo Code dependent on the private query headers 
+/** \todo Code dependent on the private query headers
 qofquery-p.h and qofquerycore-p.h may need to be modified.
 These files are temporarily exported for QOF 0.6.0 but
 cannot be considered "standard" or public parts of QOF. */
@@ -57,7 +57,8 @@
 static QofLogModule log_module = GNC_MOD_BACKEND;
 
 
-struct _gnc_query {
+struct _gnc_query
+{
     char *q_base;
     char *pq;
     size_t buflen;
@@ -86,7 +87,8 @@
 sql_Query_destroy(sqlQuery * sq)
 {
     ENTER(" ");
-    if (!sq) {
+    if (!sq)
+    {
         LEAVE("sq = (null)");
         return;
     }
@@ -103,58 +105,89 @@
 static char *
 sql_sort_get_type(char *p, GSList * path)
 {
-    if (!safe_strcmp(path->data, SPLIT_TRANS)) {
+    if (!safe_strcmp(path->data, SPLIT_TRANS))
+    {
         path = path->next;
         if (!path)
             PERR("AIEE -- sorting on the Transaction???");
 
-        if (!safe_strcmp(path->data, TRANS_DATE_POSTED)) {
+        if (!safe_strcmp(path->data, TRANS_DATE_POSTED))
+        {
             p = stpcpy(p, "gncTransaction.date_posted");
-        } else if (!safe_strcmp(path->data, TRANS_DATE_ENTERED)) {
+        }
+        else if (!safe_strcmp(path->data, TRANS_DATE_ENTERED))
+        {
             p = stpcpy(p, "gncTransaction.date_entered");
-        } else if (!safe_strcmp(path->data, TRANS_NUM)) {
+        }
+        else if (!safe_strcmp(path->data, TRANS_NUM))
+        {
             p = stpcpy(p, "gncTransaction.num");
-        } else if (!safe_strcmp(path->data, TRANS_DESCRIPTION)) {
+        }
+        else if (!safe_strcmp(path->data, TRANS_DESCRIPTION))
+        {
             p = stpcpy(p, "gncTransaction.description");
-        } else {
+        }
+        else
+        {
             PERR("Unknown Transaction parameter: %s", (char *)(path->data));
         }
 
-    } else if (!safe_strcmp(path->data, SPLIT_ACCOUNT)) {
+    }
+    else if (!safe_strcmp(path->data, SPLIT_ACCOUNT))
+    {
         path = path->next;
         if (!path)
             PERR("AIEE -- sorting on the Account??");
 
-        if (!safe_strcmp(path->data, ACCOUNT_CODE_)) {
+        if (!safe_strcmp(path->data, ACCOUNT_CODE_))
+        {
             /* XXX hack alert FIXME implement this */
             PERR("BY_ACCOUNT_CODE badly implemented");
             p = stpcpy(p, "gncAccount.accountCode");
-        } else {
+        }
+        else
+        {
             PERR("Unknown Account parameter: %s", (char *)(path->data));
         }
 
-    } else if (!safe_strcmp(path->data, SPLIT_DATE_RECONCILED)) {
+    }
+    else if (!safe_strcmp(path->data, SPLIT_DATE_RECONCILED))
+    {
         p = stpcpy(p, "gncSplit.date_reconciled");
-    } else if (!safe_strcmp(path->data, SPLIT_MEMO)) {
+    }
+    else if (!safe_strcmp(path->data, SPLIT_MEMO))
+    {
         p = stpcpy(p, "gncSplit.memo");
-    } else if (!safe_strcmp(path->data, SPLIT_RECONCILE)) {
+    }
+    else if (!safe_strcmp(path->data, SPLIT_RECONCILE))
+    {
         p = stpcpy(p, "gncSplit.reconciled");
-    } else if (!safe_strcmp(path->data, SPLIT_VALUE)) {
+    }
+    else if (!safe_strcmp(path->data, SPLIT_VALUE))
+    {
         p = stpcpy(p, "gncSplit.amount");
-    } else if (!safe_strcmp(path->data, SPLIT_ACCT_FULLNAME)) {
+    }
+    else if (!safe_strcmp(path->data, SPLIT_ACCT_FULLNAME))
+    {
         /* XXX hack alert FIXME implement this */
         PERR("BY_ACCOUNT_FULL_NAME badly implemented");
         p = stpcpy(p, "gncAccount.accountName");
-    } else if (!safe_strcmp(path->data, SPLIT_CORR_ACCT_NAME)) {
+    }
+    else if (!safe_strcmp(path->data, SPLIT_CORR_ACCT_NAME))
+    {
         /* XXX hack alert FIXME implement this */
         PERR("BY_CORR_ACCOUNT_FULL_NAME not implemented");
         p = stpcpy(p, "gncAccount.accountName");
-    } else if (!safe_strcmp(path->data, SPLIT_CORR_ACCT_CODE)) {
+    }
+    else if (!safe_strcmp(path->data, SPLIT_CORR_ACCT_CODE))
+    {
         /* XXX hack alert FIXME implement this */
         PERR("BY_CORR_ACCOUNT_CODE not implemented");
         p = stpcpy(p, "gncAccount.accountCode");
 
-    } else {
+    }
+    else
+    {
         PERR("Unknown Split parameter: %s", (char *)(path->data));
     }
 
@@ -180,17 +213,23 @@
 
     path = qof_query_sort_get_param_path(sort);
 
-    if (path == NULL) {
+    if (path == NULL)
+    {
         /* Ok, we're not sorting on anything here. */
         ;
-    } else if (!safe_strcmp(path->data, QUERY_DEFAULT_SORT)) {
-        if (TRUE == increasing) {
+    }
+    else if (!safe_strcmp(path->data, QUERY_DEFAULT_SORT))
+    {
+        if (TRUE == increasing)
+        {
             p = stpcpy(p,
                        "gncTransaction.date_posted DESC, "
                        "gncTransaction.num DESC, "
                        "gncTransaction.date_entered DESC, "
                        "gncTransaction.description");
-        } else {
+        }
+        else
+        {
             p = stpcpy(p,
                        "gncTransaction.date_posted ASC, "
                        "gncTransaction.num ASC, "
@@ -198,13 +237,18 @@
                        "gncTransaction.description");
         }
 
-    } else {
+    }
+    else
+    {
         p = sql_sort_get_type(p, path);
     }
 
-    if (TRUE == increasing) {
+    if (TRUE == increasing)
+    {
         p = stpcpy(p, " DESC ");
-    } else {
+    }
+    else
+    {
         p = stpcpy(p, " ASC ");
     }
 
@@ -222,17 +266,23 @@
 
     path = qof_query_sort_get_param_path(sort);
 
-    if (NULL != path) {
+    if (NULL != path)
+    {
         p = stpcpy(p, ", ");
     }
 
-    if (path == NULL) {
+    if (path == NULL)
+    {
         ;
 
-    } else if (!safe_strcmp(path->data, QUERY_DEFAULT_SORT)) {
+    }
+    else if (!safe_strcmp(path->data, QUERY_DEFAULT_SORT))
+    {
         p = stpcpy(p, "gncTransaction.date_posted, gncTransaction.num, "
                    "gncTransaction.date_entered, gncTransaction.description");
-    } else {
+    }
+    else
+    {
         p = sql_sort_get_type(p, path);
     }
 
@@ -254,9 +304,9 @@
 
     if (path)
         if (!safe_strcmp(path->data, SPLIT_ACCT_FULLNAME) ||
-            !safe_strcmp(path->data, SPLIT_CORR_ACCT_NAME) ||
-            !safe_strcmp(path->data, SPLIT_CORR_ACCT_CODE) ||
-            !safe_strcmp(path->data, SPLIT_ACCOUNT))
+                !safe_strcmp(path->data, SPLIT_CORR_ACCT_NAME) ||
+                !safe_strcmp(path->data, SPLIT_CORR_ACCT_CODE) ||
+                !safe_strcmp(path->data, SPLIT_ACCOUNT))
             need_account = TRUE;
 
     return need_account;
@@ -271,7 +321,7 @@
     qof_query_get_sorts(q, &s1, &s2, &s3);
 
     need_account = sql_sort_sort_need_account(s1) ||
-        sql_sort_sort_need_account(s2) || sql_sort_sort_need_account(s3);
+                   sql_sort_sort_need_account(s2) || sql_sort_sort_need_account(s3);
 
     return need_account;
 }
@@ -290,9 +340,9 @@
 
     if (path)
         if (!safe_strcmp(path->data, SPLIT_VALUE) ||
-            !safe_strcmp(path->data, SPLIT_DATE_RECONCILED) ||
-            !safe_strcmp(path->data, SPLIT_MEMO) ||
-            !safe_strcmp(path->data, SPLIT_RECONCILE))
+                !safe_strcmp(path->data, SPLIT_DATE_RECONCILED) ||
+                !safe_strcmp(path->data, SPLIT_MEMO) ||
+                !safe_strcmp(path->data, SPLIT_RECONCILE))
             need_entry = TRUE;
 
     return need_entry;
@@ -307,16 +357,16 @@
     qof_query_get_sorts(q, &s1, &s2, &s3);
 
     need_entry = sql_sort_sort_need_entry(s1) ||
-        sql_sort_sort_need_entry(s2) || sql_sort_sort_need_entry(s3);
+                 sql_sort_sort_need_entry(s2) || sql_sort_sort_need_entry(s3);
 
     return need_entry;
 }
 
 /* =========================================================== */
 /* Macro for QOF_TYPE_STRING query types
- * Note that postgres supports both case-sensitive and 
- * case-insensitve string searches, and it also supports 
- * regex!  yahooo! 
+ * Note that postgres supports both case-sensitive and
+ * case-insensitve string searches, and it also supports
+ * regex!  yahooo!
  */
 
 #define STRING_TERM(fieldname)                                \
@@ -347,8 +397,8 @@
 /* =========================================================== */
 /* Macro for QOF_TYPE_NUMERIC type terms.  The logic used here in the
  * SQL exactly matches that used in the qofquery.c code.  If
- * that code is incorrect or has changed, then the code below is 
- * broken as well. 
+ * that code is incorrect or has changed, then the code below is
+ * broken as well.
  */
 
 #define AMOUNT_TERM(signcheck,fieldname,comtable)                    \
@@ -427,28 +477,29 @@
 static const char *
 kvp_table_name(KvpValueType value_t)
 {
-    switch (value_t) {
-        case KVP_TYPE_GINT64:
-            return "gnckvpvalue_int64";
+    switch (value_t)
+    {
+    case KVP_TYPE_GINT64:
+        return "gnckvpvalue_int64";
 
-        case KVP_TYPE_DOUBLE:
-            return "gnckvpvalue_dbl";
+    case KVP_TYPE_DOUBLE:
+        return "gnckvpvalue_dbl";
 
-        case KVP_TYPE_NUMERIC:
-            return "gnckvpvalue_numeric";
+    case KVP_TYPE_NUMERIC:
+        return "gnckvpvalue_numeric";
 
-        case KVP_TYPE_STRING:
-            return "gnckvpvalue_str";
+    case KVP_TYPE_STRING:
+        return "gnckvpvalue_str";
 
-        case KVP_TYPE_GUID:
-            return "gnckvpvalue_guid";
+    case KVP_TYPE_GUID:
+        return "gnckvpvalue_guid";
 
-        case KVP_TYPE_TIMESPEC:
-            return "gnckvpvalue_timespec";
+    case KVP_TYPE_TIMESPEC:
+        return "gnckvpvalue_timespec";
 
-        default:
-            PWARN("kvp value not supported");
-            return NULL;
+    default:
+        PWARN("kvp value not supported");
+        return NULL;
     }
 }
 
@@ -458,7 +509,8 @@
     GString *s = g_string_new(NULL);
     char *name;
 
-    for (; path; path = path->next) {
+    for (; path; path = path->next)
+    {
         g_string_append_c(s, '/');
         g_string_append(s, path->data);
     }
@@ -472,27 +524,28 @@
 static const char *
 compare_op_name(QofQueryCompare how)
 {
-    switch (how) {
-        case QOF_COMPARE_LT:
-            return " < ";
+    switch (how)
+    {
+    case QOF_COMPARE_LT:
+        return " < ";
 
-        case QOF_COMPARE_LTE:
-            return " <= ";
+    case QOF_COMPARE_LTE:
+        return " <= ";
 
-        case QOF_COMPARE_EQUAL:
-            return " = ";
+    case QOF_COMPARE_EQUAL:
+        return " = ";
 
-        case QOF_COMPARE_GTE:
-            return " >= ";
+    case QOF_COMPARE_GTE:
+        return " >= ";
 
-        case QOF_COMPARE_GT:
-            return " > ";
+    case QOF_COMPARE_GT:
+        return " > ";
 
-        case QOF_COMPARE_NEQ:
-            return " != ";
+    case QOF_COMPARE_NEQ:
+        return " != ";
 
-        default:
-            return NULL;
+    default:
+        return NULL;
     }
 }
 
@@ -508,22 +561,24 @@
 
     kvptable = kvp_table_name(value_t);
 
-    switch (value_t) {
-        case KVP_TYPE_GINT64:
-        case KVP_TYPE_DOUBLE:
-        case KVP_TYPE_GUID:
-        case KVP_TYPE_TIMESPEC:
-        case KVP_TYPE_STRING:
-            return g_strdup_printf("%s.data", kvptable);
+    switch (value_t)
+    {
+    case KVP_TYPE_GINT64:
+    case KVP_TYPE_DOUBLE:
+    case KVP_TYPE_GUID:
+    case KVP_TYPE_TIMESPEC:
+    case KVP_TYPE_STRING:
+        return g_strdup_printf("%s.data", kvptable);
 
-        case KVP_TYPE_NUMERIC:{
-            gnc_numeric n = kvp_value_get_numeric(value);
-            return g_strdup_printf("(%" G_GINT64_FORMAT "::int8 * %s.num::int8)",
-                                   n.denom, kvptable);
-        }
+    case KVP_TYPE_NUMERIC:
+    {
+        gnc_numeric n = kvp_value_get_numeric(value);
+        return g_strdup_printf("(%" G_GINT64_FORMAT "::int8 * %s.num::int8)",
+                               n.denom, kvptable);
+    }
 
-        default:
-            return NULL;
+    default:
+        return NULL;
     }
 }
 
@@ -539,41 +594,46 @@
 
     kvptable = kvp_table_name(value_t);
 
-    switch (value_t) {
-        case KVP_TYPE_GINT64:
-            return g_strdup_printf("%" G_GINT64_FORMAT,
-                                   kvp_value_get_gint64(value));
+    switch (value_t)
+    {
+    case KVP_TYPE_GINT64:
+        return g_strdup_printf("%" G_GINT64_FORMAT,
+                               kvp_value_get_gint64(value));
 
-        case KVP_TYPE_DOUBLE:
-            return g_strdup_printf(SQL_DBL_FMT, kvp_value_get_double(value));
+    case KVP_TYPE_DOUBLE:
+        return g_strdup_printf(SQL_DBL_FMT, kvp_value_get_double(value));
 
-        case KVP_TYPE_GUID:{
-            /* THREAD-UNSAFE */
-            const char *guid = guid_to_string(kvp_value_get_guid(value));
-            char *s = g_strdup_printf("'%s'", guid);
-            return s;
-        }
+    case KVP_TYPE_GUID:
+    {
+        /* THREAD-UNSAFE */
+        const char *guid = guid_to_string(kvp_value_get_guid(value));
+        char *s = g_strdup_printf("'%s'", guid);
+        return s;
+    }
 
-        case KVP_TYPE_TIMESPEC:{
-            char s[80];
-            gnc_timespec_to_iso8601_buff(kvp_value_get_timespec(value), s);
-            return g_strdup_printf("'%s'", s);
-        }
+    case KVP_TYPE_TIMESPEC:
+    {
+        char s[80];
+        gnc_timespec_to_iso8601_buff(kvp_value_get_timespec(value), s);
+        return g_strdup_printf("'%s'", s);
+    }
 
-        case KVP_TYPE_STRING:{
-            const char *s = sqlEscapeString(sq->escape,
-                                            kvp_value_get_string(value));
-            return g_strdup_printf("'%s'", s);
-        }
+    case KVP_TYPE_STRING:
+    {
+        const char *s = sqlEscapeString(sq->escape,
+                                        kvp_value_get_string(value));
+        return g_strdup_printf("'%s'", s);
+    }
 
-        case KVP_TYPE_NUMERIC:{
-            gnc_numeric n = kvp_value_get_numeric(value);
-            return g_strdup_printf("(%" G_GINT64_FORMAT "::int8 * %s.denom::int8)",
-                                   n.num, kvptable);
-        }
+    case KVP_TYPE_NUMERIC:
+    {
+        gnc_numeric n = kvp_value_get_numeric(value);
+        return g_strdup_printf("(%" G_GINT64_FORMAT "::int8 * %s.denom::int8)",
+                               n.num, kvptable);
+    }
 
-        default:
-            return NULL;
+    default:
+        return NULL;
     }
 }
 
@@ -620,14 +680,15 @@
     g_return_if_fail(sq && kpd && kpd->path && kpd->value);
 
     if (safe_strcmp(sort_path->data, SPLIT_KVP) &&
-        ((safe_strcmp(sort_path->data, SPLIT_ACCOUNT) &&
-          safe_strcmp(sort_path->data, SPLIT_TRANS)) ||
-         safe_strcmp(sort_path->next->data, SPLIT_KVP)))
+            ((safe_strcmp(sort_path->data, SPLIT_ACCOUNT) &&
+              safe_strcmp(sort_path->data, SPLIT_TRANS)) ||
+             safe_strcmp(sort_path->next->data, SPLIT_KVP)))
         return;
 
     value_t = kvp_value_get_type(kpd->value);
 
-    if (value_t == KVP_TYPE_GUID && how != QOF_COMPARE_EQUAL) {
+    if (value_t == KVP_TYPE_GUID && how != QOF_COMPARE_EQUAL)
+    {
         PWARN("guid non-equality comparison not supported");
         return;
     }
@@ -658,7 +719,8 @@
     sq->pq = stpcpy(sq->pq, sqlEscapeString(sq->escape, path));
     sq->pq = stpcpy(sq->pq, "'");
 
-    for (node = list; node; node = node->next) {
+    for (node = list; node; node = node->next)
+    {
         sq->pq = stpcpy(sq->pq, " AND ");
         add_kvp_clause(sq, kvptable, node->data, left, op, right);
     }
@@ -679,10 +741,10 @@
  * This is what this code originally used to do.  However, during
  * performance tuning, I discovered that gratuitously listing a
  * table that is not referenced (e.g. gncAccount when the query
- * doesn't involve accounts) is not gratuitous: it can hurt 
- * performance by factors of ten(!!!).  Thus, there is a *lot* 
+ * doesn't involve accounts) is not gratuitous: it can hurt
+ * performance by factors of ten(!!!).  Thus, there is a *lot*
  * (hundreds of lines of code) of extra complexity here to make
- * sure that only the needed tables get listed, and no more. 
+ * sure that only the needed tables get listed, and no more.
  *
  * Yes, I agree that this should have been idempotent code, and
  * that a good SQL optimizer would have weeded away and discarded
@@ -697,11 +759,11 @@
  * larger than otherwise.)
  *
  * Specifically, I am refering to the 'need_account' and the
- * 'need_entry' booleans.  These serve no functional purpose:  
- * You'd get exactly the same results if you just set these to 
- * TRUE.  But they affect performance tremendously, and there 
- * are hundreds of lines of extra logic to compute these for 
- * the sole reason of optimizing performance. 
+ * 'need_entry' booleans.  These serve no functional purpose:
+ * You'd get exactly the same results if you just set these to
+ * TRUE.  But they affect performance tremendously, and there
+ * are hundreds of lines of extra logic to compute these for
+ * the sole reason of optimizing performance.
  */
 
 const char *
@@ -726,7 +788,8 @@
         return NULL;
 
     /* Only Split searches are allowed */
-    if (safe_strcmp(qof_query_get_search_for(q), GNC_ID_SPLIT)) {
+    if (safe_strcmp(qof_query_get_search_for(q), GNC_ID_SPLIT))
+    {
         PERR("Only SPLITs are supported, not %s", qof_query_get_search_for(q));
         return NULL;
     }
@@ -735,11 +798,13 @@
      * tables. See note above for details. */
     qterms = qof_query_get_terms(q);
 
-    for (il = qterms; il; il = il->next) {
+    for (il = qterms; il; il = il->next)
+    {
         /* andterms is GList of query terms that must be anded */
         andterms = il->data;
 
-        for (jl = andterms; jl; jl = jl->next) {
+        for (jl = andterms; jl; jl = jl->next)
+        {
             qt = (QofQueryTerm *) jl->data;
             pd = qof_query_term_get_pred_data(qt);
             path = qof_query_term_get_param_path(qt);
@@ -747,25 +812,35 @@
             g_assert(path);
 
             if (!safe_strcmp(path->data, SPLIT_ACTION) ||
-                !safe_strcmp(path->data, SPLIT_RECONCILE) ||
-                !safe_strcmp(path->data, SPLIT_MEMO) ||
-                !safe_strcmp(path->data, SPLIT_SHARE_PRICE)) {
+                    !safe_strcmp(path->data, SPLIT_RECONCILE) ||
+                    !safe_strcmp(path->data, SPLIT_MEMO) ||
+                    !safe_strcmp(path->data, SPLIT_SHARE_PRICE))
+            {
                 need_entry = TRUE;
-            } else if (!safe_strcmp(path->data, SPLIT_VALUE)) {
+            }
+            else if (!safe_strcmp(path->data, SPLIT_VALUE))
+            {
                 need_entry = TRUE;
                 need_trans_commodity = TRUE;
-            } else if (!safe_strcmp(pd->type_name, QOF_TYPE_GUID)) {
+            }
+            else if (!safe_strcmp(pd->type_name, QOF_TYPE_GUID))
+            {
                 if (!safe_strcmp(path->data, QOF_PARAM_GUID))
                     need_entry = TRUE;
-                else if (!safe_strcmp(path->data, SPLIT_ACCOUNT)) {
+                else if (!safe_strcmp(path->data, SPLIT_ACCOUNT))
+                {
                     need_account = TRUE;
                 }
-            } else if (!safe_strcmp(pd->type_name, QOF_TYPE_KVP)) {
+            }
+            else if (!safe_strcmp(pd->type_name, QOF_TYPE_KVP))
+            {
                 if (!safe_strcmp(path->data, SPLIT_KVP))
                     need_entry = TRUE;
                 else if (!safe_strcmp(path->data, SPLIT_ACCOUNT))
                     need_account = TRUE;
-            } else if (!safe_strcmp(path->data, SPLIT_AMOUNT)) {
+            }
+            else if (!safe_strcmp(path->data, SPLIT_AMOUNT))
+            {
                 need_entry = TRUE;
                 need_account_commodity = TRUE;
                 need_account = TRUE;
@@ -795,12 +870,14 @@
     if (need_trans_commodity)
         tables = g_list_prepend(tables, "gncCommodity trans_com");
 
-    if (tables) {
+    if (tables)
+    {
         GList *node;
 
         sq->pq = stpcpy(sq->pq, " FROM ");
 
-        for (node = tables; node; node = node->next) {
+        for (node = tables; node; node = node->next)
+        {
             sq->pq = stpcpy(sq->pq, node->data);
             if (node->next)
                 sq->pq = stpcpy(sq->pq, ", ");
@@ -811,29 +888,33 @@
 
     sq->pq = stpcpy(sq->pq, " WHERE ");
 
-    if (need_entry || need_account) {
+    if (need_entry || need_account)
+    {
         sq->pq = stpcpy(sq->pq,
                         " gncSplit.transGuid = gncTransaction.transGuid AND ");
     }
 
-    if (need_account) {
+    if (need_account)
+    {
         sq->pq = stpcpy(sq->pq,
                         " gncSplit.accountGuid = gncAccount.accountGuid AND ");
     }
 
     sq->pq = stpcpy(sq->pq, "  ( ");
 
-    /* qterms is a list of lists: outer list is a set of terms 
-     * that must be OR'ed together, inner lists are a set of terms 
-     * that must be anded.  Out strategy is to build the sql query 
+    /* qterms is a list of lists: outer list is a set of terms
+     * that must be OR'ed together, inner lists are a set of terms
+     * that must be anded.  Out strategy is to build the sql query
      * of the AND terms first, and OR these together ...
      */
-    for (il = qterms; il; il = il->next) {
+    for (il = qterms; il; il = il->next)
+    {
         /* andterms is GList of query terms that must be anded */
         andterms = il->data;
 
         /* if there are andterms, open a brace */
-        if (andterms) {
+        if (andterms)
+        {
             /* concatenate additional OR terms */
             if (more_or)
                 sq->pq = stpcpy(sq->pq, " OR ");
@@ -842,9 +923,11 @@
         }
 
         more_and = 0;
-        for (jl = andterms; jl; jl = jl->next) {
+        for (jl = andterms; jl; jl = jl->next)
+        {
             /* concatencate more terms together */
-            if (more_and) {
+            if (more_and)
+            {
                 sq->pq = stpcpy(sq->pq, " AND ");
             }
             more_and = 1;
@@ -854,154 +937,192 @@
             path = qof_query_term_get_param_path(qt);
             invert = qof_query_term_is_inverted(qt);
 
-            if (!safe_strcmp(pd->type_name, QOF_TYPE_GUID)) {
+            if (!safe_strcmp(pd->type_name, QOF_TYPE_GUID))
+            {
                 query_guid_t pdata = (query_guid_t) pd;
                 GList *node;
                 char *field = NULL;
 
                 PINFO("term is QOF_TYPE_GUID");
 
-                if (!safe_strcmp(path->data, QOF_PARAM_GUID)) {
+                if (!safe_strcmp(path->data, QOF_PARAM_GUID))
+                {
                     field = "gncSplit.splitGuid";
                     g_assert(pdata->options != QOF_GUID_MATCH_ALL);
 
-                } else if (!safe_strcmp(path->data, SPLIT_TRANS) &&
-                           !safe_strcmp(path->next->data, QOF_PARAM_GUID)) {
+                }
+                else if (!safe_strcmp(path->data, SPLIT_TRANS) &&
+                         !safe_strcmp(path->next->data, QOF_PARAM_GUID))
+                {
                     field = "gncSplit.transGUID";
                     g_assert(pdata->options != QOF_GUID_MATCH_ALL);
 
-                } else if (!safe_strcmp(path->data, SPLIT_ACCOUNT) &&
-                           !safe_strcmp(path->next->data, QOF_PARAM_GUID)) {
+                }
+                else if (!safe_strcmp(path->data, SPLIT_ACCOUNT) &&
+                         !safe_strcmp(path->next->data, QOF_PARAM_GUID))
+                {
                     field = "gncSplit.accountGUID";
                     g_assert(pdata->options != QOF_GUID_MATCH_ALL);
 
-                } else if (!safe_strcmp(path->data, SPLIT_TRANS) &&
-                           !safe_strcmp(path->next->data, TRANS_SPLITLIST) &&
-                           !safe_strcmp(path->next->next->data,
-                                        SPLIT_ACCOUNT_GUID)) {
+                }
+                else if (!safe_strcmp(path->data, SPLIT_TRANS) &&
+                         !safe_strcmp(path->next->data, TRANS_SPLITLIST) &&
+                         !safe_strcmp(path->next->next->data,
+                                      SPLIT_ACCOUNT_GUID))
+                {
                     field = "gncSplit.accountGUID";
                     g_assert(pdata->options == QOF_GUID_MATCH_ALL);
 
-                } else if (!safe_strcmp(path->data, QOF_PARAM_BOOK) &&
-                           !safe_strcmp(path->next->data, QOF_PARAM_GUID)) {
+                }
+                else if (!safe_strcmp(path->data, QOF_PARAM_BOOK) &&
+                         !safe_strcmp(path->next->data, QOF_PARAM_GUID))
+                {
                     /* XXX: Need to support the Book GUID? (gncAccount.bookGUID) */
                     field = "gncAccount.bookGUID";
                     g_assert(pdata->options != QOF_GUID_MATCH_ALL);
-                } else {
+                }
+                else
+                {
                     PINFO("Unknown GUID parameter, %s", (char *)path->data);
                 }
 
-                if (field != NULL) {
+                if (field != NULL)
+                {
                     if (invert)
                         sq->pq = stpcpy(sq->pq, "NOT ");
 
                     sq->pq = stpcpy(sq->pq, "(");
 
-                    for (node = pdata->guids; node; node = node->next) {
+                    for (node = pdata->guids; node; node = node->next)
+                    {
 
-                        switch (pdata->options) {
-                            case QOF_GUID_MATCH_NONE:
-                                sq->pq = stpcpy(sq->pq, "NOT ");
-                                /* fall through */
+                        switch (pdata->options)
+                        {
+                        case QOF_GUID_MATCH_NONE:
+                            sq->pq = stpcpy(sq->pq, "NOT ");
+                            /* fall through */
 
+                        case QOF_GUID_MATCH_ANY:
+                            sq->pq = stpcpy(sq->pq, field);
+                            sq->pq = stpcpy(sq->pq, "='");
+                            sq->pq =
+                                guid_to_string_buff((GUID *) node->data,
+                                                    sq->pq);
+                            sq->pq = stpcpy(sq->pq, "'");
+                            break;
+
+                        case QOF_GUID_MATCH_ALL:
+                            sq->pq = stpcpy(sq->pq,
+                                            " EXISTS ( SELECT true FROM gncSplit e"
+                                            "          WHERE "
+                                            "e.transGuid = gncTransaction.transGuid"
+                                            " AND " "e.accountGuid='");
+                            sq->pq =
+                                guid_to_string_buff((GUID *) node->data,
+                                                    sq->pq);
+                            sq->pq = stpcpy(sq->pq, "')");
+
+                            break;
+
+                        default:
+                            PERR("unexpected guid match type: %d",
+                                 pdata->options);
+                            break;
+                        }
+
+                        if (node->next)
+                        {
+                            switch (pdata->options)
+                            {
                             case QOF_GUID_MATCH_ANY:
-                                sq->pq = stpcpy(sq->pq, field);
-                                sq->pq = stpcpy(sq->pq, "='");
-                                sq->pq =
-                                    guid_to_string_buff((GUID *) node->data,
-                                                        sq->pq);
-                                sq->pq = stpcpy(sq->pq, "'");
+                                sq->pq = stpcpy(sq->pq, " OR ");
                                 break;
 
                             case QOF_GUID_MATCH_ALL:
-                                sq->pq = stpcpy(sq->pq,
-                                                " EXISTS ( SELECT true FROM gncSplit e"
-                                                "          WHERE "
-                                                "e.transGuid = gncTransaction.transGuid"
-                                                " AND " "e.accountGuid='");
-                                sq->pq =
-                                    guid_to_string_buff((GUID *) node->data,
-                                                        sq->pq);
-                                sq->pq = stpcpy(sq->pq, "')");
-
+                            case QOF_GUID_MATCH_NONE:
+                                sq->pq = stpcpy(sq->pq, " AND ");
                                 break;
 
                             default:
-                                PERR("unexpected guid match type: %d",
+                                PERR("unexpected account match type: %d",
                                      pdata->options);
                                 break;
-                        }
-
-                        if (node->next) {
-                            switch (pdata->options) {
-                                case QOF_GUID_MATCH_ANY:
-                                    sq->pq = stpcpy(sq->pq, " OR ");
-                                    break;
-
-                                case QOF_GUID_MATCH_ALL:
-                                case QOF_GUID_MATCH_NONE:
-                                    sq->pq = stpcpy(sq->pq, " AND ");
-                                    break;
-
-                                default:
-                                    PERR("unexpected account match type: %d",
-                                         pdata->options);
-                                    break;
                             }
                         }
                     }
 
                     sq->pq = stpcpy(sq->pq, ")");
 
-                } else {
+                }
+                else
+                {
                     /* Empty field -- nothing to "AND" in... */
                     more_and = 0;
                 }
 
-            } else if (!safe_strcmp(pd->type_name, QOF_TYPE_STRING)) {
+            }
+            else if (!safe_strcmp(pd->type_name, QOF_TYPE_STRING))
+            {
                 query_string_t pdata = (query_string_t) pd;
 
-                if (!safe_strcmp(path->data, SPLIT_ACTION)) {
+                if (!safe_strcmp(path->data, SPLIT_ACTION))
+                {
                     PINFO("term is PR_ACTION");
                     STRING_TERM("gncSplit.action");
 
-                } else if (!safe_strcmp(path->data, SPLIT_MEMO)) {
+                }
+                else if (!safe_strcmp(path->data, SPLIT_MEMO))
+                {
                     PINFO("term is PR_MEMO");
                     STRING_TERM("gncSplit.memo");
 
-                } else if (!safe_strcmp(path->data, SPLIT_TRANS)) {
+                }
+                else if (!safe_strcmp(path->data, SPLIT_TRANS))
+                {
                     path = path->next;
 
-                    if (!path) {
+                    if (!path)
+                    {
                         PINFO("invalid transaction parameter");
 
-                    } else if (!safe_strcmp(path->data, TRANS_DESCRIPTION)) {
+                    }
+                    else if (!safe_strcmp(path->data, TRANS_DESCRIPTION))
+                    {
                         PINFO("term is PR_DESC");
                         STRING_TERM("gncTransaction.description");
 
-                    } else if (!safe_strcmp(path->data, TRANS_NUM)) {
+                    }
+                    else if (!safe_strcmp(path->data, TRANS_NUM))
+                    {
                         PINFO("term is PR_NUM");
                         STRING_TERM("gncTransaction.num");
-                    } else
+                    }
+                    else
                         PINFO("unknown string (transaction) parameter: %s",
                               (char *)(path->data));
-                } else
+                }
+                else
                     PINFO("unknown string (split) parameter: %s",
                           (char *)(path->data));
 
 
-            } else if (!safe_strcmp(pd->type_name, QOF_TYPE_NUMERIC)) {
+            }
+            else if (!safe_strcmp(pd->type_name, QOF_TYPE_NUMERIC))
+            {
                 query_numeric_t pdata = (query_numeric_t) pd;
 
 
-                if (!safe_strcmp(path->data, SPLIT_AMOUNT)) {
+                if (!safe_strcmp(path->data, SPLIT_AMOUNT))
+                {
                     PINFO("term is PR_SHRS");
                     sq->pq = stpcpy(sq->pq,
                                     "gncAccount.commodity = account_com.commodity AND ");
                     AMOUNT_TERM("gncSplit.amount", "abs(gncSplit.amount)",
                                 "account_com.fraction");
 
-                } else if (!safe_strcmp(path->data, SPLIT_VALUE)) {
+                }
+                else if (!safe_strcmp(path->data, SPLIT_VALUE))
+                {
 
                     PINFO("term is PR_VALUE");
                     sq->pq = stpcpy(sq->pq,
@@ -1009,19 +1130,25 @@
                     AMOUNT_TERM("gncSplit.value", "abs(gncSplit.value)",
                                 "trans_com.fraction");
 
-                } else if (!safe_strcmp(path->data, SPLIT_SHARE_PRICE)) {
+                }
+                else if (!safe_strcmp(path->data, SPLIT_SHARE_PRICE))
+                {
 
                     PINFO("term is PR_PRICE");
 
                     AMOUNT_TERM("gncSplit.value / gncSplit.amount",
                                 "gncHelperPrVal(gncSplit)",
                                 "gncHelperPrAmt(gncSplit)");
-                } else {
+                }
+                else
+                {
 
                     PINFO("Unknown NUMERIC: %s", (char *)(path->data));
                 }
 
-            } else if (!safe_strcmp(pd->type_name, QOF_TYPE_DATE)) {
+            }
+            else if (!safe_strcmp(pd->type_name, QOF_TYPE_DATE))
+            {
                 query_date_t pdata = (query_date_t) pd;
                 char *field = NULL;
                 const char *op = NULL;
@@ -1031,12 +1158,13 @@
                     sq->pq = stpcpy(sq->pq, "NOT (");
 
                 if (!safe_strcmp(path->data, SPLIT_TRANS) &&
-                    !safe_strcmp(path->next->data, TRANS_DATE_POSTED))
+                        !safe_strcmp(path->next->data, TRANS_DATE_POSTED))
                     field = "gncTransaction.date_posted";
 
                 op = compare_op_name(pd->how);
 
-                if (field) {
+                if (field)
+                {
                     sq->pq = stpcpy(sq->pq, field);
                     sq->pq = stpcpy(sq->pq, op);
                     sq->pq = stpcpy(sq->pq, "'");
@@ -1048,11 +1176,14 @@
                 if (invert)
                     sq->pq = stpcpy(sq->pq, ") ");
 
-            } else if (!safe_strcmp(pd->type_name, QOF_TYPE_CHAR)) {
+            }
+            else if (!safe_strcmp(pd->type_name, QOF_TYPE_CHAR))
+            {
                 query_char_t pdata = (query_char_t) pd;
                 int got_one = 0;
 
-                if (!safe_strcmp(path->data, SPLIT_RECONCILE)) {
+                if (!safe_strcmp(path->data, SPLIT_RECONCILE))
+                {
 
                     PINFO("term is CHAR (Reconcile)");
 
@@ -1072,24 +1203,32 @@
                     if (invert)
                         sq->pq = stpcpy(sq->pq, ") ");
 
-                } else
+                }
+                else
                     PINFO("Unknown CHAR type, %s", (char *)(path->data));
 
-            } else if (!safe_strcmp(pd->type_name, QOF_TYPE_KVP)) {
+            }
+            else if (!safe_strcmp(pd->type_name, QOF_TYPE_KVP))
+            {
                 query_kvp_t pdata = (query_kvp_t) pd;
 
                 PINFO("term is a KVP");
                 sqlQuery_kvp_build(sq, path, pd->how, invert, pdata);
 
-            } else {
+            }
+            else
+            {
                 PINFO("Unsupported Query Type: %s", pd->type_name);
             }
         }
 
         /* if there were and terms, close the brace */
-        if (il->data) {
+        if (il->data)
+        {
             sq->pq = stpcpy(sq->pq, ")");
-        } else {
+        }
+        else
+        {
             more_and = 0;
         }
     }
@@ -1098,18 +1237,21 @@
 
     /* ---------------------------------------------------- */
     /* implement sorting order as well; bad sorts lead to bad data
-     * if the limit is set to a finite number of rows. 
+     * if the limit is set to a finite number of rows.
      */
 
-    if (qof_query_sort_get_param_path(s1) != NULL) {
+    if (qof_query_sort_get_param_path(s1) != NULL)
+    {
         sq->pq = stpcpy(sq->pq, "ORDER BY ");
         sq->pq = sql_sort_order(sq->pq, s1);
 
-        if (qof_query_sort_get_param_path(s2) != NULL) {
+        if (qof_query_sort_get_param_path(s2) != NULL)
+        {
             sq->pq = stpcpy(sq->pq, ", ");
             sq->pq = sql_sort_order(sq->pq, s2);
 
-            if (qof_query_sort_get_param_path(s3) != NULL) {
+            if (qof_query_sort_get_param_path(s3) != NULL)
+            {
                 sq->pq = stpcpy(sq->pq, ", ");
                 sq->pq = sql_sort_order(sq->pq, s3);
             }
@@ -1119,7 +1261,8 @@
     /* ---------------------------------------------------- */
     /* limit the query result to a finite number of rows */
     max_rows = qof_query_get_max_results(q);
-    if (0 <= max_rows) {
+    if (0 <= max_rows)
+    {
         sq->pq = stpcpy(sq->pq, " LIMIT ");
         sq->pq += snprintf(sq->pq, 30, "%d", max_rows);
     }

Modified: gnucash/trunk/src/backend/postgres/gncquery.h
===================================================================
--- gnucash/trunk/src/backend/postgres/gncquery.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/gncquery.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -26,13 +26,13 @@
  *
  * FUNCTION:
  * Convert gnucash engine Query (a la Query.h) into an SQL Query
- * 
- * The gnc engine query consists of doubly nested list of 
- * query terms.  The inner list consists of terms that need to be 
+ *
+ * The gnc engine query consists of doubly nested list of
+ * query terms.  The inner list consists of terms that need to be
  * AND'ed together; the outer list OR's together the inner lists.
  *
  * The resulting query will resemble
- * SELECT * FROM gncSplit WHERE 
+ * SELECT * FROM gncSplit WHERE
  * (splitguid='deadbeef') OR
  * (memo='deposit' AND date_reconciled>'1998-07-01 11:00:00.345678 -0500')
  *

Modified: gnucash/trunk/src/backend/postgres/kvp-sql.c
===================================================================
--- gnucash/trunk/src/backend/postgres/kvp-sql.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/kvp-sql.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -49,66 +49,67 @@
 static gpointer
 iguid_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-  int iguid = atoi (DB_GET_VAL ("iguid", 0));
-  guint32 ret = iguid;
-  return GUINT_TO_POINTER (ret);
+    int iguid = atoi (DB_GET_VAL ("iguid", 0));
+    guint32 ret = iguid;
+    return GUINT_TO_POINTER (ret);
 }
 
 
 guint32
 pgendNewGUIDidx (PGBackend *be)
 {
-   guint32 iguid;
-   char * p;
+    guint32 iguid;
+    char * p;
 
-   p = "SELECT nextval('gnc_iguid_seq') AS iguid;";
-   SEND_QUERY (be, p, 0);
-   iguid = GPOINTER_TO_UINT (pgendGetResults (be, iguid_cb,
-                                              GUINT_TO_POINTER (0)));
-   return iguid;
+    p = "SELECT nextval('gnc_iguid_seq') AS iguid;";
+    SEND_QUERY (be, p, 0);
+    iguid = GPOINTER_TO_UINT (pgendGetResults (be, iguid_cb,
+                              GUINT_TO_POINTER (0)));
+    return iguid;
 }
 
 /* =========================================================== */
-/* given integer ipath (path id) and a string, poke the string 
+/* given integer ipath (path id) and a string, poke the string
  * into a cache in local memory
  */
 
 static void
 pgendPokePathCache (PGBackend *be, int ipath, const char *path_str)
 {
-   int i;
+    int i;
 
-   /* get more memory for cache if needed */
-   if (ipath >= be->path_cache_size)
-   {
-      be->path_cache = 
-         (char **) g_realloc (be->path_cache, (ipath+100)*sizeof (char *));
-      for (i=be->path_cache_size; i<ipath+100; i++) {
-        (be->path_cache)[i] = NULL;
-      }
-      be->path_cache_size = ipath+100;
-   }
+    /* get more memory for cache if needed */
+    if (ipath >= be->path_cache_size)
+    {
+        be->path_cache =
+            (char **) g_realloc (be->path_cache, (ipath + 100) * sizeof (char *));
+        for (i = be->path_cache_size; i < ipath + 100; i++)
+        {
+            (be->path_cache)[i] = NULL;
+        }
+        be->path_cache_size = ipath + 100;
+    }
 
-   /* poke string into slot ipath */
-   if (NULL == (be->path_cache)[ipath])
-   {
-       (be->path_cache)[ipath] = g_strdup (path_str);
-   }
+    /* poke string into slot ipath */
+    if (NULL == (be->path_cache)[ipath])
+    {
+        (be->path_cache)[ipath] = g_strdup (path_str);
+    }
 
-   if (be->ipath_max < ipath) be->ipath_max = ipath;
+    if (be->ipath_max < ipath) be->ipath_max = ipath;
 }
 
 /* =========================================================== */
-/* given an integer ipath (path id), return the path string 
- * from local memory 
+/* given an integer ipath (path id), return the path string
+ * from local memory
  */
 
 static char *
 pgendPeekPathCache (PGBackend *be, int ipath)
 {
-   if (ipath > be->ipath_max) return NULL;
-   if (0 >= ipath) return NULL;
-   return (be->path_cache)[ipath];
+    if (ipath > be->ipath_max) return NULL;
+    if (0 >= ipath) return NULL;
+    return (be->path_cache)[ipath];
 }
 
 /* =========================================================== */
@@ -117,46 +118,48 @@
 static gpointer
 ival_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-  int ival = atoi (DB_GET_VAL ("ipath", 0));
-  return GINT_TO_POINTER(ival);
+    int ival = atoi (DB_GET_VAL ("ipath", 0));
+    return GINT_TO_POINTER(ival);
 }
 
 
 static int
 pgendGetCache (PGBackend *be, const char *val_str, sqlEscape *escape)
 {
-   char *p;
-   int ival =0;
+    char *p;
+    int ival = 0;
 
-   if (!be || !val_str || !escape) return 0;
+    if (!be || !val_str || !escape) return 0;
 
-   val_str = sqlEscapeString (escape, val_str);
+    val_str = sqlEscapeString (escape, val_str);
 
-   /* first, lets see if we can find the guid or path. 
-    * If we can then  just return it */
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "SELECT ipath FROM gncPathCache WHERE path='");
-   p = stpcpy (p, val_str);
-   p = stpcpy (p, "';");
+    /* first, lets see if we can find the guid or path.
+     * If we can then  just return it */
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "SELECT ipath FROM gncPathCache WHERE path='");
+    p = stpcpy (p, val_str);
+    p = stpcpy (p, "';");
 
-   SEND_QUERY (be,be->buff, 0);
-   ival = GPOINTER_TO_INT(pgendGetResults (be, ival_cb, (gpointer) 0));
-   if (ival) return ival;
+    SEND_QUERY (be, be->buff, 0);
+    ival = GPOINTER_TO_INT(pgendGetResults (be, ival_cb, (gpointer) 0));
+    if (ival) return ival;
 
-   /* Else, this guid has never been stored before. 
-    * Poke it into the the database */
+    /* Else, this guid has never been stored before.
+     * Poke it into the the database */
 
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "INSERT INTO gncPathCache (path) VALUES ('");
-   p = stpcpy (p, val_str);
-   p = stpcpy (p, "');");
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "INSERT INTO gncPathCache (path) VALUES ('");
+    p = stpcpy (p, val_str);
+    p = stpcpy (p, "');");
 
-   SEND_QUERY (be,be->buff, 0);
-   FINISH_QUERY(be->connection);
+    SEND_QUERY (be, be->buff, 0);
+    FINISH_QUERY(be->connection);
 
-   /* and requery to get the serial number ... */
-   ival = pgendGetCache (be, val_str, escape);
-   return ival;
+    /* and requery to get the serial number ... */
+    ival = pgendGetCache (be, val_str, escape);
+    return ival;
 }
 
 /* =========================================================== */
@@ -165,13 +168,13 @@
 static int
 pgendGetPathCache (PGBackend *be, const char *path_str, sqlEscape *escape)
 {
-   int ival;
-   ival = pgendGetCache (be, path_str, escape);
-   PINFO ("cached %d for %s", ival, path_str ? path_str : "(null)");
+    int ival;
+    ival = pgendGetCache (be, path_str, escape);
+    PINFO ("cached %d for %s", ival, path_str ? path_str : "(null)");
 
-   if (0 >= ival) return ival;
-   pgendPokePathCache (be, ival, path_str);
-   return ival;
+    if (0 >= ival) return ival;
+    pgendPokePathCache (be, ival, path_str);
+    return ival;
 }
 
 /* =========================================================== */
@@ -179,211 +182,214 @@
  * of a traversal callback.  The store_cb() routine is the callback.
  */
 
-typedef struct store_data_s {
-   PGBackend *be;
-   sqlEscape *escape;
-   int iguid;
-   int ipath;
-   char *path;
-   char *stype;
-   union {
-      gint64 ival;
-      double dbl;
-      gnc_numeric numeric;
-      const char *str;
-      const GUID *guid;
-      Timespec ts;
-      GList *list;
-   } u;
+typedef struct store_data_s
+{
+    PGBackend *be;
+    sqlEscape *escape;
+    int iguid;
+    int ipath;
+    char *path;
+    char *stype;
+    union
+    {
+        gint64 ival;
+        double dbl;
+        gnc_numeric numeric;
+        const char *str;
+        const GUID *guid;
+        Timespec ts;
+        GList *list;
+    } u;
 } store_data_t;
 
 #include "kvp-autogen.h"
 #include "kvp-autogen.c"
 
-static void 
+static void
 store_cb (const char *key, KvpValue *val, gpointer p)
 {
-   store_data_t *cb_data = (store_data_t *) p;
-   PGBackend *be = cb_data->be;
-   int ipath;
-   char *path_save;
+    store_data_t *cb_data = (store_data_t *) p;
+    PGBackend *be = cb_data->be;
+    int ipath;
+    char *path_save;
 
-   path_save = cb_data->path;
-   cb_data->path = g_strjoin ("/", path_save, key, NULL);
+    path_save = cb_data->path;
+    cb_data->path = g_strjoin ("/", path_save, key, NULL);
 
-   ipath = pgendGetPathCache (be, cb_data->path, cb_data->escape);
-   cb_data->ipath = ipath;
+    ipath = pgendGetPathCache (be, cb_data->path, cb_data->escape);
+    cb_data->ipath = ipath;
 
-   if (ipath)
-   {
+    if (ipath)
+    {
 
-      switch (kvp_value_get_type (val))
-      {
-         case KVP_TYPE_GINT64:
-            {
-               gint64 ival = kvp_value_get_gint64 (val);
-               PINFO ("path=%s type=gint64 val=%" G_GINT64_FORMAT,
-                      cb_data->path,
-                      ival);
+        switch (kvp_value_get_type (val))
+        {
+        case KVP_TYPE_GINT64:
+        {
+            gint64 ival = kvp_value_get_gint64 (val);
+            PINFO ("path=%s type=gint64 val=%" G_GINT64_FORMAT,
+                   cb_data->path,
+                   ival);
 
-               cb_data->stype = "int8";
-               cb_data->u.ival = ival;
-               pgendPutOneKVPint64Only (be, cb_data);
-            }
-            break;
+            cb_data->stype = "int8";
+            cb_data->u.ival = ival;
+            pgendPutOneKVPint64Only (be, cb_data);
+        }
+        break;
 
-         case KVP_TYPE_DOUBLE:
-            {
-               double ival = kvp_value_get_double (val);
-               PINFO ("path=%s type=double val=%g", cb_data->path, ival);
+        case KVP_TYPE_DOUBLE:
+        {
+            double ival = kvp_value_get_double (val);
+            PINFO ("path=%s type=double val=%g", cb_data->path, ival);
 
-               cb_data->stype = "flt8";
-               cb_data->u.dbl = ival;
-               pgendPutOneKVPdoubleOnly (be, cb_data);
-            }
-            break;
+            cb_data->stype = "flt8";
+            cb_data->u.dbl = ival;
+            pgendPutOneKVPdoubleOnly (be, cb_data);
+        }
+        break;
 
-         case KVP_TYPE_NUMERIC:
-            {
-               gnc_numeric ival = kvp_value_get_numeric (val);
-               PINFO ("path=%s type=numeric val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
-                      cb_data->path,
-                      ival.num,
-                      ival.denom);
+        case KVP_TYPE_NUMERIC:
+        {
+            gnc_numeric ival = kvp_value_get_numeric (val);
+            PINFO ("path=%s type=numeric val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
+                   cb_data->path,
+                   ival.num,
+                   ival.denom);
 
-               cb_data->stype = "frac";
-               cb_data->u.numeric = ival;
-               pgendPutOneKVPnumericOnly (be, cb_data);
-            }
-            break;
+            cb_data->stype = "frac";
+            cb_data->u.numeric = ival;
+            pgendPutOneKVPnumericOnly (be, cb_data);
+        }
+        break;
 
-         case KVP_TYPE_STRING:
-            {
-               const char *str = kvp_value_get_string (val);
-               PINFO ("path=%s type=str val=%s", cb_data->path, str);
+        case KVP_TYPE_STRING:
+        {
+            const char *str = kvp_value_get_string (val);
+            PINFO ("path=%s type=str val=%s", cb_data->path, str);
 
-               cb_data->stype = "text";
-               cb_data->u.str = str;
-               pgendPutOneKVPstringOnly (be, cb_data);
-            }
-            break;
+            cb_data->stype = "text";
+            cb_data->u.str = str;
+            pgendPutOneKVPstringOnly (be, cb_data);
+        }
+        break;
 
-         case KVP_TYPE_GUID:
-            {
-               char guid_str[GUID_ENCODING_LENGTH+1];
-               const GUID *guid = kvp_value_get_guid(val);
-               guid_to_string_buff (guid, guid_str);
-               PINFO ("path=%s type=guid val=%s", cb_data->path, guid_str);
+        case KVP_TYPE_GUID:
+        {
+            char guid_str[GUID_ENCODING_LENGTH+1];
+            const GUID *guid = kvp_value_get_guid(val);
+            guid_to_string_buff (guid, guid_str);
+            PINFO ("path=%s type=guid val=%s", cb_data->path, guid_str);
 
-               cb_data->stype = "guid";
-               cb_data->u.str = guid_str;
-               pgendPutOneKVPguidOnly (be, cb_data);
-            }
-            break;
+            cb_data->stype = "guid";
+            cb_data->u.str = guid_str;
+            pgendPutOneKVPguidOnly (be, cb_data);
+        }
+        break;
 
-         case KVP_TYPE_TIMESPEC:
-           {
-             PINFO ("path=%s type=timespec", cb_data->path);
-             cb_data->stype = "time";
-             cb_data->u.ts = kvp_value_get_timespec (val);
-             pgendPutOneKVPtimespecOnly (be, cb_data);
-           }
-           break;
+        case KVP_TYPE_TIMESPEC:
+        {
+            PINFO ("path=%s type=timespec", cb_data->path);
+            cb_data->stype = "time";
+            cb_data->u.ts = kvp_value_get_timespec (val);
+            pgendPutOneKVPtimespecOnly (be, cb_data);
+        }
+        break;
 
-         case KVP_TYPE_BINARY:
+        case KVP_TYPE_BINARY:
             PERR ("Binary KVP Type not yet implemented\n");
             break;
 
-         case KVP_TYPE_GLIST:
-            {
-               GList *start;
-               start = kvp_value_get_glist (val);
-               PINFO ("path=%s type=glist", cb_data->path);
+        case KVP_TYPE_GLIST:
+        {
+            GList *start;
+            start = kvp_value_get_glist (val);
+            PINFO ("path=%s type=glist", cb_data->path);
 
-               cb_data->stype = "list";
-               cb_data->u.list = start;
-               PERR ("List KVP Type not yet implemented\n");
-            }
-            break;
+            cb_data->stype = "list";
+            cb_data->u.list = start;
+            PERR ("List KVP Type not yet implemented\n");
+        }
+        break;
 
-         case KVP_TYPE_FRAME: 
-            {
-               KvpFrame *frame;
-               PINFO ("path=%s type=frame", cb_data->path);
-               frame = kvp_value_get_frame (val);
-               kvp_frame_for_each_slot (frame, store_cb, p);
-            }
-            break;
+        case KVP_TYPE_FRAME:
+        {
+            KvpFrame *frame;
+            PINFO ("path=%s type=frame", cb_data->path);
+            frame = kvp_value_get_frame (val);
+            kvp_frame_for_each_slot (frame, store_cb, p);
+        }
+        break;
 
-         default:
-            PERR("Unknown type %d for path=%s\n", 
+        default:
+            PERR("Unknown type %d for path=%s\n",
                  kvp_value_get_type (val), cb_data->path);
-      }
-   }
+        }
+    }
 
-   g_free (cb_data->path);
-   cb_data->path = path_save;
+    g_free (cb_data->path);
+    cb_data->path = path_save;
 }
 
-void 
+void
 pgendKVPStore (PGBackend *be, guint32 iguid, KvpFrame *kf)
 {
-   store_data_t cb_data;
-   if (!be || 0 == iguid || !kf) return;
-   ENTER (" ");
+    store_data_t cb_data;
+    if (!be || 0 == iguid || !kf) return;
+    ENTER (" ");
 
-   cb_data.be = be;
-   cb_data.escape = sqlEscape_new ();
-   cb_data.iguid = iguid;
-   cb_data.path = "";
+    cb_data.be = be;
+    cb_data.escape = sqlEscape_new ();
+    cb_data.iguid = iguid;
+    cb_data.path = "";
 
-   kvp_frame_for_each_slot (kf, store_cb, &cb_data);
+    kvp_frame_for_each_slot (kf, store_cb, &cb_data);
 
-   sqlEscape_destroy (cb_data.escape);
+    sqlEscape_destroy (cb_data.escape);
 
-   LEAVE (" ");
+    LEAVE (" ");
 }
 
 /* =========================================================== */
-/* These functions suck new, unknown paths out of the database 
+/* These functions suck new, unknown paths out of the database
  * and poke them into our local cache.
  */
 
-static gpointer 
+static gpointer
 path_loader (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   int ipath = atoi (DB_GET_VAL ("ipath", j));
-   char *path = DB_GET_VAL ("path", j);
-   pgendPokePathCache (be, ipath, path);
-   return 0;
+    int ipath = atoi (DB_GET_VAL ("ipath", j));
+    char *path = DB_GET_VAL ("path", j);
+    pgendPokePathCache (be, ipath, path);
+    return 0;
 }
 
 void
 pgendKVPInit (PGBackend *be)
 {
-   char *p;
+    char *p;
 
-   /* don't re-init multiple times in single-user mode.
-    * Once is enough.  But in multi-user mode, we need to
-    * check constantly, since other users may have added
-    * more paths. 
-    */
-   if (((MODE_SINGLE_UPDATE == be->session_mode) || 
-        (MODE_SINGLE_FILE   == be->session_mode)) &&
-        (0 < be->ipath_max)) return;
+    /* don't re-init multiple times in single-user mode.
+     * Once is enough.  But in multi-user mode, we need to
+     * check constantly, since other users may have added
+     * more paths.
+     */
+    if (((MODE_SINGLE_UPDATE == be->session_mode) ||
+            (MODE_SINGLE_FILE   == be->session_mode)) &&
+            (0 < be->ipath_max)) return;
 
-   /* get new paths out of the database */
-   p = be->buff; *p=0;
-   p = stpcpy (p, "SELECT * FROM gncPathCache WHERE ipath > ");
-   p += sprintf (p, "%d", be->ipath_max);
-   p = stpcpy (p, ";");
-   SEND_QUERY (be,be->buff, );
-   pgendGetResults (be, path_loader, NULL);
+    /* get new paths out of the database */
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "SELECT * FROM gncPathCache WHERE ipath > ");
+    p += sprintf (p, "%d", be->ipath_max);
+    p = stpcpy (p, ";");
+    SEND_QUERY (be, be->buff, );
+    pgendGetResults (be, path_loader, NULL);
 }
 
 /* =========================================================== */
 /* hack alert -- this code assumed that the path cache
- * is up to date, which it might not be in a multi-user world 
+ * is up to date, which it might not be in a multi-user world
  */
 
 #define KVP_HANDLER_SETUP				\
@@ -401,9 +407,9 @@
    tail ++;						\
 							\
    if (!kf) kf = kvp_frame_new();			\
+ 
 
 
-
 #define KVP_HANDLER_TAKEDOWN				\
    final = kvp_frame_get_frame_slash (kf, path);	\
    kvp_frame_set_slot_nc (final, tail, kv);		\
@@ -413,74 +419,74 @@
    *tail = '/';						\
 							\
    return kf;						\
+ 
 
 
-
-static gpointer 
+static gpointer
 int64_handler (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   KVP_HANDLER_SETUP;
-   kv = kvp_value_new_gint64 (strtoll (DB_GET_VAL ("data", j), NULL, 0));
-   KVP_HANDLER_TAKEDOWN;
+    KVP_HANDLER_SETUP;
+    kv = kvp_value_new_gint64 (strtoll (DB_GET_VAL ("data", j), NULL, 0));
+    KVP_HANDLER_TAKEDOWN;
 }
 
-static gpointer 
+static gpointer
 dbl_handler (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   KVP_HANDLER_SETUP;
-   kv = kvp_value_new_double (atof (DB_GET_VAL ("data", j)));
-   KVP_HANDLER_TAKEDOWN;
+    KVP_HANDLER_SETUP;
+    kv = kvp_value_new_double (atof (DB_GET_VAL ("data", j)));
+    KVP_HANDLER_TAKEDOWN;
 }
 
-static gpointer 
+static gpointer
 numeric_handler (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   gnc_numeric gn;
-   KVP_HANDLER_SETUP;
-   gn.num = strtoll (DB_GET_VAL ("num", j), NULL, 0);
-   gn.denom = strtoll (DB_GET_VAL ("denom", j), NULL, 0);
-   kv = kvp_value_new_gnc_numeric (gn);
-   KVP_HANDLER_TAKEDOWN;
+    gnc_numeric gn;
+    KVP_HANDLER_SETUP;
+    gn.num = strtoll (DB_GET_VAL ("num", j), NULL, 0);
+    gn.denom = strtoll (DB_GET_VAL ("denom", j), NULL, 0);
+    kv = kvp_value_new_gnc_numeric (gn);
+    KVP_HANDLER_TAKEDOWN;
 }
 
 
-static gpointer 
+static gpointer
 str_handler (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   KVP_HANDLER_SETUP;
-   kv = kvp_value_new_string (DB_GET_VAL ("data", j));
-   KVP_HANDLER_TAKEDOWN;
+    KVP_HANDLER_SETUP;
+    kv = kvp_value_new_string (DB_GET_VAL ("data", j));
+    KVP_HANDLER_TAKEDOWN;
 }
 
 
-static gpointer 
+static gpointer
 guid_handler (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   gboolean rc;
-   GUID guid;
-   KVP_HANDLER_SETUP;
-   rc = string_to_guid ((DB_GET_VAL ("data", j)), &guid);
-   if (rc) kv = kvp_value_new_guid (&guid);
-   KVP_HANDLER_TAKEDOWN;
+    gboolean rc;
+    GUID guid;
+    KVP_HANDLER_SETUP;
+    rc = string_to_guid ((DB_GET_VAL ("data", j)), &guid);
+    if (rc) kv = kvp_value_new_guid (&guid);
+    KVP_HANDLER_TAKEDOWN;
 }
 
-static gpointer 
+static gpointer
 timespec_handler (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   Timespec ts;
-   KVP_HANDLER_SETUP;
-   ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL ("data", j));
-   kv = kvp_value_new_timespec (ts);
-   KVP_HANDLER_TAKEDOWN;
+    Timespec ts;
+    KVP_HANDLER_SETUP;
+    ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL ("data", j));
+    kv = kvp_value_new_timespec (ts);
+    KVP_HANDLER_TAKEDOWN;
 }
 
-static gpointer 
+static gpointer
 list_handler (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   KVP_HANDLER_SETUP;
-   PERR ("not implemented");
-   // kv = kvp_value_new_glist ();
-   KVP_HANDLER_TAKEDOWN;
+    KVP_HANDLER_SETUP;
+    PERR ("not implemented");
+    // kv = kvp_value_new_glist ();
+    KVP_HANDLER_TAKEDOWN;
 }
 
 #define GET_KVP(TYPE)					\
@@ -493,32 +499,32 @@
    kf = pgendGetResults (be, TYPE##_handler, kf);	\
 }
 
-KvpFrame * 
+KvpFrame *
 pgendKVPFetch (PGBackend *be, guint32 iguid, KvpFrame *kf)
 {
-   char * p;
-   char iguid_str[40];
-   if (!be || 0 == iguid) return kf;
+    char * p;
+    char iguid_str[40];
+    if (!be || 0 == iguid) return kf;
 
-   ENTER (" ");
+    ENTER (" ");
 
-   /* update the path cache; other users may have added more paths */
-   pgendKVPInit (be);   
+    /* update the path cache; other users may have added more paths */
+    pgendKVPInit (be);
 
-   /* get the effective iguid for this object */
-   snprintf (iguid_str, 40, "%d;", iguid);
+    /* get the effective iguid for this object */
+    snprintf (iguid_str, 40, "%d;", iguid);
 
-   /* now troll the individual tables for data */
-   GET_KVP(int64);
-   GET_KVP(dbl);
-   GET_KVP(numeric);
-   GET_KVP(str);
-   GET_KVP(guid);
-   GET_KVP(timespec);
-   GET_KVP(list);
+    /* now troll the individual tables for data */
+    GET_KVP(int64);
+    GET_KVP(dbl);
+    GET_KVP(numeric);
+    GET_KVP(str);
+    GET_KVP(guid);
+    GET_KVP(timespec);
+    GET_KVP(list);
 
-   LEAVE (" ");
-   return kf;
+    LEAVE (" ");
+    return kf;
 }
 
 /* =========================================================== */
@@ -533,49 +539,50 @@
    p = stpcpy (p, iguid_str);						\
 }
 
-void 
+void
 pgendKVPDelete (PGBackend *be, guint32 iguid)
 {
-   char iguid_str[80], sess_str[80];
-   char * p;
+    char iguid_str[80], sess_str[80];
+    char * p;
 
-   if (!be || 0 == iguid)
-     return;
+    if (!be || 0 == iguid)
+        return;
 
-   sprintf (iguid_str, "%d;\n", iguid);
-   guid_to_string_buff (be->sessionGuid, sess_str);
+    sprintf (iguid_str, "%d;\n", iguid);
+    guid_to_string_buff (be->sessionGuid, sess_str);
 
-   /* first, copy values to the audit tables */
-   p = be->buff; *p = 0;
-   CPY_KVP("");
-   CPY_KVP("_dbl");
-   CPY_KVP("_guid");
-   CPY_KVP("_timespec");
-   CPY_KVP("_int64");
-   CPY_KVP("_list");
-   CPY_KVP("_numeric");
-   CPY_KVP("_str");
+    /* first, copy values to the audit tables */
+    p = be->buff;
+    *p = 0;
+    CPY_KVP("");
+    CPY_KVP("_dbl");
+    CPY_KVP("_guid");
+    CPY_KVP("_timespec");
+    CPY_KVP("_int64");
+    CPY_KVP("_list");
+    CPY_KVP("_numeric");
+    CPY_KVP("_str");
 
-   /* then delete the values */
-   p = stpcpy (p, "DELETE FROM gncKVPValue WHERE iguid=");
-   p = stpcpy (p, iguid_str);
-   p = stpcpy (p, "DELETE FROM gncKVPValue_dbl WHERE iguid=");
-   p = stpcpy (p, iguid_str);
-   p = stpcpy (p, "DELETE FROM gncKVPValue_guid WHERE iguid=");
-   p = stpcpy (p, iguid_str);
-   p = stpcpy (p, "DELETE FROM gncKVPValue_timespec WHERE iguid=");
-   p = stpcpy (p, iguid_str);
-   p = stpcpy (p, "DELETE FROM gncKVPValue_int64 WHERE iguid=");
-   p = stpcpy (p, iguid_str);
-   p = stpcpy (p, "DELETE FROM gncKVPValue_list WHERE iguid=");
-   p = stpcpy (p, iguid_str);
-   p = stpcpy (p, "DELETE FROM gncKVPValue_numeric WHERE iguid=");
-   p = stpcpy (p, iguid_str);
-   p = stpcpy (p, "DELETE FROM gncKVPValue_str WHERE iguid=");
-   p = stpcpy (p, iguid_str);
+    /* then delete the values */
+    p = stpcpy (p, "DELETE FROM gncKVPValue WHERE iguid=");
+    p = stpcpy (p, iguid_str);
+    p = stpcpy (p, "DELETE FROM gncKVPValue_dbl WHERE iguid=");
+    p = stpcpy (p, iguid_str);
+    p = stpcpy (p, "DELETE FROM gncKVPValue_guid WHERE iguid=");
+    p = stpcpy (p, iguid_str);
+    p = stpcpy (p, "DELETE FROM gncKVPValue_timespec WHERE iguid=");
+    p = stpcpy (p, iguid_str);
+    p = stpcpy (p, "DELETE FROM gncKVPValue_int64 WHERE iguid=");
+    p = stpcpy (p, iguid_str);
+    p = stpcpy (p, "DELETE FROM gncKVPValue_list WHERE iguid=");
+    p = stpcpy (p, iguid_str);
+    p = stpcpy (p, "DELETE FROM gncKVPValue_numeric WHERE iguid=");
+    p = stpcpy (p, iguid_str);
+    p = stpcpy (p, "DELETE FROM gncKVPValue_str WHERE iguid=");
+    p = stpcpy (p, iguid_str);
 
-   SEND_QUERY (be,be->buff, );
-   FINISH_QUERY(be->connection);
+    SEND_QUERY (be, be->buff, );
+    FINISH_QUERY(be->connection);
 }
 
 /* =========================== END OF FILE ===================== */

Modified: gnucash/trunk/src/backend/postgres/kvp-sql.h
===================================================================
--- gnucash/trunk/src/backend/postgres/kvp-sql.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/kvp-sql.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -39,7 +39,7 @@
 
 /*
  * The pgendKVPInit() routine initializes a local cache. This routine
- *    must be called before any db access that might require kvp 
+ *    must be called before any db access that might require kvp
  *    handling (e.g. a fetch of accounts).
  */
 void pgendKVPInit (PGBackend *);
@@ -49,12 +49,12 @@
  *    with the indicated GUID cache index 'iguid'.
  *    (Note that currently it does not delete excess kvp data.
  *    That is, if the database has more kvp data in it than
- *    what was passed to this routine, then it does not delete 
+ *    what was passed to this routine, then it does not delete
  *    the excess. This should be considered to be a bug that needs
  *    fixing.)
  *
  * The pgendKVPDelete() and pgendKVPDeleteStr() routines delete
- *    all kvp data in the database associated with the indicated 
+ *    all kvp data in the database associated with the indicated
  *    GUID cache index 'iguid'.
  *
  * The pgendKVPFetch() routine pulls kvp data out of the database.

Modified: gnucash/trunk/src/backend/postgres/newtables.h
===================================================================
--- gnucash/trunk/src/backend/postgres/newtables.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/newtables.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -2,7 +2,7 @@
 #define __GNC_NEWTABLES_H__
 
 /*
- 
+
 -- Drop indexes on the tables
 -- Drop functions on the tables
 -- Alter tables to rename them
@@ -18,244 +18,244 @@
 */
 
 const char *lock_entry =
-"LOCK TABLE gncEntry IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncEntryTrail IN ACCESS EXCLUSIVE MODE;\n"
-;
+    "LOCK TABLE gncEntry IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncEntryTrail IN ACCESS EXCLUSIVE MODE;\n"
+    ;
 
 const char *lock_split =
-"LOCK TABLE gncSplit IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncSplitTrail IN ACCESS EXCLUSIVE MODE;\n"
-;
+    "LOCK TABLE gncSplit IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncSplitTrail IN ACCESS EXCLUSIVE MODE;\n"
+    ;
 
-const char *lock_tables = 
-"LOCK TABLE gncVersion IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncTransaction IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncCheckpoint IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncPrice IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncSession IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncKVPvalue_timespec IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncAccountTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncBookTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncCommodityTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncKVPvalueTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncKVPvalue_int64Trail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncKVPvalue_dblTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncKVPvalue_numericTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncKVPvalue_strTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncKVPvalue_guidTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncKVPvalue_listTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncPriceTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncTransactionTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncKVPvalue_timespecTrail IN ACCESS EXCLUSIVE MODE;\n"
-"LOCK TABLE gncAuditTrail IN ACCESS EXCLUSIVE MODE;\n"
-;
+const char *lock_tables =
+    "LOCK TABLE gncVersion IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncTransaction IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncCheckpoint IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncPrice IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncSession IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncKVPvalue_timespec IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncAccountTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncBookTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncCommodityTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncKVPvalueTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncKVPvalue_int64Trail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncKVPvalue_dblTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncKVPvalue_numericTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncKVPvalue_strTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncKVPvalue_guidTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncKVPvalue_listTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncPriceTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncTransactionTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncKVPvalue_timespecTrail IN ACCESS EXCLUSIVE MODE;\n"
+    "LOCK TABLE gncAuditTrail IN ACCESS EXCLUSIVE MODE;\n"
+    ;
 
 const char *drop_index =
-"ALTER TABLE gncVersion DROP CONSTRAINT gncversion_name_key;\n"
-"ALTER TABLE gncTransaction DROP CONSTRAINT gnctransaction_pkey;\n"
-"ALTER TABLE gncEntry DROP CONSTRAINT gncEntry_pkey;\n"
-"ALTER TABLE gncCheckpoint DROP CONSTRAINT gncCheckpoint_pkey;\n"
-"ALTER TABLE gncPrice DROP CONSTRAINT gncPrice_pkey;\n"
-"ALTER TABLE gncSession DROP CONSTRAINT gncSession_pkey;\n"
-"DROP INDEX gncTransaction_posted_idx;\n"
-"DROP INDEX gncEntry_trn_idx;\n"
-"DROP INDEX gncAccountTrail_account_idx;\n"
-"DROP INDEX gncBookTrail_book_idx;\n"
-"DROP INDEX gncCommodityTrail_commodity_idx;\n"
-"DROP INDEX gncEntryTrail_entry_idx;\n"
-"DROP INDEX gncPriceTrail_price_idx;\n"
-"DROP INDEX gncTransactionTrail_trans_idx;\n"
-;
+    "ALTER TABLE gncVersion DROP CONSTRAINT gncversion_name_key;\n"
+    "ALTER TABLE gncTransaction DROP CONSTRAINT gnctransaction_pkey;\n"
+    "ALTER TABLE gncEntry DROP CONSTRAINT gncEntry_pkey;\n"
+    "ALTER TABLE gncCheckpoint DROP CONSTRAINT gncCheckpoint_pkey;\n"
+    "ALTER TABLE gncPrice DROP CONSTRAINT gncPrice_pkey;\n"
+    "ALTER TABLE gncSession DROP CONSTRAINT gncSession_pkey;\n"
+    "DROP INDEX gncTransaction_posted_idx;\n"
+    "DROP INDEX gncEntry_trn_idx;\n"
+    "DROP INDEX gncAccountTrail_account_idx;\n"
+    "DROP INDEX gncBookTrail_book_idx;\n"
+    "DROP INDEX gncCommodityTrail_commodity_idx;\n"
+    "DROP INDEX gncEntryTrail_entry_idx;\n"
+    "DROP INDEX gncPriceTrail_price_idx;\n"
+    "DROP INDEX gncTransactionTrail_trans_idx;\n"
+    ;
 
-const char *drop_functions = 
-"DROP FUNCTION gncHelperPrVal(gncEntry);\n"
-"DROP FUNCTION gncHelperPrAmt(gncEntry);\n"
-"DROP FUNCTION gncSubtotalBalance(CHAR(32), TIMESTAMP, TIMESTAMP);\n"
-"DROP FUNCTION gncSubtotalClearedBalance (CHAR(32), TIMESTAMP, TIMESTAMP);\n"
-"DROP FUNCTION gncSubtotalReconedBalance(CHAR(32), TIMESTAMP, TIMESTAMP);\n"
-;
+const char *drop_functions =
+    "DROP FUNCTION gncHelperPrVal(gncEntry);\n"
+    "DROP FUNCTION gncHelperPrAmt(gncEntry);\n"
+    "DROP FUNCTION gncSubtotalBalance(CHAR(32), TIMESTAMP, TIMESTAMP);\n"
+    "DROP FUNCTION gncSubtotalClearedBalance (CHAR(32), TIMESTAMP, TIMESTAMP);\n"
+    "DROP FUNCTION gncSubtotalReconedBalance(CHAR(32), TIMESTAMP, TIMESTAMP);\n"
+    ;
 
 const char *alter_tables =
-"ALTER TABLE gncVersion RENAME TO gncVersion_old;\n"
-"ALTER TABLE gncTransaction RENAME TO gncTransaction_old;\n"
-"ALTER TABLE gncEntry RENAME TO gncEntry_old;\n"
-"ALTER TABLE gncCheckpoint RENAME TO gncCheckpoint_old;\n"
-"ALTER TABLE gncPrice RENAME TO gncPrice_old;\n"
-"ALTER TABLE gncSession RENAME TO gncSession_old;\n"
-"ALTER TABLE gncKVPvalue_timespec RENAME TO gncKVPvalue_timespec_old;\n"
-"ALTER TABLE gncAuditTrail RENAME to gncAuditTrail_old;\n"
-"ALTER TABLE gncAccountTrail RENAME to gncAccountTrail_old;\n"
-"ALTER TABLE gncBookTrail RENAME to gncBookTrail_old;\n"
-"ALTER TABLE gncCommodityTrail RENAME to gncCommodityTrail_old;\n"
-"ALTER TABLE gncKVPvalueTrail RENAME to gncKVPvalueTrail_old;\n"
-"ALTER TABLE gncKVPvalue_int64Trail RENAME TO gncKVPvalue_int64Trail_old;\n"
-"ALTER TABLE gncKVPvalue_dblTrail RENAME TO gncKVPvalue_dblTrail_old;\n"
-"ALTER TABLE gncKVPvalue_numericTrail RENAME TO gncKVPvalue_numericTrail_old;\n"
-"ALTER TABLE gncKVPvalue_strTrail RENAME TO gncKVPvalue_strTrail_old;\n"
-"ALTER TABLE gncKVPvalue_guidTrail RENAME TO gncKVPvalue_guidTrail_old;\n"
-"ALTER TABLE gncKVPvalue_listTrail RENAME TO gncKVPvalue_listTrail_old;\n"
-"ALTER TABLE gncEntryTrail RENAME to gncEntryTrail_old;\n"
-"ALTER TABLE gncPriceTrail RENAME to gncPriceTrail_old;\n"
-"ALTER TABLE gncTransactionTrail RENAME to gncTransactionTrail_old;\n"
-"ALTER TABLE gncKVPvalue_timespecTrail RENAME to gncKVPvalue_timespecTrail_old;\n"
-;
+    "ALTER TABLE gncVersion RENAME TO gncVersion_old;\n"
+    "ALTER TABLE gncTransaction RENAME TO gncTransaction_old;\n"
+    "ALTER TABLE gncEntry RENAME TO gncEntry_old;\n"
+    "ALTER TABLE gncCheckpoint RENAME TO gncCheckpoint_old;\n"
+    "ALTER TABLE gncPrice RENAME TO gncPrice_old;\n"
+    "ALTER TABLE gncSession RENAME TO gncSession_old;\n"
+    "ALTER TABLE gncKVPvalue_timespec RENAME TO gncKVPvalue_timespec_old;\n"
+    "ALTER TABLE gncAuditTrail RENAME to gncAuditTrail_old;\n"
+    "ALTER TABLE gncAccountTrail RENAME to gncAccountTrail_old;\n"
+    "ALTER TABLE gncBookTrail RENAME to gncBookTrail_old;\n"
+    "ALTER TABLE gncCommodityTrail RENAME to gncCommodityTrail_old;\n"
+    "ALTER TABLE gncKVPvalueTrail RENAME to gncKVPvalueTrail_old;\n"
+    "ALTER TABLE gncKVPvalue_int64Trail RENAME TO gncKVPvalue_int64Trail_old;\n"
+    "ALTER TABLE gncKVPvalue_dblTrail RENAME TO gncKVPvalue_dblTrail_old;\n"
+    "ALTER TABLE gncKVPvalue_numericTrail RENAME TO gncKVPvalue_numericTrail_old;\n"
+    "ALTER TABLE gncKVPvalue_strTrail RENAME TO gncKVPvalue_strTrail_old;\n"
+    "ALTER TABLE gncKVPvalue_guidTrail RENAME TO gncKVPvalue_guidTrail_old;\n"
+    "ALTER TABLE gncKVPvalue_listTrail RENAME TO gncKVPvalue_listTrail_old;\n"
+    "ALTER TABLE gncEntryTrail RENAME to gncEntryTrail_old;\n"
+    "ALTER TABLE gncPriceTrail RENAME to gncPriceTrail_old;\n"
+    "ALTER TABLE gncTransactionTrail RENAME to gncTransactionTrail_old;\n"
+    "ALTER TABLE gncKVPvalue_timespecTrail RENAME to gncKVPvalue_timespecTrail_old;\n"
+    ;
 
 const char *create_new_tables =
-"CREATE TABLE gncVersion ( \n"
-"	major	INT NOT NULL, \n"
-"	minor	INT NOT NULL, \n"
-"	rev	    INT DEFAULT '0', \n"
-"	name	TEXT UNIQUE NOT NULL CHECK (name <> ''), \n"
-"	date	TIMESTAMP WITH TIME ZONE DEFAULT 'NOW' \n"
-"); \n"
-"--\n"
-"CREATE TABLE gncTransaction ( \n"
-"	transGuid	CHAR(32) PRIMARY KEY, \n"
-"	last_modified 	TIMESTAMP WITH TIME ZONE DEFAULT 'NOW', \n"
-"	date_entered 	TIMESTAMP WITH TIME ZONE, \n"
-"	date_posted 	TIMESTAMP WITH TIME ZONE, \n"
-"	num             TEXT, \n"
-"	description	    TEXT, \n"
-"   currency	    TEXT NOT NULL CHECK (currency <> ''), \n"
-"	version		    INT4 NOT NULL, \n"
-"	iguid		    INT4 DEFAULT 0 \n"
-"); \n"
-"-- \n"
-"CREATE TABLE gncSplit ( \n"
-"	splitGuid		CHAR(32) PRIMARY KEY, \n"
-"	accountGuid		CHAR(32) NOT NULL, \n"
-"	transGuid		CHAR(32) NOT NULL, \n"
-"	memo			TEXT, \n"
-"	action			TEXT, \n"
-"	reconciled		CHAR DEFAULT 'n', \n"
-"	date_reconciled TIMESTAMP WITH TIME ZONE, \n"
-"	amount			INT8 DEFAULT '0', \n"
-"	value			INT8 DEFAULT '0', \n"
-"	iguid			INT4 DEFAULT 0 \n"
-"); \n"
-"-- \n"
-"CREATE TABLE gncCheckpoint ( \n"
-"   accountGuid         CHAR(32) NOT NULL, \n"
-"	date_start	 	    TIMESTAMP WITH TIME ZONE NOT NULL, \n"
-" 	date_end	 	    TIMESTAMP WITH TIME ZONE NOT NULL, \n"
-"	commodity		    TEXT NOT NULL CHECK (commodity <>''), \n"
-"	type			    TEXT DEFAULT 'simple', \n"
-"	balance			    INT8 DEFAULT '0', \n"
-"	cleared_balance		INT8 DEFAULT '0', \n"
-"	reconciled_balance	INT8 DEFAULT '0', \n"
-"   PRIMARY KEY (accountGuid, date_start, commodity) \n"
-"); \n"
-"-- \n"
-"CREATE TABLE gncPrice ( \n"
-"	priceGuid	CHAR(32) PRIMARY KEY, \n"
-"	bookGuid	CHAR(32) NOT NULL, \n"
-"	commodity	TEXT NOT NULL CHECK (commodity <>''), \n"
-"	currency	TEXT NOT NULL CHECK (commodity <>''), \n"
-"	time		TIMESTAMP WITH TIME ZONE, \n"
-"	source		TEXT, \n"
-"	type		TEXT, \n"
-"	valueNum	INT8 DEFAULT '0', \n"
-"	valueDenom	INT4 DEFAULT '100', \n"
-"	version		INT4 NOT NULL \n"
-"); \n"
-"-- \n"
-"CREATE TABLE gncSession ( \n"
-"	sessionGuid		CHAR(32) PRIMARY KEY, \n"
-"	session_mode	CHAR(16) NOT NULL, \n"
-"	hostname		TEXT, \n"
-"	login_name		TEXT, \n"
-"	gecos			TEXT, \n"
-"	time_on			TIMESTAMP WITH TIME ZONE NOT NULL, \n"
-"	time_off		TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'INFINITY' \n"
-"); \n"
-"--\n"
-"CREATE TABLE gncKVPvalue_timespec ( \n"
-"	data		TIMESTAMP WITH TIME ZONE \n"
-") INHERITS (gncKVPvalue); \n"
-"--\n"
-;
+    "CREATE TABLE gncVersion ( \n"
+    "	major	INT NOT NULL, \n"
+    "	minor	INT NOT NULL, \n"
+    "	rev	    INT DEFAULT '0', \n"
+    "	name	TEXT UNIQUE NOT NULL CHECK (name <> ''), \n"
+    "	date	TIMESTAMP WITH TIME ZONE DEFAULT 'NOW' \n"
+    "); \n"
+    "--\n"
+    "CREATE TABLE gncTransaction ( \n"
+    "	transGuid	CHAR(32) PRIMARY KEY, \n"
+    "	last_modified 	TIMESTAMP WITH TIME ZONE DEFAULT 'NOW', \n"
+    "	date_entered 	TIMESTAMP WITH TIME ZONE, \n"
+    "	date_posted 	TIMESTAMP WITH TIME ZONE, \n"
+    "	num             TEXT, \n"
+    "	description	    TEXT, \n"
+    "   currency	    TEXT NOT NULL CHECK (currency <> ''), \n"
+    "	version		    INT4 NOT NULL, \n"
+    "	iguid		    INT4 DEFAULT 0 \n"
+    "); \n"
+    "-- \n"
+    "CREATE TABLE gncSplit ( \n"
+    "	splitGuid		CHAR(32) PRIMARY KEY, \n"
+    "	accountGuid		CHAR(32) NOT NULL, \n"
+    "	transGuid		CHAR(32) NOT NULL, \n"
+    "	memo			TEXT, \n"
+    "	action			TEXT, \n"
+    "	reconciled		CHAR DEFAULT 'n', \n"
+    "	date_reconciled TIMESTAMP WITH TIME ZONE, \n"
+    "	amount			INT8 DEFAULT '0', \n"
+    "	value			INT8 DEFAULT '0', \n"
+    "	iguid			INT4 DEFAULT 0 \n"
+    "); \n"
+    "-- \n"
+    "CREATE TABLE gncCheckpoint ( \n"
+    "   accountGuid         CHAR(32) NOT NULL, \n"
+    "	date_start	 	    TIMESTAMP WITH TIME ZONE NOT NULL, \n"
+    " 	date_end	 	    TIMESTAMP WITH TIME ZONE NOT NULL, \n"
+    "	commodity		    TEXT NOT NULL CHECK (commodity <>''), \n"
+    "	type			    TEXT DEFAULT 'simple', \n"
+    "	balance			    INT8 DEFAULT '0', \n"
+    "	cleared_balance		INT8 DEFAULT '0', \n"
+    "	reconciled_balance	INT8 DEFAULT '0', \n"
+    "   PRIMARY KEY (accountGuid, date_start, commodity) \n"
+    "); \n"
+    "-- \n"
+    "CREATE TABLE gncPrice ( \n"
+    "	priceGuid	CHAR(32) PRIMARY KEY, \n"
+    "	bookGuid	CHAR(32) NOT NULL, \n"
+    "	commodity	TEXT NOT NULL CHECK (commodity <>''), \n"
+    "	currency	TEXT NOT NULL CHECK (commodity <>''), \n"
+    "	time		TIMESTAMP WITH TIME ZONE, \n"
+    "	source		TEXT, \n"
+    "	type		TEXT, \n"
+    "	valueNum	INT8 DEFAULT '0', \n"
+    "	valueDenom	INT4 DEFAULT '100', \n"
+    "	version		INT4 NOT NULL \n"
+    "); \n"
+    "-- \n"
+    "CREATE TABLE gncSession ( \n"
+    "	sessionGuid		CHAR(32) PRIMARY KEY, \n"
+    "	session_mode	CHAR(16) NOT NULL, \n"
+    "	hostname		TEXT, \n"
+    "	login_name		TEXT, \n"
+    "	gecos			TEXT, \n"
+    "	time_on			TIMESTAMP WITH TIME ZONE NOT NULL, \n"
+    "	time_off		TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'INFINITY' \n"
+    "); \n"
+    "--\n"
+    "CREATE TABLE gncKVPvalue_timespec ( \n"
+    "	data		TIMESTAMP WITH TIME ZONE \n"
+    ") INHERITS (gncKVPvalue); \n"
+    "--\n"
+    ;
 
 const char *create_audits =
 #include "table-audit.c"
-;
+    ;
 
 const char *create_indexes =
-"CREATE INDEX gncTransaction_posted_idx ON gncTransaction (date_posted); \n"
-"CREATE INDEX gncSplit_acc_idx ON gncSplit (accountGuid); \n"
-"CREATE INDEX gncSplit_trn_idx ON gncSplit (transGuid); \n"
-"--\n"
-;
+    "CREATE INDEX gncTransaction_posted_idx ON gncTransaction (date_posted); \n"
+    "CREATE INDEX gncSplit_acc_idx ON gncSplit (accountGuid); \n"
+    "CREATE INDEX gncSplit_trn_idx ON gncSplit (transGuid); \n"
+    "--\n"
+    ;
 
-const char *create_functions = 
+const char *create_functions =
 #include "functions.c"
-;
+    ;
 
-const char *insert_new_data = 
-"INSERT INTO gncVersion (major,	minor, rev, name, date) SELECT major, minor, rev, name, date from gncVersion_old; \n"
-"INSERT INTO gncTransaction (transGuid,last_modified,date_entered,date_posted,num,description,currency,version,iguid) "
-" SELECT transGuid,last_modified,date_entered,date_posted,num,description,currency,version,iguid FROM gncTransaction_old; \n"
-"INSERT INTO gncSplit (splitGuid,accountGuid,transGuid,memo,action,reconciled,date_reconciled,amount,value,iguid) "
-" SELECT entryGuid,accountGuid,transGuid,memo,action,reconciled,date_reconciled,amount,value,iguid from gncEntry_old;\n"
-"INSERT INTO gncCheckpoint (accountGuid,date_start,date_end,commodity,type,balance,cleared_balance,reconciled_balance) "
-" SELECT accountGuid,date_start,date_end,commodity,type,balance,cleared_balance,reconciled_balance FROM gncCheckpoint_old;\n"
-"INSERT INTO gncPrice (priceGuid,commodity,currency,time,source,type,valueNum,valueDenom,version,bookGuid) "
-" SELECT priceGuid,commodity,currency,time,source,type,valueNum,valueDenom,version,bookGuid FROM gncPrice_old;\n"
-"INSERT INTO gncSession (sessionGuid,session_mode,hostname,login_name,gecos,time_on,time_off) "
-" SELECT sessionGuid,session_mode,hostname,login_name,gecos,time_on,time_off FROM gncSession_old;\n"
-"INSERT INTO gncKVPvalue_timespec (data) SELECT data FROM gncKVPvalue_timespec_old;\n"
-"--\n"
-"--INSERT INTO gncAuditTrail (sessionGuid,date_changed,change,objtype) "
-"-- SELECT sessionGuid,date_changed,change,objtype FROM gncAuditTrail_old;\n"
-"INSERT INTO gncAccountTrail (sessionGuid,date_changed,change,objtype,accountGuid,parentGuid,bookGuid,accountName,accountCode,description,type,commodity,version,iguid) "
-" SELECT sessionGuid,date_changed,change,objtype,accountGuid,parentGuid,bookGuid,accountName,accountCode,description,type,commodity,version,iguid FROM gncAccountTrail_old;\n"
-"INSERT INTO gncBookTrail (sessionGuid,date_changed,change,objtype,bookGuid,book_open,version,iguid) "
-" SELECT sessionGuid,date_changed,change,objtype,bookGuid,book_open,version,iguid FROM gncBookTrail_old;\n"
-"INSERT INTO gncCommodityTrail (sessionGuid,date_changed,change,objtype,commodity,fullname,namespace,mnemonic,code,fraction) "
-" SELECT sessionGuid,date_changed,change,objtype,commodity,fullname,namespace,mnemonic,code,fraction FROM gncCommodityTrail_old;\n"
-"INSERT INTO gncSplitTrail (sessionGuid,date_changed,change,objtype,splitGuid,accountGuid,transGuid,memo,action,reconciled,date_reconciled,amount,value,iguid) "
-" SELECT sessionGuid,date_changed,change,objtype,entryGuid,accountGuid,transGuid,memo,action,reconciled,date_reconciled,amount,value,iguid from gncEntryTrail_old;\n"
-"INSERT INTO gncPriceTrail (sessionGuid,date_changed,change,objtype,priceGuid,commodity,currency,time,source,type,valueNum,valueDenom,version,bookGuid) "
-" SELECT sessionGuid,date_changed,change,objtype,priceGuid,commodity,currency,time,source,type,valueNum,valueDenom,version,bookGuid FROM gncPriceTrail_old;\n"
-"INSERT INTO gncTransactionTrail (sessionGuid,date_changed,change,objtype,transGuid,last_modified,date_entered,date_posted,num,description,currency,version,iguid) "
-" SELECT sessionGuid,date_changed,change,objtype,transGuid,last_modified,date_entered,date_posted,num,description,currency,version,iguid from gncTransactionTrail_old;\n"
-"INSERT INTO gncKVPvalueTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type FROM gncKvpValueTrail_old;\n"
-"INSERT INTO gncKVPvalue_int64Trail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_int64trail_old;\n"
-"INSERT INTO gncKVPvalue_dblTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_dbltrail_old;\n"
-"INSERT INTO gncKVPvalue_numericTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,num,denom) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,num,denom FROM gncKVPvalue_numericTrail_old;\n"
-"INSERT INTO gncKVPvalue_strTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_strtrail_old;\n"
-"INSERT INTO gncKVPvalue_guidTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_guidtrail_old;\n"
-"INSERT INTO gncKVPvalue_timespecTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_timespectrail_old;\n"
-"INSERT INTO gncKVPvalue_listTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_listtrail_old;\n"
-;
+const char *insert_new_data =
+    "INSERT INTO gncVersion (major,	minor, rev, name, date) SELECT major, minor, rev, name, date from gncVersion_old; \n"
+    "INSERT INTO gncTransaction (transGuid,last_modified,date_entered,date_posted,num,description,currency,version,iguid) "
+    " SELECT transGuid,last_modified,date_entered,date_posted,num,description,currency,version,iguid FROM gncTransaction_old; \n"
+    "INSERT INTO gncSplit (splitGuid,accountGuid,transGuid,memo,action,reconciled,date_reconciled,amount,value,iguid) "
+    " SELECT entryGuid,accountGuid,transGuid,memo,action,reconciled,date_reconciled,amount,value,iguid from gncEntry_old;\n"
+    "INSERT INTO gncCheckpoint (accountGuid,date_start,date_end,commodity,type,balance,cleared_balance,reconciled_balance) "
+    " SELECT accountGuid,date_start,date_end,commodity,type,balance,cleared_balance,reconciled_balance FROM gncCheckpoint_old;\n"
+    "INSERT INTO gncPrice (priceGuid,commodity,currency,time,source,type,valueNum,valueDenom,version,bookGuid) "
+    " SELECT priceGuid,commodity,currency,time,source,type,valueNum,valueDenom,version,bookGuid FROM gncPrice_old;\n"
+    "INSERT INTO gncSession (sessionGuid,session_mode,hostname,login_name,gecos,time_on,time_off) "
+    " SELECT sessionGuid,session_mode,hostname,login_name,gecos,time_on,time_off FROM gncSession_old;\n"
+    "INSERT INTO gncKVPvalue_timespec (data) SELECT data FROM gncKVPvalue_timespec_old;\n"
+    "--\n"
+    "--INSERT INTO gncAuditTrail (sessionGuid,date_changed,change,objtype) "
+    "-- SELECT sessionGuid,date_changed,change,objtype FROM gncAuditTrail_old;\n"
+    "INSERT INTO gncAccountTrail (sessionGuid,date_changed,change,objtype,accountGuid,parentGuid,bookGuid,accountName,accountCode,description,type,commodity,version,iguid) "
+    " SELECT sessionGuid,date_changed,change,objtype,accountGuid,parentGuid,bookGuid,accountName,accountCode,description,type,commodity,version,iguid FROM gncAccountTrail_old;\n"
+    "INSERT INTO gncBookTrail (sessionGuid,date_changed,change,objtype,bookGuid,book_open,version,iguid) "
+    " SELECT sessionGuid,date_changed,change,objtype,bookGuid,book_open,version,iguid FROM gncBookTrail_old;\n"
+    "INSERT INTO gncCommodityTrail (sessionGuid,date_changed,change,objtype,commodity,fullname,namespace,mnemonic,code,fraction) "
+    " SELECT sessionGuid,date_changed,change,objtype,commodity,fullname,namespace,mnemonic,code,fraction FROM gncCommodityTrail_old;\n"
+    "INSERT INTO gncSplitTrail (sessionGuid,date_changed,change,objtype,splitGuid,accountGuid,transGuid,memo,action,reconciled,date_reconciled,amount,value,iguid) "
+    " SELECT sessionGuid,date_changed,change,objtype,entryGuid,accountGuid,transGuid,memo,action,reconciled,date_reconciled,amount,value,iguid from gncEntryTrail_old;\n"
+    "INSERT INTO gncPriceTrail (sessionGuid,date_changed,change,objtype,priceGuid,commodity,currency,time,source,type,valueNum,valueDenom,version,bookGuid) "
+    " SELECT sessionGuid,date_changed,change,objtype,priceGuid,commodity,currency,time,source,type,valueNum,valueDenom,version,bookGuid FROM gncPriceTrail_old;\n"
+    "INSERT INTO gncTransactionTrail (sessionGuid,date_changed,change,objtype,transGuid,last_modified,date_entered,date_posted,num,description,currency,version,iguid) "
+    " SELECT sessionGuid,date_changed,change,objtype,transGuid,last_modified,date_entered,date_posted,num,description,currency,version,iguid from gncTransactionTrail_old;\n"
+    "INSERT INTO gncKVPvalueTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type FROM gncKvpValueTrail_old;\n"
+    "INSERT INTO gncKVPvalue_int64Trail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_int64trail_old;\n"
+    "INSERT INTO gncKVPvalue_dblTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_dbltrail_old;\n"
+    "INSERT INTO gncKVPvalue_numericTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,num,denom) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,num,denom FROM gncKVPvalue_numericTrail_old;\n"
+    "INSERT INTO gncKVPvalue_strTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_strtrail_old;\n"
+    "INSERT INTO gncKVPvalue_guidTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_guidtrail_old;\n"
+    "INSERT INTO gncKVPvalue_timespecTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_timespectrail_old;\n"
+    "INSERT INTO gncKVPvalue_listTrail (sessionGuid,date_changed,change,objtype,iguid,ipath,type,data) SELECT sessionGuid,date_changed,change,objtype,iguid,ipath,type,data FROM gncKVPvalue_listtrail_old;\n"
+    ;
 
-const char *drop_old_tables = 
-"DROP TABLE gncVersion_old;\n"
-"DROP TABLE gncTransaction_old;\n"
-"DROP TABLE gncEntry_old;\n"
-"DROP TABLE gncCheckpoint_old;\n"
-"DROP TABLE gncPrice_old;\n"
-"DROP TABLE gncSession_old;\n"
-"DROP TABLE gncKVPvalue_timespec_old;\n"
-"DROP TABLE gncAccountTrail_old;\n"
-"DROP TABLE gncBookTrail_old;\n"
-"DROP TABLE gncCommodityTrail_old;\n"
-"DROP TABLE gncKVPvalueTrail_old;\n"
-"DROP TABLE gncKVPvalue_int64Trail_old;\n"
-"DROP TABLE gncKVPvalue_dblTrail_old;\n"
-"DROP TABLE gncKVPvalue_numericTrail_old;\n"
-"DROP TABLE gncKVPvalue_strTrail_old;\n"
-"DROP TABLE gncKVPvalue_guidTrail_old;\n"
-"DROP TABLE gncKVPvalue_listTrail_old;\n"
-"DROP TABLE gncEntryTrail_old;\n"
-"DROP TABLE gncPriceTrail_old;\n"
-"DROP TABLE gncTransactionTrail_old;\n"
-"DROP TABLE gncKVPvalue_timespecTrail_old;\n"
-"DROP TABLE gncAuditTrail_old;\n"
-;
+const char *drop_old_tables =
+    "DROP TABLE gncVersion_old;\n"
+    "DROP TABLE gncTransaction_old;\n"
+    "DROP TABLE gncEntry_old;\n"
+    "DROP TABLE gncCheckpoint_old;\n"
+    "DROP TABLE gncPrice_old;\n"
+    "DROP TABLE gncSession_old;\n"
+    "DROP TABLE gncKVPvalue_timespec_old;\n"
+    "DROP TABLE gncAccountTrail_old;\n"
+    "DROP TABLE gncBookTrail_old;\n"
+    "DROP TABLE gncCommodityTrail_old;\n"
+    "DROP TABLE gncKVPvalueTrail_old;\n"
+    "DROP TABLE gncKVPvalue_int64Trail_old;\n"
+    "DROP TABLE gncKVPvalue_dblTrail_old;\n"
+    "DROP TABLE gncKVPvalue_numericTrail_old;\n"
+    "DROP TABLE gncKVPvalue_strTrail_old;\n"
+    "DROP TABLE gncKVPvalue_guidTrail_old;\n"
+    "DROP TABLE gncKVPvalue_listTrail_old;\n"
+    "DROP TABLE gncEntryTrail_old;\n"
+    "DROP TABLE gncPriceTrail_old;\n"
+    "DROP TABLE gncTransactionTrail_old;\n"
+    "DROP TABLE gncKVPvalue_timespecTrail_old;\n"
+    "DROP TABLE gncAuditTrail_old;\n"
+    ;
 
 const char *version_sql =
-"INSERT INTO gncVersion (major, minor, rev, name, date) "
-"VALUES (1, 5, 1, 'Change timestamp definition', now());\n"
-;
+    "INSERT INTO gncVersion (major, minor, rev, name, date) "
+    "VALUES (1, 5, 1, 'Change timestamp definition', now());\n"
+    ;
 
 #endif

Modified: gnucash/trunk/src/backend/postgres/price.c
===================================================================
--- gnucash/trunk/src/backend/postgres/price.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/price.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -25,7 +25,7 @@
 #include <glib.h>
 #include <stdlib.h>
 #include <string.h>
-#include <libpq-fe.h>  
+#include <libpq-fe.h>
 
 #include "qof.h"
 #include "gnc-commodity.h"
@@ -53,77 +53,77 @@
 static gpointer
 get_commodities_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   GList *node;
+    GList *node;
 
-   /* stick the commodity in every book ... */
-   for (node=be->blist; node; node=node->next)
-   {
-      gnc_commodity *com;
-      QofBook *book = node->data;
-      gnc_commodity_table *comtab = gnc_book_get_commodity_table (book);
-   
-      if (!comtab) continue;
+    /* stick the commodity in every book ... */
+    for (node = be->blist; node; node = node->next)
+    {
+        gnc_commodity *com;
+        QofBook *book = node->data;
+        gnc_commodity_table *comtab = gnc_book_get_commodity_table (book);
 
-      /* first, lets see if we've already got this one */
-      com = gnc_commodity_table_lookup(comtab,
-                                       DB_GET_VAL("namespace",j),
-                                       DB_GET_VAL("mnemonic",j));
-   
-      if (com) continue;
-   
-      /* no we don't ... restore it */
-      com = gnc_commodity_new (book,
-			       DB_GET_VAL("fullname",j),
-                               DB_GET_VAL("namespace",j),
-                               DB_GET_VAL("mnemonic",j),
-                               DB_GET_VAL("code",j),
-                               atoi(DB_GET_VAL("fraction",j)));
-   
-      gnc_commodity_table_insert (comtab, com);
-   }
-   return NULL;
+        if (!comtab) continue;
+
+        /* first, lets see if we've already got this one */
+        com = gnc_commodity_table_lookup(comtab,
+                                         DB_GET_VAL("namespace", j),
+                                         DB_GET_VAL("mnemonic", j));
+
+        if (com) continue;
+
+        /* no we don't ... restore it */
+        com = gnc_commodity_new (book,
+                                 DB_GET_VAL("fullname", j),
+                                 DB_GET_VAL("namespace", j),
+                                 DB_GET_VAL("mnemonic", j),
+                                 DB_GET_VAL("code", j),
+                                 atoi(DB_GET_VAL("fraction", j)));
+
+        gnc_commodity_table_insert (comtab, com);
+    }
+    return NULL;
 }
 
 void
 pgendGetAllCommodities (PGBackend *be)
 {
-   char * p;
-   if (!be) return;
+    char * p;
+    if (!be) return;
 
-   ENTER ("be=%p, conn=%p", be, be->connection);
+    ENTER ("be=%p, conn=%p", be, be->connection);
 
-   /* Get them ALL */
-   p = "SELECT * FROM gncCommodity;";
-   SEND_QUERY (be, p, );
-   pgendGetResults (be, get_commodities_cb, NULL);
+    /* Get them ALL */
+    p = "SELECT * FROM gncCommodity;";
+    SEND_QUERY (be, p, );
+    pgendGetResults (be, get_commodities_cb, NULL);
 
-   LEAVE (" ");
+    LEAVE (" ");
 }
 
 void
 pgendGetCommodity (PGBackend *be, const char * unique_name)
 {
-   sqlEscape *escape;
-   char *p;
+    sqlEscape *escape;
+    char *p;
 
-   if (!be || !unique_name) return;
+    if (!be || !unique_name) return;
 
-   ENTER ("be=%p, conn=%p", be, be->connection);
+    ENTER ("be=%p, conn=%p", be, be->connection);
 
-   escape = sqlEscape_new ();
+    escape = sqlEscape_new ();
 
-   /* Get them ALL */
-   p = be->buff;
-   p = stpcpy (p, "SELECT * FROM gncCommodity WHERE gncCommodity.commodity='");
-   p = stpcpy (p, sqlEscapeString (escape, unique_name));
-   p = stpcpy (p, "';");
+    /* Get them ALL */
+    p = be->buff;
+    p = stpcpy (p, "SELECT * FROM gncCommodity WHERE gncCommodity.commodity='");
+    p = stpcpy (p, sqlEscapeString (escape, unique_name));
+    p = stpcpy (p, "';");
 
-   SEND_QUERY (be, be->buff, );
-   pgendGetResults (be, get_commodities_cb, NULL);
+    SEND_QUERY (be, be->buff, );
+    pgendGetResults (be, get_commodities_cb, NULL);
 
-   sqlEscape_destroy (escape);
+    sqlEscape_destroy (escape);
 
-   LEAVE (" ");
+    LEAVE (" ");
 }
 
 /* ============================================================= */
@@ -135,115 +135,117 @@
 
 static void
 pgendStorePriceNoLock (PGBackend *be, GNCPrice *pr,
-                        gboolean do_check_version)
+                       gboolean do_check_version)
 {
-   gnc_commodity *modity;
+    gnc_commodity *modity;
 
-   if (do_check_version)
-   {
-     if (0 < pgendPriceCompareVersion (be, pr)) return;
-   }
-   /* be sure to update the version !! */
-   qof_instance_increment_version(pr, be->version_check);
+    if (do_check_version)
+    {
+        if (0 < pgendPriceCompareVersion (be, pr)) return;
+    }
+    /* be sure to update the version !! */
+    qof_instance_increment_version(pr, be->version_check);
 
-   /* make sure that we've stored the commodity 
-    * and currency before we store the price.
-    */
-   modity = gnc_price_get_commodity (pr);
-   pgendPutOneCommodityOnly (be, modity);
+    /* make sure that we've stored the commodity
+     * and currency before we store the price.
+     */
+    modity = gnc_price_get_commodity (pr);
+    pgendPutOneCommodityOnly (be, modity);
 
-   modity = gnc_price_get_currency (pr);
-   pgendPutOneCommodityOnly (be, modity);
+    modity = gnc_price_get_currency (pr);
+    pgendPutOneCommodityOnly (be, modity);
 
-   pgendPutOnePriceOnly (be, pr);
+    pgendPutOnePriceOnly (be, pr);
 }
 
 /* ============================================================= */
 /* store entire price database */
 
-static gboolean 
+static gboolean
 foreach_price_cb (GNCPrice *pr, gpointer bend)
 {
-   PGBackend *be = (PGBackend *) bend;
-   gnc_commodity *modity;
-   gint16 mark;
+    PGBackend *be = (PGBackend *) bend;
+    gnc_commodity *modity;
+    gint16 mark;
 
-   /* make sure that we've stored the commodity 
-    * and currency before we store the price.
-    * We use marks to avoid redundant stores. 
-    */
-   modity = gnc_price_get_commodity (pr);
-   mark = gnc_commodity_get_mark (modity);
-   if (!mark) {
-      pgendPutOneCommodityOnly (be, modity);
-      gnc_commodity_set_mark (modity, 1);
-   }
+    /* make sure that we've stored the commodity
+     * and currency before we store the price.
+     * We use marks to avoid redundant stores.
+     */
+    modity = gnc_price_get_commodity (pr);
+    mark = gnc_commodity_get_mark (modity);
+    if (!mark)
+    {
+        pgendPutOneCommodityOnly (be, modity);
+        gnc_commodity_set_mark (modity, 1);
+    }
 
-   modity = gnc_price_get_currency (pr);
-   mark = gnc_commodity_get_mark (modity);
-   if (!mark) {
-      pgendPutOneCommodityOnly (be, modity);
-      gnc_commodity_set_mark (modity, 1);
-   }
+    modity = gnc_price_get_currency (pr);
+    mark = gnc_commodity_get_mark (modity);
+    if (!mark)
+    {
+        pgendPutOneCommodityOnly (be, modity);
+        gnc_commodity_set_mark (modity, 1);
+    }
 
-   pgendPutOnePriceOnly (be, pr);
+    pgendPutOnePriceOnly (be, pr);
 
-   return TRUE;
+    return TRUE;
 }
 
 static gboolean
 commodity_mark_cb (gnc_commodity *cm, gpointer user_data)
 {
-   gint32 v = ((gint32) GPOINTER_TO_INT(user_data)) & 0xffff;
-   gnc_commodity_set_mark (cm, (gint16) v);
-   return TRUE;
+    gint32 v = ((gint32) GPOINTER_TO_INT(user_data)) & 0xffff;
+    gnc_commodity_set_mark (cm, (gint16) v);
+    return TRUE;
 }
 
 
 void
 pgendStorePriceDBNoLock (PGBackend *be, QofBook *book)
 {
-   GNCPriceDB *prdb;
-   gnc_commodity_table *comtab;
+    GNCPriceDB *prdb;
+    gnc_commodity_table *comtab;
 
-   prdb = gnc_book_get_pricedb(book);
-   comtab = gnc_book_get_commodity_table (book);
+    prdb = gnc_book_get_pricedb(book);
+    comtab = gnc_book_get_commodity_table (book);
 
-   /* Clear the marks on commodities -- we use this to mark 
-    * the thing as 'already stored', avoiding redundant stores */
-   gnc_commodity_table_foreach_commodity (comtab, commodity_mark_cb, 0);
+    /* Clear the marks on commodities -- we use this to mark
+     * the thing as 'already stored', avoiding redundant stores */
+    gnc_commodity_table_foreach_commodity (comtab, commodity_mark_cb, 0);
 
-   gnc_pricedb_foreach_price (prdb, foreach_price_cb,
-                              (gpointer) be, FALSE);
+    gnc_pricedb_foreach_price (prdb, foreach_price_cb,
+                               (gpointer) be, FALSE);
 
-   gnc_commodity_table_foreach_commodity (comtab, commodity_mark_cb, 0);
+    gnc_commodity_table_foreach_commodity (comtab, commodity_mark_cb, 0);
 }
 
 void
 pgendStorePriceDB (PGBackend *be, QofBook *book)
 {
-   char *p;
-   ENTER ("be=%p, book=%p", be, book);
-   if (!be || !book) return;
+    char *p;
+    ENTER ("be=%p, book=%p", be, book);
+    if (!be || !book) return;
 
-   /* Lock it up so that we store atomically */
-   p = "BEGIN;\n"
-       "LOCK TABLE gncPrice IN EXCLUSIVE MODE;\n";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    /* Lock it up so that we store atomically */
+    p = "BEGIN;\n"
+        "LOCK TABLE gncPrice IN EXCLUSIVE MODE;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   pgendStorePriceDBNoLock (be, book);
+    pgendStorePriceDBNoLock (be, book);
 
-   p = "COMMIT;\n"
-       "NOTIFY gncPrice;";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
-   LEAVE(" ");
+    p = "COMMIT;\n"
+        "NOTIFY gncPrice;";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+    LEAVE(" ");
 }
 
 /* ============================================================= */
-/* The pgendGetAllPrices() routine sucks *all* of the 
- *    prices out of the database.  This is a potential 
+/* The pgendGetAllPrices() routine sucks *all* of the
+ *    prices out of the database.  This is a potential
  *    CPU and memory-burner; its use is not suggested for anything
  *    but single-user mode.
  */
@@ -251,97 +253,98 @@
 static gpointer
 get_price_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   QofBook *book = data;
-   GNCPriceDB *prdb;
-   GNCPrice *pr;
-   gint32 sql_vers, local_vers;
-   Timespec ts;
-   gint64 num, denom;
-   gnc_numeric value;
-   GUID guid = nullguid;
-   int not_found = 0;
+    QofBook *book = data;
+    GNCPriceDB *prdb;
+    GNCPrice *pr;
+    gint32 sql_vers, local_vers;
+    Timespec ts;
+    gint64 num, denom;
+    gnc_numeric value;
+    GUID guid = nullguid;
+    int not_found = 0;
 
-   gnc_commodity * modity;
+    gnc_commodity * modity;
 
-   FIND_BOOK (book);
+    FIND_BOOK (book);
 
-   prdb = gnc_book_get_pricedb(book);
+    prdb = gnc_book_get_pricedb(book);
 
-   /* First, lets see if we've already got this one */
-   string_to_guid (DB_GET_VAL ("priceGuid", j), &guid);
-   pr = gnc_price_lookup (&guid, book);
+    /* First, lets see if we've already got this one */
+    string_to_guid (DB_GET_VAL ("priceGuid", j), &guid);
+    pr = gnc_price_lookup (&guid, book);
 
-   if (!pr) 
-   { 
-      pr = gnc_price_create(book);
-      gnc_price_begin_edit (pr);
-      gnc_price_set_guid (pr, &guid);
-      not_found = 1;
-   } 
-   else
-   {
-      gnc_price_ref (pr);
-      gnc_price_begin_edit (pr);
-      not_found = 0;
-   }
+    if (!pr)
+    {
+        pr = gnc_price_create(book);
+        gnc_price_begin_edit (pr);
+        gnc_price_set_guid (pr, &guid);
+        not_found = 1;
+    }
+    else
+    {
+        gnc_price_ref (pr);
+        gnc_price_begin_edit (pr);
+        not_found = 0;
+    }
 
-   /* compare versions. Hack alert -- Not sure how to handle failures */
-   sql_vers = atoi (DB_GET_VAL("version",j));
-   local_vers = qof_instance_get_version(pr);
-   if (sql_vers < local_vers) {
-      PERR ("local price version is higher than db !!! local=%d sql=%d",
-         local_vers, sql_vers);
-      gnc_price_commit_edit (pr);
-      gnc_price_unref (pr);
-      return data;
-   }
-   qof_instance_set_version (pr, sql_vers);
+    /* compare versions. Hack alert -- Not sure how to handle failures */
+    sql_vers = atoi (DB_GET_VAL("version", j));
+    local_vers = qof_instance_get_version(pr);
+    if (sql_vers < local_vers)
+    {
+        PERR ("local price version is higher than db !!! local=%d sql=%d",
+              local_vers, sql_vers);
+        gnc_price_commit_edit (pr);
+        gnc_price_unref (pr);
+        return data;
+    }
+    qof_instance_set_version (pr, sql_vers);
 
-   modity = gnc_string_to_commodity (DB_GET_VAL("commodity",j), book);
-   gnc_price_set_commodity (pr, modity);
+    modity = gnc_string_to_commodity (DB_GET_VAL("commodity", j), book);
+    gnc_price_set_commodity (pr, modity);
 
-   modity = gnc_string_to_commodity (DB_GET_VAL("currency",j), book);
-   gnc_price_set_currency (pr, modity);
+    modity = gnc_string_to_commodity (DB_GET_VAL("currency", j), book);
+    gnc_price_set_currency (pr, modity);
 
-   ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("time",j));
-   gnc_price_set_time (pr, ts);
+    ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("time", j));
+    gnc_price_set_time (pr, ts);
 
-   gnc_price_set_source (pr, DB_GET_VAL("source",j));
-   gnc_price_set_typestr (pr, DB_GET_VAL("type",j));
+    gnc_price_set_source (pr, DB_GET_VAL("source", j));
+    gnc_price_set_typestr (pr, DB_GET_VAL("type", j));
 
-   num = strtoll (DB_GET_VAL("valueNum", j), NULL, 0);
-   denom = strtoll (DB_GET_VAL("valueDenom", j), NULL, 0);
-   value = gnc_numeric_create (num, denom);
-   gnc_price_set_value (pr, value);
+    num = strtoll (DB_GET_VAL("valueNum", j), NULL, 0);
+    denom = strtoll (DB_GET_VAL("valueDenom", j), NULL, 0);
+    value = gnc_numeric_create (num, denom);
+    gnc_price_set_value (pr, value);
 
-   if (not_found) gnc_pricedb_add_price(prdb, pr);
-   gnc_price_commit_edit (pr);
-   gnc_price_unref (pr);
+    if (not_found) gnc_pricedb_add_price(prdb, pr);
+    gnc_price_commit_edit (pr);
+    gnc_price_unref (pr);
 
-   return data;
+    return data;
 }
 
 
 void
 pgendGetAllPricesInBook (PGBackend *be, QofBook *book)
 {
-   char buff[400], *p;
+    char buff[400], *p;
 
-   if (!be) return;
-   ENTER ("be=%p, conn=%p", be, be->connection);
+    if (!be) return;
+    ENTER ("be=%p, conn=%p", be, be->connection);
 
-   /* first, make sure commodities table is up to date */
-   pgendGetAllCommodities (be);
+    /* first, make sure commodities table is up to date */
+    pgendGetAllCommodities (be);
 
-   /* Get them ALL */
-   p = buff;
-   p = stpcpy (p, "SELECT * FROM gncPrice WHERE bookGuid='");
-   p = guid_to_string_buff (qof_book_get_guid(book), p);
-   p = stpcpy (p, "';");
-   SEND_QUERY (be, buff, );
-   pgendGetResults (be, get_price_cb, book);
+    /* Get them ALL */
+    p = buff;
+    p = stpcpy (p, "SELECT * FROM gncPrice WHERE bookGuid='");
+    p = guid_to_string_buff (qof_book_get_guid(book), p);
+    p = stpcpy (p, "';");
+    SEND_QUERY (be, buff, );
+    pgendGetResults (be, get_price_cb, book);
 
-   LEAVE (" ");
+    LEAVE (" ");
 }
 
 /* ============================================================= */
@@ -349,98 +352,104 @@
 void
 pgendPriceFind (QofBackend *bend, gpointer olook)
 {
-   PGBackend *be = (PGBackend *)bend;
-   GNCPriceLookup *look = (GNCPriceLookup *)olook;
-   const char * commodity_str;
-   const char * currency_str;
-   sqlEscape *escape;
-   char * p;
+    PGBackend *be = (PGBackend *)bend;
+    GNCPriceLookup *look = (GNCPriceLookup *)olook;
+    const char * commodity_str;
+    const char * currency_str;
+    sqlEscape *escape;
+    char * p;
 
-   ENTER ("be=%p, lookup=%p", be, look);
-   if (!be || !look) { LEAVE("(null) args"); return; }
+    ENTER ("be=%p, lookup=%p", be, look);
+    if (!be || !look)
+    {
+        LEAVE("(null) args");
+        return;
+    }
 
-   /* special case the two-way search in terms of more basic primitives */
-   if (LOOKUP_NEAREST_IN_TIME == look->type)
-   {
-      look->type = LOOKUP_LATEST_BEFORE;
-      pgendPriceFind (bend, look);
-      look->type = LOOKUP_EARLIEST_AFTER;
-      pgendPriceFind (bend, look);
-      LEAVE(" ");
-      return;
-   }
+    /* special case the two-way search in terms of more basic primitives */
+    if (LOOKUP_NEAREST_IN_TIME == look->type)
+    {
+        look->type = LOOKUP_LATEST_BEFORE;
+        pgendPriceFind (bend, look);
+        look->type = LOOKUP_EARLIEST_AFTER;
+        pgendPriceFind (bend, look);
+        LEAVE(" ");
+        return;
+    }
 
-   escape = sqlEscape_new ();
+    escape = sqlEscape_new ();
 
-   commodity_str = gnc_commodity_get_unique_name(look->commodity);
-   currency_str  = gnc_commodity_get_unique_name(look->currency);
+    commodity_str = gnc_commodity_get_unique_name(look->commodity);
+    currency_str  = gnc_commodity_get_unique_name(look->currency);
 
-   /* don't send events  to GUI, don't accept callbacks to backend */
-   qof_event_suspend();
-   pgendDisable(be);
+    /* don't send events  to GUI, don't accept callbacks to backend */
+    qof_event_suspend();
+    pgendDisable(be);
 
-   /* set up the common part of the query */
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "SELECT * FROM gncPrice"
-                  "  WHERE commodity='");
-   p = stpcpy (p, sqlEscapeString (escape, commodity_str));
-   p = stpcpy (p, "' ");
+    /* set up the common part of the query */
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "SELECT * FROM gncPrice"
+                "  WHERE commodity='");
+    p = stpcpy (p, sqlEscapeString (escape, commodity_str));
+    p = stpcpy (p, "' ");
 
-   if (currency_str) {
-       p = stpcpy (p, "AND currency='");
-       p = stpcpy (p, sqlEscapeString (escape, currency_str));
-       p = stpcpy (p, "' ");
-   }
+    if (currency_str)
+    {
+        p = stpcpy (p, "AND currency='");
+        p = stpcpy (p, sqlEscapeString (escape, currency_str));
+        p = stpcpy (p, "' ");
+    }
 
-   PINFO("query = %s", be->buff);
+    PINFO("query = %s", be->buff);
 
-   sqlEscape_destroy (escape);
-   escape = NULL;
+    sqlEscape_destroy (escape);
+    escape = NULL;
 
-   switch (look->type)
-   {
-      case LOOKUP_LATEST:
-         p = stpcpy (p, "ORDER BY time DESC LIMIT 1;");
-         break;
-      case LOOKUP_ALL:
-         /* Get all prices for this commodity and currency */
-         p = stpcpy (p, ";");
-         break;
-      case LOOKUP_AT_TIME:
-         p = stpcpy (p, "AND time='");
-         p = gnc_timespec_to_iso8601_buff (look->date, p);
-         p = stpcpy (p, "';");
-         break;
-      case LOOKUP_NEAREST_IN_TIME:
-         PERR ("this can't possibly happen but it did!!!");
-         p = stpcpy (p, ";");
-         break;
-      case LOOKUP_LATEST_BEFORE:
-         p = stpcpy (p, "AND time <= '");
-         p = gnc_timespec_to_iso8601_buff (look->date, p);
-         p = stpcpy (p, "' ORDER BY time DESC LIMIT 1;");
-         break;
-      case LOOKUP_EARLIEST_AFTER:
-         p = stpcpy (p, "AND time >= '");
-         p = gnc_timespec_to_iso8601_buff (look->date, p);
-         p = stpcpy (p, "' ORDER BY time ASC LIMIT 1;");
-         break;
-      default:
-         PERR ("unknown lookup type %d", look->type);
-         /* re-enable events */
-         pgendEnable(be);
-         qof_event_resume();
-         LEAVE(" ");
-         return;
-   }
+    switch (look->type)
+    {
+    case LOOKUP_LATEST:
+        p = stpcpy (p, "ORDER BY time DESC LIMIT 1;");
+        break;
+    case LOOKUP_ALL:
+        /* Get all prices for this commodity and currency */
+        p = stpcpy (p, ";");
+        break;
+    case LOOKUP_AT_TIME:
+        p = stpcpy (p, "AND time='");
+        p = gnc_timespec_to_iso8601_buff (look->date, p);
+        p = stpcpy (p, "';");
+        break;
+    case LOOKUP_NEAREST_IN_TIME:
+        PERR ("this can't possibly happen but it did!!!");
+        p = stpcpy (p, ";");
+        break;
+    case LOOKUP_LATEST_BEFORE:
+        p = stpcpy (p, "AND time <= '");
+        p = gnc_timespec_to_iso8601_buff (look->date, p);
+        p = stpcpy (p, "' ORDER BY time DESC LIMIT 1;");
+        break;
+    case LOOKUP_EARLIEST_AFTER:
+        p = stpcpy (p, "AND time >= '");
+        p = gnc_timespec_to_iso8601_buff (look->date, p);
+        p = stpcpy (p, "' ORDER BY time ASC LIMIT 1;");
+        break;
+    default:
+        PERR ("unknown lookup type %d", look->type);
+        /* re-enable events */
+        pgendEnable(be);
+        qof_event_resume();
+        LEAVE(" ");
+        return;
+    }
 
-   SEND_QUERY (be, be->buff, );
-   pgendGetResults (be, get_price_cb, NULL);
+    SEND_QUERY (be, be->buff, );
+    pgendGetResults (be, get_price_cb, NULL);
 
-   /* re-enable events */
-   pgendEnable(be);
-   qof_event_resume();
-   LEAVE(" ");
+    /* re-enable events */
+    pgendEnable(be);
+    qof_event_resume();
+    LEAVE(" ");
 }
 
 /* ============================================================= */
@@ -452,76 +461,77 @@
 void
 pgend_price_begin_edit (QofBackend * bend, GNCPrice *pr)
 {
-   if (pr && pr->db && qof_instance_get_dirty_flag(pr->db)) 
-   {
-      PERR ("price db is unexpectedly dirty");
-   }
-   return;
+    if (pr && pr->db && qof_instance_get_dirty_flag(pr->db))
+    {
+        PERR ("price db is unexpectedly dirty");
+    }
+    return;
 }
 
 void
 pgend_price_commit_edit (QofBackend * bend, GNCPrice *pr)
 {
-   char * bufp;
-   PGBackend *be = (PGBackend *)bend;
+    char * bufp;
+    PGBackend *be = (PGBackend *)bend;
 
-   ENTER ("be=%p, price=%p", be, pr);
-   if (!be || !pr) return; 
+    ENTER ("be=%p, price=%p", be, pr);
+    if (!be || !pr) return;
 
-   /* lock it up so that we query and store atomically */
-   bufp = "BEGIN;\n"
-          "LOCK TABLE gncPrice IN EXCLUSIVE MODE;\n";
-   SEND_QUERY (be,bufp,);
-   FINISH_QUERY(be->connection);
+    /* lock it up so that we query and store atomically */
+    bufp = "BEGIN;\n"
+           "LOCK TABLE gncPrice IN EXCLUSIVE MODE;\n";
+    SEND_QUERY (be, bufp,);
+    FINISH_QUERY(be->connection);
 
-   /* check to see that the engine version is equal or newer than 
-    * whats in the database.  It its not, then some other user has 
-    * made changes, and we must roll back. */
-   if (0 < pgendPriceCompareVersion (be, pr))
-   {
-      qof_instance_set_destroying(pr, FALSE);
-      bufp = "ROLLBACK;";
-      SEND_QUERY (be,bufp,);
-      FINISH_QUERY(be->connection);
+    /* check to see that the engine version is equal or newer than
+     * whats in the database.  It its not, then some other user has
+     * made changes, and we must roll back. */
+    if (0 < pgendPriceCompareVersion (be, pr))
+    {
+        qof_instance_set_destroying(pr, FALSE);
+        bufp = "ROLLBACK;";
+        SEND_QUERY (be, bufp,);
+        FINISH_QUERY(be->connection);
 
-      /* hack alert -- we should restore the price data from the 
-       * sql back end at this point ! !!! */
-      PWARN(" price data in engine is newer\n"
-            " price must be rolled back.  This function\n"
-            " is not completely implemented !! \n");
-      LEAVE ("rolled back");
-      qof_backend_set_error (&be->be, ERR_BACKEND_MODIFIED);
-      return;
-   }
-   /* be sure to update the version !! */
-   qof_instance_increment_version(pr, be->version_check);
+        /* hack alert -- we should restore the price data from the
+         * sql back end at this point ! !!! */
+        PWARN(" price data in engine is newer\n"
+              " price must be rolled back.  This function\n"
+              " is not completely implemented !! \n");
+        LEAVE ("rolled back");
+        qof_backend_set_error (&be->be, ERR_BACKEND_MODIFIED);
+        return;
+    }
+    /* be sure to update the version !! */
+    qof_instance_increment_version(pr, be->version_check);
 
-   if (qof_instance_get_destroying(pr))
-   {
-      pgendStoreAuditPrice (be, pr, SQL_DELETE);
-      bufp = be->buff; *bufp = 0;
-      bufp = stpcpy (bufp, "DELETE FROM gncPrice WHERE priceGuid='");
-      bufp = guid_to_string_buff (gnc_price_get_guid(pr), bufp);
-      bufp = stpcpy (bufp, "';");
-      PINFO ("%s\n", be->buff ? be->buff : "(null)");
-      SEND_QUERY (be,be->buff, );
-      FINISH_QUERY(be->connection);
-   }
-   else 
-   { 
-      pgendStorePriceNoLock (be, pr, FALSE);
-   }
+    if (qof_instance_get_destroying(pr))
+    {
+        pgendStoreAuditPrice (be, pr, SQL_DELETE);
+        bufp = be->buff;
+        *bufp = 0;
+        bufp = stpcpy (bufp, "DELETE FROM gncPrice WHERE priceGuid='");
+        bufp = guid_to_string_buff (gnc_price_get_guid(pr), bufp);
+        bufp = stpcpy (bufp, "';");
+        PINFO ("%s\n", be->buff ? be->buff : "(null)");
+        SEND_QUERY (be, be->buff, );
+        FINISH_QUERY(be->connection);
+    }
+    else
+    {
+        pgendStorePriceNoLock (be, pr, FALSE);
+    }
 
-   bufp = "COMMIT;\n"
-          "NOTIFY gncPrice;";
-   SEND_QUERY (be,bufp,);
-   FINISH_QUERY(be->connection);
+    bufp = "COMMIT;\n"
+           "NOTIFY gncPrice;";
+    SEND_QUERY (be, bufp,);
+    FINISH_QUERY(be->connection);
 
-   if (pr->db)
-     qof_instance_mark_clean(&pr->db->inst);
+    if (pr->db)
+        qof_instance_mark_clean(&pr->db->inst);
 
-   LEAVE ("commited");
-   return;
+    LEAVE ("commited");
+    return;
 }
 
 /* ======================== END OF FILE ======================== */

Modified: gnucash/trunk/src/backend/postgres/putil.c
===================================================================
--- gnucash/trunk/src/backend/postgres/putil.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/putil.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -19,7 +19,7 @@
  * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
 \********************************************************************/
 
-/* 
+/*
  * FILE:
  * putil.c
  *
@@ -28,14 +28,14 @@
  *
  * HISTORY:
  * Copyright (c) 2002 Matthew Vanecek <mevanecek at yahoo.com>
- * 
+ *
  */
 
-#include "config.h" 
-#include <glib.h> 
+#include "config.h"
+#include <glib.h>
 #include <glib/gi18n.h>
-#include <libpq-fe.h>  
-#include <stdlib.h>  
+#include <libpq-fe.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "qof.h"
@@ -45,69 +45,75 @@
 
 #include "putil.h"
 
-ExecStatusType execQuery(PGBackend *be, const char * q) {
-	PGresult * result;
-	ExecStatusType status;
-	gchar * msg;
+ExecStatusType execQuery(PGBackend *be, const char * q)
+{
+    PGresult * result;
+    ExecStatusType status;
+    gchar * msg;
 
     ENTER(" ");
-    
-    if (!be || !be->connection) {
+
+    if (!be || !be->connection)
+    {
         LEAVE("Backend or connection is not available");
         qof_backend_set_message(&be->be, _("Backend connection is not available"));
         qof_backend_set_error(&be->be, ERR_BACKEND_CONN_LOST);
         return -1;
     }
-     
-	result = PQexec(be->connection, q);
 
-	if (!result) {
-		PINFO("Query could not be executed");
+    result = PQexec(be->connection, q);
+
+    if (!result)
+    {
+        PINFO("Query could not be executed");
         qof_backend_set_message(&be->be, _("Query could not be executed"));
         qof_backend_set_error(&be->be, ERR_BACKEND_SERVER_ERR);
-		return -1;
-	}
+        return -1;
+    }
 
-	status = PQresultStatus(result);
-	msg = (gchar *)PQresultErrorMessage(result);
-	PINFO("Result status: %s/%s",
-		PQresStatus(status), (strlen(msg)) > 0 ? msg : "(No Message)");
-	PINFO("Number of rows affected: %d", atoi(PQcmdTuples(result)));
-    
-    if (status != PGRES_COMMAND_OK) {
+    status = PQresultStatus(result);
+    msg = (gchar *)PQresultErrorMessage(result);
+    PINFO("Result status: %s/%s",
+          PQresStatus(status), (strlen(msg)) > 0 ? msg : "(No Message)");
+    PINFO("Number of rows affected: %d", atoi(PQcmdTuples(result)));
+
+    if (status != PGRES_COMMAND_OK)
+    {
         PINFO("Query causing error: %s", q);
         qof_backend_set_message(&be->be, _("From the Postgresql Server: %s"), msg);
         qof_backend_set_error(&be->be, ERR_BACKEND_SERVER_ERR);
     }
 
-	PQclear(result);
+    PQclear(result);
     return status;
 }
 
 
 /* ============================================================= */
-/* The sendQuery function sends the sql statement off to the server. 
+/* The sendQuery function sends the sql statement off to the server.
  * It performs a minimal check to see that the send succeeded. The
  * return value indicates success or failure of the send.
  */
-int sendQuery(PGBackend *be,char * buff) {
-   int rc = 0;
+int sendQuery(PGBackend *be, char * buff)
+{
+    int rc = 0;
 
-   ENTER(" ");
-   if (NULL == be->connection) return ERR_BACKEND_CONN_LOST;
-   PINFO("Connectionn is %p", be->connection);
-   PINFO ("sending query %s", buff);
-   rc = PQsendQuery (be->connection, buff);
-   if (!rc) {
-      gchar * msg = (gchar *)PQerrorMessage(be->connection);
-      PERR("send query failed:\n"
-           "\t%s", msg);
-      qof_backend_set_message(&be->be, _("From the Postgresql Server: %s"), msg);
-      qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);
-      return ERR_BACKEND_SERVER_ERR;
-   }
-   LEAVE("PQsendQuery rc = %d", rc);
-   return ERR_BACKEND_NO_ERR;
+    ENTER(" ");
+    if (NULL == be->connection) return ERR_BACKEND_CONN_LOST;
+    PINFO("Connectionn is %p", be->connection);
+    PINFO ("sending query %s", buff);
+    rc = PQsendQuery (be->connection, buff);
+    if (!rc)
+    {
+        gchar * msg = (gchar *)PQerrorMessage(be->connection);
+        PERR("send query failed:\n"
+             "\t%s", msg);
+        qof_backend_set_message(&be->be, _("From the Postgresql Server: %s"), msg);
+        qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);
+        return ERR_BACKEND_SERVER_ERR;
+    }
+    LEAVE("PQsendQuery rc = %d", rc);
+    return ERR_BACKEND_NO_ERR;
 }
 
 /* --------------------------------------------------------------- */
@@ -118,39 +124,44 @@
  * rows affected by the query is returned.
  */
 
-int finishQuery(PGBackend *be) {
-   int i=0;
-   PGresult *result;
+int finishQuery(PGBackend *be)
+{
+    int i = 0;
+    PGresult *result;
 
-   ENTER(" ");
-   /* complete/commit the transaction, check the status */
-   PINFO("Connection is %p", be->connection);
-   do {
-      int x;
-      ExecStatusType status;
-      result = PQgetResult(be->connection);
-      if (!result) {
-          PINFO("Result is (null)");
-          break;
-      }
-      
-      status = PQresultStatus(result);
-      x = atoi(PQcmdTuples(result));
-      PINFO("Result status: %s, rows affected: %d, by %s",
-            PQresStatus(status), x, PQcmdStatus(result));
-      i += x;
+    ENTER(" ");
+    /* complete/commit the transaction, check the status */
+    PINFO("Connection is %p", be->connection);
+    do
+    {
+        int x;
+        ExecStatusType status;
+        result = PQgetResult(be->connection);
+        if (!result)
+        {
+            PINFO("Result is (null)");
+            break;
+        }
 
-      if (PGRES_COMMAND_OK != status) {
-         gchar * msg = (gchar *)PQerrorMessage(be->connection);
-         PERR("finish query failed:\n\t%s", msg);
-         PQclear(result);
-         qof_backend_set_message(&be->be, _("From the Postgresql Server: %s"), msg);
-         qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);
-         break; 
-      }
-      PQclear(result);
-   } while (result);
+        status = PQresultStatus(result);
+        x = atoi(PQcmdTuples(result));
+        PINFO("Result status: %s, rows affected: %d, by %s",
+              PQresStatus(status), x, PQcmdStatus(result));
+        i += x;
 
-   LEAVE("%d rows affected by SQL statement", i);
-   return i;
+        if (PGRES_COMMAND_OK != status)
+        {
+            gchar * msg = (gchar *)PQerrorMessage(be->connection);
+            PERR("finish query failed:\n\t%s", msg);
+            PQclear(result);
+            qof_backend_set_message(&be->be, _("From the Postgresql Server: %s"), msg);
+            qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);
+            break;
+        }
+        PQclear(result);
+    }
+    while (result);
+
+    LEAVE("%d rows affected by SQL statement", i);
+    return i;
 }

Modified: gnucash/trunk/src/backend/postgres/putil.h
===================================================================
--- gnucash/trunk/src/backend/postgres/putil.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/putil.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -19,7 +19,7 @@
  * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
 \********************************************************************/
 
-/* 
+/*
  * FILE:
  * putil.h
  *
@@ -28,17 +28,17 @@
  *
  * HISTORY:
  * Copyright (c) 2000, 2001, 2002 Linas Vepstas <linas at linas.org>
- * 
+ *
  */
 
-#ifndef P_UTIL_H 
-#define P_UTIL_H 
+#ifndef P_UTIL_H
+#define P_UTIL_H
 
 #include <glib.h>
-#include <string.h>  
-#include <sys/types.h>  
+#include <string.h>
+#include <sys/types.h>
 
-#include <libpq-fe.h>  
+#include <libpq-fe.h>
 
 #include "qof.h"
 
@@ -56,8 +56,8 @@
  */
 
 gpointer pgendGetResults (PGBackend *be,
-            gpointer (*handler) (PGBackend *, PGresult *, int, gpointer),
-            gpointer data);
+                          gpointer (*handler) (PGBackend *, PGresult *, int, gpointer),
+                          gpointer data);
 
 /* The gnc_string_to_commodity() routine finds the commodity by
  *     parsing a string of the form NAMESPACE::MNEMONIC
@@ -65,20 +65,20 @@
 gnc_commodity * gnc_string_to_commodity (const char *str, QofBook *book);
 
 ExecStatusType execQuery(PGBackend *be, const char * q);
-int sendQuery(PGBackend *be,char * buff);
+int sendQuery(PGBackend *be, char * buff);
 int finishQuery(PGBackend *be);
 
-/* hack alert -- calling PQfinish() on error is quite harsh, since 
+/* hack alert -- calling PQfinish() on error is quite harsh, since
  * all subsequent sql queries will fail. On the other hand, killing
- * anything that follows *is* a way of minimizing data corruption 
- * due to subsequent mishaps ... so anyway, error handling in these 
+ * anything that follows *is* a way of minimizing data corruption
+ * due to subsequent mishaps ... so anyway, error handling in these
  * routines needs to be redone.   There are notes describing the
  * 'correct' solution in src/doc/backend-error.txt.
  */
 
 /* ============================================================= */
-/* The SEND_QUERY macro sends the sql statement off to the server. 
- * It performs a minimal check to see that the send succeeded. 
+/* The SEND_QUERY macro sends the sql statement off to the server.
+ * It performs a minimal check to see that the send succeeded.
  */
 
 #define SEND_QUERY(be,buff,retval)                              \
@@ -97,7 +97,7 @@
       return retval;                                            \
    }                                                            \
 }                                                               \
-
+ 
 /* --------------------------------------------------------------- */
 /* The FINISH_QUERY macro makes sure that the previously sent
  * query complete with no errors.  It assumes that the query
@@ -129,10 +129,10 @@
       i++;                                                      \
    } while (result);                                            \
 }                                                               \
-
+ 
 /* --------------------------------------------------------------- */
 /* The GET_RESULTS macro grabs the result of an pgSQL query off the
- * wire, and makes sure that no errors occured. Results are left 
+ * wire, and makes sure that no errors occured. Results are left
  * in the result buffer.
  */
 #define GET_RESULTS(conn,result)                            \
@@ -153,10 +153,10 @@
       break;                                                \
    }                                                        \
 }                                                           \
-
+ 
 /* --------------------------------------------------------------- */
 /* The EXEC_QUERY macro executes a query and returns the results
- * and makes sure that no errors occured. Results are left 
+ * and makes sure that no errors occured. Results are left
  * in the result buffer.
  */
 #define EXEC_QUERY(conn,buff,result)                        \
@@ -183,13 +183,13 @@
       qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);\
    }                                                        \
 }                                                           \
-
+ 
 /* --------------------------------------------------------------- */
-/* The IF_ONE_ROW macro counts the number of rows returned by 
+/* The IF_ONE_ROW macro counts the number of rows returned by
  * a query, reports an error if there is more than one row, and
  * conditionally executes a block for the first row.
  */
- 
+
 #define IF_ONE_ROW(result,nrows,loopcounter)			\
    {								\
       int ncols = PQnfields (result);				\
@@ -201,7 +201,7 @@
       PERR ("unexpected duplicate records");			\
       qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT);	\
       break;							\
-   } else if (1 == nrows) 
+   } else if (1 == nrows)
 
 /* --------------------------------------------------------------- */
 /* Some utility macros for comparing values returned from the
@@ -209,7 +209,7 @@
  * all take three arguments:
  * -- sqlname -- input -- the name of the field in the sql table
  * -- fun -- input -- a subroutine returning a value
- * -- ndiffs -- input/output -- integer, incremented if the 
+ * -- ndiffs -- input/output -- integer, incremented if the
  *              value of the field and the value returned by
  *              the subroutine differ.
  *
@@ -218,7 +218,7 @@
 
 #define DB_GET_VAL(str,n) (PQgetvalue (result, n, PQfnumber (result, str)))
 
-/* Compare string types.  Null strings and empty strings are  
+/* Compare string types.  Null strings and empty strings are
  * considered to be equal */
 #define COMP_STR(sqlname,fun,ndiffs) { 				\
    if (null_strcmp (DB_GET_VAL(sqlname,0),fun)) {		\
@@ -228,7 +228,7 @@
    }								\
 }
 
-/* Compare commodities. This routine is almost identical to 
+/* Compare commodities. This routine is almost identical to
  * COMP_STR, except that a NULL currency from the engine
  * is allowed to match any currency in the sql DB.  This is
  * used to facilitate deletion, where the currency has been
@@ -244,8 +244,8 @@
    }								\
 }
 
-/* Compare guids. A NULL GUID from the engine is considered to 
- * match any value of a GUID in the sql database.  This is 
+/* Compare guids. A NULL GUID from the engine is considered to
+ * match any value of a GUID in the sql database.  This is
  * equality is used to enable deletion, where the GUID may have
  * already been set to NULL in the engine, but not yet in the DB.
  */
@@ -260,7 +260,7 @@
          ndiffs++; 						\
       }								\
    }								\
-} 
+}
 
 /* Comapre one char only */
 #define COMP_CHAR(sqlname,fun, ndiffs) { 			\
@@ -272,11 +272,11 @@
 }
 
 /* Compare dates.
- * Assumes the datestring is in ISO-8601 format 
- * i.e. looks like 1998-07-17 11:00:00.68-05  
- * hack-alert doesn't compare nano-seconds ..  
+ * Assumes the datestring is in ISO-8601 format
+ * i.e. looks like 1998-07-17 11:00:00.68-05
+ * hack-alert doesn't compare nano-seconds ..
  * this is intentional,  its because I suspect
- * the sql db round nanoseconds off ... 
+ * the sql db round nanoseconds off ...
  */
 #define COMP_DATE(sqlname,fun,ndiffs) { 			\
     Timespec eng_time = fun;					\
@@ -291,10 +291,10 @@
    }								\
 }
 
-/* Compare the date of last modification. 
- * This is a special date comp to 
+/* Compare the date of last modification.
+ * This is a special date comp to
  * (1) make the m4 macros simpler, and
- * (2) avoid needless updates 
+ * (2) avoid needless updates
  */
 #define COMP_NOW(sqlname,fun,ndiffs) { 	 			\
     Timespec eng_time = xaccTransRetDateEnteredTS(ptr);		\

Modified: gnucash/trunk/src/backend/postgres/test/test-db.c
===================================================================
--- gnucash/trunk/src/backend/postgres/test/test-db.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/test/test-db.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -14,8 +14,8 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  *  02110-1301, USA.
  */
- 
-#include "config.h" 
+
+#include "config.h"
 #include <glib.h>
 #include <libpq-fe.h>
 #include <stdlib.h>
@@ -37,7 +37,8 @@
 
 static QofLogModule log_module = GNC_MOD_TEST;
 
-struct _dbinfo {
+struct _dbinfo
+{
     char *host;
     char *port;
     char *dbname;
@@ -93,7 +94,8 @@
     g_return_val_if_fail(dbinfo->dbname && dbinfo->mode, NULL);
 
     if ((!g_ascii_strncasecmp(dbinfo->port, "7777", 4)) &&
-        (!g_ascii_strncasecmp(dbinfo->host, "localhost", 8))) {
+            (!g_ascii_strncasecmp(dbinfo->host, "localhost", 8)))
+    {
         /* TEST_DB_SOCKET_DIR must be an absolute path */
         db_socket_dir = getenv("TEST_DB_SOCKET_DIR");
         if (!db_socket_dir)
@@ -101,7 +103,9 @@
         g_return_val_if_fail(db_socket_dir, NULL);
         url = g_strdup_printf("postgres://%s:7777/%s?mode=%s",
                               db_socket_dir, dbinfo->dbname, dbinfo->mode);
-    } else {
+    }
+    else
+    {
         url = g_strdup_printf("postgres://%s:%s/%s?mode=%s",
                               dbinfo->host, dbinfo->port,
                               dbinfo->dbname, dbinfo->mode);
@@ -183,7 +187,8 @@
                       dbinfo->dbname, dbinfo->mode))
         return FALSE;
 
-    if (end_session) {
+    if (end_session)
+    {
         qof_session_end(session);
         io_err = qof_session_get_error(session);
         if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
@@ -229,14 +234,17 @@
     qof_session_begin(session_2, filename, FALSE, FALSE);
     io_err = qof_session_get_error(session_2);
 
-    if (multi_user) {
+    if (multi_user)
+    {
         if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
                           "Beginning second multi-user db session",
                           __FILE__, __LINE__,
                           "can't begin second session for %s in mode %s",
                           dbinfo->dbname, dbinfo->mode))
             return FALSE;
-    } else {
+    }
+    else
+    {
         if (!do_test_args(io_err != ERR_BACKEND_NO_ERR,
                           "Beginning second single-user db session",
                           __FILE__, __LINE__,
@@ -280,7 +288,8 @@
     return TRUE;
 }
 
-typedef struct {
+typedef struct
+{
     GHashTable *hash;
     GList *to_delete;
 } CommodityDeleteInfo;
@@ -310,10 +319,10 @@
     book = qof_session_get_book(session);
 
     gnc_account_foreach_descendant(gnc_book_get_root_account(book),
-                            mark_account_commodities, cdi.hash);
+                                   mark_account_commodities, cdi.hash);
 
     xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
-                                mark_transaction_commodities, cdi.hash);
+                                      mark_transaction_commodities, cdi.hash);
 
     gnc_pricedb_foreach_price(gnc_book_get_pricedb(book),
                               mark_price_commodities, cdi.hash, FALSE);
@@ -395,7 +404,8 @@
 
     make_random_changes_to_session(session);
 
-    if (!multi_user) {
+    if (!multi_user)
+    {
         qof_session_end(session);
         io_err = qof_session_get_error(session);
         if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
@@ -427,7 +437,8 @@
                  "book 1: %s,\nbook 2: %s",
                  dbinfo->dbname, dbinfo->mode, str1, str2);
 
-    if (multi_user) {
+    if (multi_user)
+    {
         qof_session_end(session);
         io_err = qof_session_get_error(session);
         if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
@@ -447,7 +458,8 @@
             return FALSE;
     }
 
-    if (!ok) {
+    if (!ok)
+    {
         save_xml_files(session, session_2);
         return FALSE;
     }
@@ -485,7 +497,8 @@
     return num;
 }
 
-typedef struct {
+typedef struct
+{
     QofSession *session_base;
     DbInfo *dbinfo;
     gint loaded;
@@ -516,14 +529,17 @@
     result = PQexec(be->connection, sql_query_string);
 
     ok = (result && PQresultStatus(result) == PGRES_TUPLES_OK);
-    if (!ok) {
+    if (!ok)
+    {
         failure_args("Raw query failed",
                      __FILE__, __LINE__,
                      "Error: %s\nQuery: %s",
                      PQresultErrorMessage(result),
                      sql_query_string);
         /* failure("raw query failed: %s", sql_query_string); */
-    } else {
+    }
+    else
+    {
         ok = ok && (PQntuples(result) == 1);
         if (!ok)
             failure_args("number returned test",
@@ -531,7 +547,8 @@
                          "query returned %d tuples", PQntuples(result));
     }
 
-    if (ok) {
+    if (ok)
+    {
         success("raw query succeeded");
     }
 
@@ -577,13 +594,15 @@
     q = make_trans_query(trans, get_random_query_type() | GUID_QT);
     xaccQuerySetBook(q, book);
 
-    if (!test_raw_query(session, q)) {
+    if (!test_raw_query(session, q))
+    {
         failure("raw query failed");
         return FALSE;
     }
 
     list = xaccQueryGetTransactions(q, QUERY_TXN_MATCH_ANY);
-    if (g_list_length(list) != 1) {
+    if (g_list_length(list) != 1)
+    {
         failure_args("test num returned", __FILE__, __LINE__,
                      "number of matching transactions %d not 1",
                      g_list_length(list));
@@ -594,7 +613,8 @@
     qtd->loaded += session_num_trans(session);
     qtd->total += session_num_trans(qtd->session_base);
 
-    if (!xaccTransEqual(trans, list->data, TRUE, TRUE, TRUE, FALSE)) {
+    if (!xaccTransEqual(trans, list->data, TRUE, TRUE, TRUE, FALSE))
+    {
         failure("matching transaction is wrong");
         g_list_free(list);
         return FALSE;
@@ -625,12 +645,14 @@
     ok = TRUE;
 
     list = gnc_account_get_descendants(gnc_book_get_root_account(book_1));
-    for (node = list; node; node = node->next) {
+    for (node = list; node; node = node->next)
+    {
         Account *account_1 = node->data;
         Account *account_2;
 
         account_2 = xaccAccountLookup(xaccAccountGetGUID(account_1), book_2);
-        if (!account_2) {
+        if (!account_2)
+        {
             failure_args("", __FILE__, __LINE__,
                          "session_1 has account %s but not session_2",
                          guid_to_string(xaccAccountGetGUID(account_1)));
@@ -638,7 +660,8 @@
         }
 
         if (!gnc_numeric_equal(xaccAccountGetBalance(account_1),
-                               xaccAccountGetBalance(account_2))) {
+                               xaccAccountGetBalance(account_2)))
+        {
             failure_args("", __FILE__, __LINE__,
                          "balances not equal for account %s",
                          guid_to_string(xaccAccountGetGUID(account_1)));
@@ -646,7 +669,8 @@
         }
 
         if (!gnc_numeric_equal(xaccAccountGetClearedBalance(account_1),
-                               xaccAccountGetClearedBalance(account_2))) {
+                               xaccAccountGetClearedBalance(account_2)))
+        {
             failure_args("", __FILE__, __LINE__,
                          "cleared balances not equal for account %s",
                          guid_to_string(xaccAccountGetGUID(account_1)));
@@ -654,7 +678,8 @@
         }
 
         if (!gnc_numeric_equal(xaccAccountGetReconciledBalance(account_1),
-                               xaccAccountGetReconciledBalance(account_2))) {
+                               xaccAccountGetReconciledBalance(account_2)))
+        {
             failure_args("", __FILE__, __LINE__,
                          "reconciled balances not equal for account %s",
                          guid_to_string(xaccAccountGetGUID(account_1)));
@@ -699,7 +724,8 @@
     return ok;
 }
 
-typedef struct {
+typedef struct
+{
     QofSession *session_1;
     QofSession *session_2;
 
@@ -734,7 +760,7 @@
 
     xaccTransBeginEdit(trans);
     make_random_changes_to_transaction_and_splits(book_1, trans,
-                                                  td->accounts_1);
+            td->accounts_1);
     xaccTransCommitEdit(trans);
 
     io_err = qof_session_get_error(td->session_1);
@@ -748,10 +774,11 @@
     trans_2 = xaccTransLookup(&guid, book_2);
 
     /* This should get rolled back. */
-    if (trans_2) {
+    if (trans_2)
+    {
         xaccTransBeginEdit(trans_2);
         make_random_changes_to_transaction_and_splits(book_2, trans_2,
-                                                      td->accounts_2);
+                td->accounts_2);
         xaccTransCommitEdit(trans_2);
     }
 
@@ -759,7 +786,7 @@
 
     ok = xaccTransEqual(trans, trans_2, TRUE, TRUE, TRUE, FALSE);
     if (trans && trans_2)
-      ok = ok && (qof_instance_compare_version(trans, trans_2));
+        ok = ok && (qof_instance_compare_version(trans, trans_2));
 
     /*
        ok = ok && (qof_session_get_error (td->session_2) == ERR_BACKEND_MODIFIED);
@@ -790,10 +817,13 @@
     gchar *dropdb = NULL;
     int rc;
 
-    if (!g_ascii_strncasecmp(dbinfo->port, "7777", 4)) {
+    if (!g_ascii_strncasecmp(dbinfo->port, "7777", 4))
+    {
         dropdb = g_strdup_printf("dropdb -p %s %s",
                                  dbinfo->port, dbinfo->dbname);
-    } else {
+    }
+    else
+    {
         dropdb = g_strdup_printf("dropdb -p %s -h %s %s",
                                  dbinfo->port, dbinfo->host,
                                  dbinfo->dbname);
@@ -803,7 +833,8 @@
     sleep(5);
     rc = system(dropdb);
     printf("Executed %s,\nreturn code was %d\n", dropdb, rc);
-    if (rc) {
+    if (rc)
+    {
         printf("Please run the command\n"
                "\t%s\nwhen this process completes\n", dropdb);
     }
@@ -811,9 +842,9 @@
     dropdb = NULL;
     return rc == 0 ? TRUE : FALSE;
 }
-    
+
 static gboolean
-test_updates_2(QofSession * session_base, DbInfo *dbinfo) 
+test_updates_2(QofSession * session_base, DbInfo *dbinfo)
 {
     UpdateTestData td;
     char *filename;
@@ -849,7 +880,8 @@
     ok = TRUE;
     transes = NULL;
     xaccAccountTreeForEachTransaction(td.root_1, add_trans_helper, &transes);
-    for (node = transes; node; node = node->next) {
+    for (node = transes; node; node = node->next)
+    {
         ok = test_trans_update(node->data, &td);
         if (!ok)
             return FALSE;
@@ -857,7 +889,8 @@
     g_list_free(transes);
 
 #if 0
-    for (node = td.accounts_1; node; node = node->next) {
+    for (node = td.accounts_1; node; node = node->next)
+    {
         Account *account_1 = node->data;
         Account *account_2 =
             xaccAccountLookup(xaccAccountGetGUID(account_1), td.book_2);
@@ -870,7 +903,7 @@
             ok = ok && (account_1->version == account_2->version);
 
         ok = ok
-            && (qof_session_get_error(td.session_2) == ERR_BACKEND_MODIFIED);
+             && (qof_session_get_error(td.session_2) == ERR_BACKEND_MODIFIED);
 
         if (!do_test_args(ok,
                           "test account rollback",
@@ -895,7 +928,8 @@
         xaccAccountCommitEdit(account);
 
         xaccTransBeginEdit(trans);
-        for (node = xaccTransGetSplitList(trans); node; node = node->next) {
+        for (node = xaccTransGetSplitList(trans); node; node = node->next)
+        {
             Split *split = node->data;
 
             xaccAccountInsertSplit(child, split);
@@ -912,7 +946,8 @@
 
         xaccFreeQuery(q);
 
-        if (ok) {
+        if (ok)
+        {
             Transaction *trans_2;
             Account *account_2;
             Account *child_2;
@@ -967,7 +1002,8 @@
     if (!load_db_file(session_db, dbinfo, !multi_user))
         return FALSE;
 
-    if (multi_user) {
+    if (multi_user)
+    {
         if (!compare_balances(session, session_db))
             return FALSE;
 
@@ -981,7 +1017,8 @@
                  "Books not equal for session %s in mode %s",
                  dbinfo->dbname, dbinfo->mode);
 
-    if (multi_user) {
+    if (multi_user)
+    {
         QofBackendError io_err;
 
         qof_session_end(session_db);
@@ -994,7 +1031,8 @@
             return FALSE;
     }
 
-    if (!ok) {
+    if (!ok)
+    {
         save_xml_files(session, session_db);
         return FALSE;
     }
@@ -1065,7 +1103,7 @@
         return;
     REPORT_CLOCK(0, "Finished saving session");
     dbinfo->mode = modesave;
-    
+
     qof_session_destroy(session);
     session = qof_session_new();
 
@@ -1091,16 +1129,17 @@
 main (int argc, char **argv)
 {
     DbInfo *dbinfo;
-    
+
     qof_init();
     do_test(qof_load_backend_library ("../.libs/", PG_LIB_NAME),
             " loading gnc-backend-postgres GModule failed");
 
     dbinfo = g_new0(DbInfo, 1);
-    
+
     if (argc >= 2)
         dbinfo->host = argv[1];
-    else {
+    else
+    {
         dbinfo->host = getenv("PGHOST");
         if (!dbinfo->host)
             dbinfo->host = "localhost";
@@ -1108,7 +1147,8 @@
 
     if (argc >= 3)
         dbinfo->port = argv[2];
-    else {
+    else
+    {
         dbinfo->port = getenv("PGPORT");
         if (!dbinfo->port)
             dbinfo->port = "5432";

Modified: gnucash/trunk/src/backend/postgres/test/test-escape.c
===================================================================
--- gnucash/trunk/src/backend/postgres/test/test-escape.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/test/test-escape.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -11,52 +11,52 @@
 static void
 test_escape (const char *s, const char *expected)
 {
-  const char *escaped;
-  gboolean success;
+    const char *escaped;
+    gboolean success;
 
-  escaped = sqlEscapeString (escape, s);
+    escaped = sqlEscapeString (escape, s);
 
-  if (escaped == expected)
-    success = TRUE;
-  else
-    success = (strcmp (escaped, expected) == 0);
+    if (escaped == expected)
+        success = TRUE;
+    else
+        success = (strcmp (escaped, expected) == 0);
 
-  do_test_args (success, "escape test", __FILE__, __LINE__,
-                "bad escaping: expected %s -> %s, got %s",
-                s, expected, escaped);
+    do_test_args (success, "escape test", __FILE__, __LINE__,
+                  "bad escaping: expected %s -> %s, got %s",
+                  s, expected, escaped);
 }
 
 int
 main (int argc, char *argv[])
 {
-  int i;
+    int i;
 
-  random_character_include_funky_chars (TRUE);
+    random_character_include_funky_chars (TRUE);
 
-  escape = sqlEscape_new ();
+    escape = sqlEscape_new ();
 
-  test_escape (NULL, NULL);
-  test_escape ("", "");
-  test_escape ("'", "\\'");
-  test_escape ("\\", "\\\\");
+    test_escape (NULL, NULL);
+    test_escape ("", "");
+    test_escape ("'", "\\'");
+    test_escape ("\\", "\\\\");
 
-  for (i = 0; i < 200; i++)
-  {
-    char *s;
-    const char *ss;
+    for (i = 0; i < 200; i++)
+    {
+        char *s;
+        const char *ss;
 
-    s = get_random_string ();
+        s = get_random_string ();
 
-    ss = sqlEscapeString (escape, s);
-    sqlEscapeString (escape, ss);
+        ss = sqlEscapeString (escape, s);
+        sqlEscapeString (escape, ss);
 
-    g_free (s);
-  }
+        g_free (s);
+    }
 
-  success ("crash test");
+    success ("crash test");
 
-  sqlEscape_destroy (escape);
+    sqlEscape_destroy (escape);
 
-  print_test_results ();
-  exit (get_rv ());
+    print_test_results ();
+    exit (get_rv ());
 }

Modified: gnucash/trunk/src/backend/postgres/test/test-load-backend.c
===================================================================
--- gnucash/trunk/src/backend/postgres/test/test-load-backend.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/test/test-load-backend.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -24,8 +24,8 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  *  02110-1301, USA.
  */
- 
-#include "config.h" 
+
+#include "config.h"
 #include "qof.h"
 #include "cashobjects.h"
 #include "test-stuff.h"
@@ -34,13 +34,13 @@
 
 int main (int argc, char ** argv)
 {
-	qof_init();
-	cashobjects_register();
-	/* the test needs to run locally in case make install
-	 * has not yet been run. Use GNC_LIBDIR usually. */
-	do_test(qof_load_backend_library ("../.libs/", PG_LIB_NAME),
-		" loading gnc-backend-postgres GModule failed");
-	print_test_results();
-	qof_close();
-	return 0;
+    qof_init();
+    cashobjects_register();
+    /* the test needs to run locally in case make install
+     * has not yet been run. Use GNC_LIBDIR usually. */
+    do_test(qof_load_backend_library ("../.libs/", PG_LIB_NAME),
+            " loading gnc-backend-postgres GModule failed");
+    print_test_results();
+    qof_close();
+    return 0;
 }

Modified: gnucash/trunk/src/backend/postgres/test/test-period.c
===================================================================
--- gnucash/trunk/src/backend/postgres/test/test-period.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/test/test-period.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -15,14 +15,14 @@
  *  02110-1301, USA.
  */
 
-/* 
+/*
  * Test file created by Linas Vepstas <linas at linas.org>
  * Minimal test to see if a book can be split into two periods
  * without crashing.  Book is written to the database.
  * December 2001
  */
 
-#include "config.h" 
+#include "config.h"
 #include <ctype.h>
 #include <glib.h>
 #include <time.h>
@@ -39,126 +39,126 @@
 static void
 run_test (void)
 {
-  QofBackendError io_err;
-  QofSession *session;
-  QofBook *openbook, *closedbook;
-  GList *acclist, *anode;
-  Account *root, *acc = NULL;
-  SplitList *splist;
-  Split *sfirst, *slast;
-  Transaction *tfirst, *tlast;
-  Timespec tsfirst, tslast, tsmiddle;
-  char * test_url;
-  
-  do_test(qof_load_backend_library ("../.libs/", PG_LIB_NAME),
-          " loading gnc-backend-postgres GModule failed");
+    QofBackendError io_err;
+    QofSession *session;
+    QofBook *openbook, *closedbook;
+    GList *acclist, *anode;
+    Account *root, *acc = NULL;
+    SplitList *splist;
+    Split *sfirst, *slast;
+    Transaction *tfirst, *tlast;
+    Timespec tsfirst, tslast, tsmiddle;
+    char * test_url;
 
-  session = get_random_session ();
+    do_test(qof_load_backend_library ("../.libs/", PG_LIB_NAME),
+            " loading gnc-backend-postgres GModule failed");
 
-  test_url = "postgres://localhost/qqq?mode=single-update";
-  qof_session_begin (session, test_url, FALSE, TRUE);
+    session = get_random_session ();
 
-  io_err = qof_session_get_error (session);
-  g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
+    test_url = "postgres://localhost/qqq?mode=single-update";
+    qof_session_begin (session, test_url, FALSE, TRUE);
 
-  openbook = qof_session_get_book (session);
-  if (!openbook)
-  {
-    failure("book not created");
-    exit(get_rv());
-  }
+    io_err = qof_session_get_error (session);
+    g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
 
-  add_random_transactions_to_book (openbook, 12);
+    openbook = qof_session_get_book (session);
+    if (!openbook)
+    {
+        failure("book not created");
+        exit(get_rv());
+    }
 
-  root = gnc_book_get_root_account(openbook);
+    add_random_transactions_to_book (openbook, 12);
 
-  acclist = gnc_account_get_descendants (root);
-  for (anode=acclist; anode; anode=anode->next)
-  {
-    int ns;
-    acc = anode->data;
-    ns = g_list_length (xaccAccountGetSplitList (acc));
-    if (2 <= ns) break;
-    acc = NULL;
-  }
-  g_list_free(acclist);
+    root = gnc_book_get_root_account(openbook);
 
-  if(!acc)
-  {
-    failure("group didn't have accounts with enough splits");
-    exit(get_rv());
-  }
+    acclist = gnc_account_get_descendants (root);
+    for (anode = acclist; anode; anode = anode->next)
+    {
+        int ns;
+        acc = anode->data;
+        ns = g_list_length (xaccAccountGetSplitList (acc));
+        if (2 <= ns) break;
+        acc = NULL;
+    }
+    g_list_free(acclist);
 
-  splist = xaccAccountGetSplitList(acc);
-  if(!splist)
-  {
-    failure("account has no transactions");
-    exit(get_rv());
-  }
+    if (!acc)
+    {
+        failure("group didn't have accounts with enough splits");
+        exit(get_rv());
+    }
 
-  sfirst = splist->data;
-  slast = g_list_last(splist) ->data;
-  if (sfirst == slast)
-  {
-    failure("account doesn't have enough transactions");
-    exit(get_rv());
-  }
+    splist = xaccAccountGetSplitList(acc);
+    if (!splist)
+    {
+        failure("account has no transactions");
+        exit(get_rv());
+    }
 
-  tfirst = xaccSplitGetParent (sfirst);
-  tlast = xaccSplitGetParent (slast);
-  
-  if (!tfirst || !tlast)
-  {
-    failure("malformed transactions in account");
-    exit(get_rv());
-  }
+    sfirst = splist->data;
+    slast = g_list_last(splist) ->data;
+    if (sfirst == slast)
+    {
+        failure("account doesn't have enough transactions");
+        exit(get_rv());
+    }
 
-  tsfirst = xaccTransRetDatePostedTS (tfirst);
-  tslast = xaccTransRetDatePostedTS (tlast);
+    tfirst = xaccSplitGetParent (sfirst);
+    tlast = xaccSplitGetParent (slast);
 
-  if (tsfirst.tv_sec == tslast.tv_sec)
-  {
-    failure("transactions not time separated");
-    exit(get_rv());
-  }
+    if (!tfirst || !tlast)
+    {
+        failure("malformed transactions in account");
+        exit(get_rv());
+    }
 
-  tsmiddle = tsfirst;
-  tsmiddle.tv_sec = (tsfirst.tv_sec + tslast.tv_sec)/2;
+    tsfirst = xaccTransRetDatePostedTS (tfirst);
+    tslast = xaccTransRetDatePostedTS (tlast);
 
-  qof_session_save (session, NULL);
-  io_err = qof_session_get_error (session);
-  g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
+    if (tsfirst.tv_sec == tslast.tv_sec)
+    {
+        failure("transactions not time separated");
+        exit(get_rv());
+    }
 
-  qof_log_set_file (stdout);
-  qof_log_set_level("gnc", G_LOG_LEVEL_INFO);
+    tsmiddle = tsfirst;
+    tsmiddle.tv_sec = (tsfirst.tv_sec + tslast.tv_sec) / 2;
 
-  closedbook = gnc_book_close_period (openbook, tsmiddle, 
-                  NULL, "this is opening balance dude");
+    qof_session_save (session, NULL);
+    io_err = qof_session_get_error (session);
+    g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
 
-  if (!closedbook)
-  {
-    failure("closed book not created");
-    exit(get_rv());
-  }
+    qof_log_set_file (stdout);
+    qof_log_set_level("gnc", G_LOG_LEVEL_INFO);
 
-  qof_session_save (session, NULL);
-  io_err = qof_session_get_error (session);
-  g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
+    closedbook = gnc_book_close_period (openbook, tsmiddle,
+                                        NULL, "this is opening balance dude");
 
-  qof_session_end (session);
-  io_err = qof_session_get_error (session);
-  g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
+    if (!closedbook)
+    {
+        failure("closed book not created");
+        exit(get_rv());
+    }
 
-  success ("periods lightly tested and seem to work");
+    qof_session_save (session, NULL);
+    io_err = qof_session_get_error (session);
+    g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
+
+    qof_session_end (session);
+    io_err = qof_session_get_error (session);
+    g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
+
+    success ("periods lightly tested and seem to work");
 }
 
 int
 main (int argc, char **argv)
 {
-  qof_init();
-  run_test ();
+    qof_init();
+    run_test ();
 
-  print_test_results();
-  qof_close();
-  return 0;
+    print_test_results();
+    qof_close();
+    return 0;
 }

Modified: gnucash/trunk/src/backend/postgres/txn.c
===================================================================
--- gnucash/trunk/src/backend/postgres/txn.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/txn.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -23,12 +23,12 @@
 #include "config.h"
 
 #include <glib.h>
-#include <stdio.h>  
+#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>  
+#include <string.h>
 
-#include <libpq-fe.h>  
- 
+#include <libpq-fe.h>
+
 #include "Account.h"
 #include "AccountP.h"
 #include "gnc-commodity.h"
@@ -36,7 +36,7 @@
 #include "gnc-pricedb.h"
 #include "Transaction.h"
 #include "TransactionP.h"
- 
+
 #include "PostgresBackend.h"
 #include "account.h"
 #include "base-autogen.h"
@@ -54,41 +54,41 @@
 /*            TRANSACTION STUFF                                  */
 /* ============================================================= */
 /* ============================================================= */
-/* The is_trans_empty() routine returns TRUE if this appears to 
- * be a fresh, 'null' transaction.  It would be better if somehow 
- * we could get the gui to mark this as a fresh transaction, rather 
- * than having to scan a bunch of fields.  But, oh well, this is 
+/* The is_trans_empty() routine returns TRUE if this appears to
+ * be a fresh, 'null' transaction.  It would be better if somehow
+ * we could get the gui to mark this as a fresh transaction, rather
+ * than having to scan a bunch of fields.  But, oh well, this is
  * a minor quibble in the grand scheme of things.
  */
 
 static gboolean
 is_trans_empty (Transaction *trans)
 {
-   Split *s;
-   if (!trans) return TRUE;
-   if (0 != (xaccTransGetDescription(trans))[0]) return FALSE;
-   if (0 != (xaccTransGetNum(trans))[0]) return FALSE;
-   if (1 != xaccTransCountSplits(trans)) return FALSE;
+    Split *s;
+    if (!trans) return TRUE;
+    if (0 != (xaccTransGetDescription(trans))[0]) return FALSE;
+    if (0 != (xaccTransGetNum(trans))[0]) return FALSE;
+    if (1 != xaccTransCountSplits(trans)) return FALSE;
 
-   s = xaccTransGetSplit(trans, 0);
-   if (TRUE != gnc_numeric_zero_p(xaccSplitGetAmount(s))) return FALSE;
-   if (TRUE != gnc_numeric_zero_p(xaccSplitGetValue(s))) return FALSE;
-   if ('n' != xaccSplitGetReconcile(s)) return FALSE;
-   if (0 != (xaccSplitGetMemo(s))[0]) return FALSE;
-   if (0 != (xaccSplitGetAction(s))[0]) return FALSE;
-   if (TRUE != (kvp_frame_is_empty (xaccSplitGetSlots(s)))) return FALSE;
-   return TRUE;
+    s = xaccTransGetSplit(trans, 0);
+    if (TRUE != gnc_numeric_zero_p(xaccSplitGetAmount(s))) return FALSE;
+    if (TRUE != gnc_numeric_zero_p(xaccSplitGetValue(s))) return FALSE;
+    if ('n' != xaccSplitGetReconcile(s)) return FALSE;
+    if (0 != (xaccSplitGetMemo(s))[0]) return FALSE;
+    if (0 != (xaccSplitGetAction(s))[0]) return FALSE;
+    if (TRUE != (kvp_frame_is_empty (xaccSplitGetSlots(s)))) return FALSE;
+    return TRUE;
 }
 
 /* ============================================================= */
-/* The pgendStoreTransactionNoLock() routine traverses the transaction 
- * structure and stores/updates it in the database.  If checks the 
+/* The pgendStoreTransactionNoLock() routine traverses the transaction
+ * structure and stores/updates it in the database.  If checks the
  * transaction splits as well, updating those.  If the database
- * has splits which the transaction doesn't, those are deleted.  
+ * has splits which the transaction doesn't, those are deleted.
  * Then any new splits are poked into the database.
  *
  * If the do_check_version flag is set, then the database version
- * is compared to the engine version.  If the database version is 
+ * is compared to the engine version.  If the database version is
  * newer, then the engine transaction is not stored.
  *
  * The pgendStoreTransaction() routine does the same, except that
@@ -97,204 +97,207 @@
 
 typedef struct
 {
-  GUID guid;
-  char *guid_str;
-  guint32 iguid;
+    GUID guid;
+    char *guid_str;
+    guint32 iguid;
 } DeleteTransInfo;
 
 static gpointer
 delete_list_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   GList * deletelist = (GList *) data;
-   GUID guid = nullguid;
+    GList * deletelist = (GList *) data;
+    GUID guid = nullguid;
 
-   string_to_guid (DB_GET_VAL ("splitGuid", j), &guid);
+    string_to_guid (DB_GET_VAL ("splitGuid", j), &guid);
 
-   /* If the database has splits that the engine doesn't,
-    * collect 'em up & we'll have to delete em */
-   if (NULL == pgendSplitLookup (be, &guid))
-   {
-      DeleteTransInfo *dti;
+    /* If the database has splits that the engine doesn't,
+     * collect 'em up & we'll have to delete em */
+    if (NULL == pgendSplitLookup (be, &guid))
+    {
+        DeleteTransInfo *dti;
 
-      dti = g_new (DeleteTransInfo, 1);
+        dti = g_new (DeleteTransInfo, 1);
 
-      dti->guid = guid;
-      dti->guid_str = g_strdup (DB_GET_VAL ("splitGuid", j));
-      dti->iguid = atoi (DB_GET_VAL ("iguid", j));
+        dti->guid = guid;
+        dti->guid_str = g_strdup (DB_GET_VAL ("splitGuid", j));
+        dti->iguid = atoi (DB_GET_VAL ("iguid", j));
 
-      deletelist = g_list_prepend (deletelist, dti);
-   }
+        deletelist = g_list_prepend (deletelist, dti);
+    }
 
-   return deletelist;
+    return deletelist;
 }
 
 void
 pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans,
                              gboolean do_check_version)
 {
-   GList *start, *deletelist=NULL, *node;
-   guint32 s_idata, t_idata;
-   char * p;
+    GList *start, *deletelist = NULL, *node;
+    guint32 s_idata, t_idata;
+    char * p;
 
-   if (!be || !trans) return;
-   ENTER ("trans=%p do_check=%d", trans, do_check_version);
+    if (!be || !trans) return;
+    ENTER ("trans=%p do_check=%d", trans, do_check_version);
 
-   /* don't update the database if the database is newer ... */
-   if (do_check_version)
-   {
-      if (0 < pgendTransactionCompareVersion (be, trans)) return;
-   }
-   /* be sure to update the version !! */
-   qof_instance_increment_version(trans, be->version_check);
+    /* don't update the database if the database is newer ... */
+    if (do_check_version)
+    {
+        if (0 < pgendTransactionCompareVersion (be, trans)) return;
+    }
+    /* be sure to update the version !! */
+    qof_instance_increment_version(trans, be->version_check);
 
-   /* first, we need to see which splits are in the database
-    * since what is there may not match what we have cached in 
-    * the engine. */
-   p = be->buff; *p = 0;
-   p = stpcpy (p, "SELECT splitGuid, iguid FROM gncSplit WHERE transGuid='");
-   p = guid_to_string_buff(xaccTransGetGUID(trans), p);
-   p = stpcpy (p, "';");
+    /* first, we need to see which splits are in the database
+     * since what is there may not match what we have cached in
+     * the engine. */
+    p = be->buff;
+    *p = 0;
+    p = stpcpy (p, "SELECT splitGuid, iguid FROM gncSplit WHERE transGuid='");
+    p = guid_to_string_buff(xaccTransGetGUID(trans), p);
+    p = stpcpy (p, "';");
 
-   SEND_QUERY (be,be->buff, );
-   deletelist = pgendGetResults (be, delete_list_cb, deletelist);
+    SEND_QUERY (be, be->buff, );
+    deletelist = pgendGetResults (be, delete_list_cb, deletelist);
 
-   /* delete those splits that don't belong */
-   p = be->buff; *p = 0;
-   for (node=deletelist; node; node=node->next)
-   {
-      DeleteTransInfo *dti = node->data;
-      GList *split_node;
+    /* delete those splits that don't belong */
+    p = be->buff;
+    *p = 0;
+    for (node = deletelist; node; node = node->next)
+    {
+        DeleteTransInfo *dti = node->data;
+        GList *split_node;
 
-      /* find the old split in the saved original */
-      if (trans->orig && trans->orig->splits)
-        for (split_node = trans->orig->splits; split_node;
-             split_node = split_node->next)
-        {
-          Split *s = split_node->data;
+        /* find the old split in the saved original */
+        if (trans->orig && trans->orig->splits)
+            for (split_node = trans->orig->splits; split_node;
+                    split_node = split_node->next)
+            {
+                Split *s = split_node->data;
 
-          if (s && guid_equal (qof_instance_get_guid(s), &dti->guid))
-          {
-            pgendStoreAuditSplit (be, s, SQL_DELETE);
-            break;
-          }
-        }
+                if (s && guid_equal (qof_instance_get_guid(s), &dti->guid))
+                {
+                    pgendStoreAuditSplit (be, s, SQL_DELETE);
+                    break;
+                }
+            }
 
-      p = stpcpy (p, "DELETE FROM gncSplit WHERE splitGuid='");
-      p = stpcpy (p, dti->guid_str);
-      p = stpcpy (p, "';\n");
-   }
+        p = stpcpy (p, "DELETE FROM gncSplit WHERE splitGuid='");
+        p = stpcpy (p, dti->guid_str);
+        p = stpcpy (p, "';\n");
+    }
 
-   if (p != be->buff)
-   {
-      PINFO ("%s", be->buff ? be->buff : "(null)");
-      SEND_QUERY (be,be->buff, );
-      FINISH_QUERY(be->connection);
+    if (p != be->buff)
+    {
+        PINFO ("%s", be->buff ? be->buff : "(null)");
+        SEND_QUERY (be, be->buff, );
+        FINISH_QUERY(be->connection);
 
-      /* destroy any associated kvp data as well */
-      for (node=deletelist; node; node=node->next)
-      {
-         DeleteTransInfo *dti = node->data;
+        /* destroy any associated kvp data as well */
+        for (node = deletelist; node; node = node->next)
+        {
+            DeleteTransInfo *dti = node->data;
 
-         pgendKVPDelete (be, dti->iguid);
-      }
-   }
+            pgendKVPDelete (be, dti->iguid);
+        }
+    }
 
-   for (node = deletelist; node; node = node->next)
-   {
-     DeleteTransInfo *dti = node->data;
+    for (node = deletelist; node; node = node->next)
+    {
+        DeleteTransInfo *dti = node->data;
 
-     g_free (dti->guid_str);
-     g_free (dti);
-   }
-   g_list_free (deletelist);
-   deletelist = NULL;
+        g_free (dti->guid_str);
+        g_free (dti);
+    }
+    g_list_free (deletelist);
+    deletelist = NULL;
 
-   /* Update the rest */
-   start = xaccTransGetSplitList(trans);
+    /* Update the rest */
+    start = xaccTransGetSplitList(trans);
 
-   PINFO ("split-list=%p, destroying=%d", start,
-          qof_instance_get_destroying(trans));
-   if ((start) && !qof_instance_get_destroying(trans))
-   {
-      gnc_commodity *com;
+    PINFO ("split-list=%p, destroying=%d", start,
+           qof_instance_get_destroying(trans));
+    if ((start) && !qof_instance_get_destroying(trans))
+    {
+        gnc_commodity *com;
 
-      for (node=start; node; node=node->next) 
-      {
-         Split * s = node->data;
-         s_idata = qof_instance_get_idata(s);
-         if ((0 == s_idata) &&
-             (FALSE == kvp_frame_is_empty (xaccSplitGetSlots(s))))
-         {
-            s_idata = pgendNewGUIDidx(be);
-            qof_instance_set_idata(s, s_idata);
-         }
-         pgendPutOneSplitOnly (be, s);
-         if (s_idata)
-         {
-           pgendKVPDelete (be, s_idata);
-           pgendKVPStore (be, s_idata, s->inst.kvp_data);
-         }
-      }
+        for (node = start; node; node = node->next)
+        {
+            Split * s = node->data;
+            s_idata = qof_instance_get_idata(s);
+            if ((0 == s_idata) &&
+                    (FALSE == kvp_frame_is_empty (xaccSplitGetSlots(s))))
+            {
+                s_idata = pgendNewGUIDidx(be);
+                qof_instance_set_idata(s, s_idata);
+            }
+            pgendPutOneSplitOnly (be, s);
+            if (s_idata)
+            {
+                pgendKVPDelete (be, s_idata);
+                pgendKVPStore (be, s_idata, s->inst.kvp_data);
+            }
+        }
 
-      t_idata = qof_instance_get_idata(trans);
-      if ((0 == t_idata) &&
-          (FALSE == kvp_frame_is_empty (xaccTransGetSlots(trans))))
-      {
-         t_idata = pgendNewGUIDidx(be);
-         qof_instance_set_idata(trans, t_idata);
-      }
+        t_idata = qof_instance_get_idata(trans);
+        if ((0 == t_idata) &&
+                (FALSE == kvp_frame_is_empty (xaccTransGetSlots(trans))))
+        {
+            t_idata = pgendNewGUIDidx(be);
+            qof_instance_set_idata(trans, t_idata);
+        }
 
-      /* Make sure the commodity is in the table.
-       * See account.c for why this might be bad. */
-      com = xaccTransGetCurrency (trans);
-      pgendPutOneCommodityOnly (be, com);
+        /* Make sure the commodity is in the table.
+         * See account.c for why this might be bad. */
+        com = xaccTransGetCurrency (trans);
+        pgendPutOneCommodityOnly (be, com);
 
-      pgendPutOneTransactionOnly (be, trans);
+        pgendPutOneTransactionOnly (be, trans);
 
-      if (t_idata)
-      {
-        pgendKVPDelete (be, t_idata);
-        pgendKVPStore (be, t_idata, trans->inst.kvp_data);
-      }
-   }
-   else
-   {
-      p = be->buff; *p = 0;
-      for (node=start; node; node=node->next) 
-      {
-         Split * s = node->data;
-         pgendStoreAuditSplit (be, s, SQL_DELETE);
-         p = stpcpy (p, "DELETE FROM gncSplit WHERE splitGuid='");
-         p = guid_to_string_buff (xaccSplitGetGUID(s), p);
-         p = stpcpy (p, "';\n");
-      }
- 
-      /* If this trans is marked for deletetion, use the 'orig' values
-       * as the base for recording the audit.  This wouldn't be normally
-       * required, except that otherwise one gets a trashed currency 
-       * value.
-       */
-      pgendStoreAuditTransaction (be, trans->orig, SQL_DELETE);
-      p = be->buff; 
-      p = stpcpy (p, "DELETE FROM gncTransaction WHERE transGuid='");
-      p = guid_to_string_buff (xaccTransGetGUID(trans), p);
-      p = stpcpy (p, "';");
-      PINFO ("%s\n", be->buff ? be->buff : "(null)");
-      SEND_QUERY (be,be->buff, );
-      FINISH_QUERY(be->connection);
+        if (t_idata)
+        {
+            pgendKVPDelete (be, t_idata);
+            pgendKVPStore (be, t_idata, trans->inst.kvp_data);
+        }
+    }
+    else
+    {
+        p = be->buff;
+        *p = 0;
+        for (node = start; node; node = node->next)
+        {
+            Split * s = node->data;
+            pgendStoreAuditSplit (be, s, SQL_DELETE);
+            p = stpcpy (p, "DELETE FROM gncSplit WHERE splitGuid='");
+            p = guid_to_string_buff (xaccSplitGetGUID(s), p);
+            p = stpcpy (p, "';\n");
+        }
 
-      /* destroy any associated kvp data as well */
-      for (node=start; node; node=node->next) 
-      {
-         Split * s = node->data;
-         s_idata = qof_instance_get_idata(s);
-         if (0 != s_idata) pgendKVPDelete (be, s_idata);
-      }
-      t_idata = qof_instance_get_idata(trans);
-      if (0 != t_idata) pgendKVPDelete (be, t_idata);
-   }
+        /* If this trans is marked for deletetion, use the 'orig' values
+         * as the base for recording the audit.  This wouldn't be normally
+         * required, except that otherwise one gets a trashed currency
+         * value.
+         */
+        pgendStoreAuditTransaction (be, trans->orig, SQL_DELETE);
+        p = be->buff;
+        p = stpcpy (p, "DELETE FROM gncTransaction WHERE transGuid='");
+        p = guid_to_string_buff (xaccTransGetGUID(trans), p);
+        p = stpcpy (p, "';");
+        PINFO ("%s\n", be->buff ? be->buff : "(null)");
+        SEND_QUERY (be, be->buff, );
+        FINISH_QUERY(be->connection);
 
-   LEAVE(" ");
+        /* destroy any associated kvp data as well */
+        for (node = start; node; node = node->next)
+        {
+            Split * s = node->data;
+            s_idata = qof_instance_get_idata(s);
+            if (0 != s_idata) pgendKVPDelete (be, s_idata);
+        }
+        t_idata = qof_instance_get_idata(trans);
+        if (0 != t_idata) pgendKVPDelete (be, t_idata);
+    }
+
+    LEAVE(" ");
 }
 
 #if 0
@@ -305,40 +308,40 @@
 static void
 pgendStoreTransaction (PGBackend *be, Transaction *trans)
 {
-   char * bufp;
-   if (!be || !trans) return;
-   ENTER ("be=%p, trans=%p", be, trans);
+    char * bufp;
+    if (!be || !trans) return;
+    ENTER ("be=%p, trans=%p", be, trans);
 
-   /* lock it up so that we store atomically */
-   bufp = "BEGIN;\n"
-          "LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n"
-          "LOCK TABLE gncSplit IN EXCLUSIVE MODE;\n";
-   SEND_QUERY (be,bufp, );
-   FINISH_QUERY(be->connection);
+    /* lock it up so that we store atomically */
+    bufp = "BEGIN;\n"
+           "LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n"
+           "LOCK TABLE gncSplit IN EXCLUSIVE MODE;\n";
+    SEND_QUERY (be, bufp, );
+    FINISH_QUERY(be->connection);
 
-   pgendStoreTransactionNoLock (be, trans, TRUE);
+    pgendStoreTransactionNoLock (be, trans, TRUE);
 
-   bufp = "COMMIT;\n"
-          "NOTIFY  gncTransaction;";
-   SEND_QUERY (be,bufp, );
-   FINISH_QUERY(be->connection);
+    bufp = "COMMIT;\n"
+           "NOTIFY  gncTransaction;";
+    SEND_QUERY (be, bufp, );
+    FINISH_QUERY(be->connection);
 
-   /* If this is the multi-user mode, we need to update the
-    * balances as well.  */
-   if ((MODE_POLL == be->session_mode) ||
-       (MODE_EVENT == be->session_mode))
-   {
-      /* hack alert --  we should also recompute
-       * the checkpoints for any accounts from which splits have
-       * been deleted ... but we don't have these handy here ...
-       * is this is actually kinda wrong ...
-       */
-      pgendTransactionRecomputeCheckpoints (be, trans);
-   }
+    /* If this is the multi-user mode, we need to update the
+     * balances as well.  */
+    if ((MODE_POLL == be->session_mode) ||
+            (MODE_EVENT == be->session_mode))
+    {
+        /* hack alert --  we should also recompute
+         * the checkpoints for any accounts from which splits have
+         * been deleted ... but we don't have these handy here ...
+         * is this is actually kinda wrong ...
+         */
+        pgendTransactionRecomputeCheckpoints (be, trans);
+    }
 
-   LEAVE(" ");
+    LEAVE(" ");
 }
- #endif
+#endif
 
 /* ============================================================= */
 /* The pgendStoreAllTransactions() routine traverses through *all*
@@ -350,65 +353,65 @@
 static int
 trans_traverse_cb (Transaction *trans, void *cb_data)
 {
-   pgendStoreTransactionNoLock ((PGBackend *) cb_data, trans, TRUE);
-   return 0;
+    pgendStoreTransactionNoLock ((PGBackend *) cb_data, trans, TRUE);
+    return 0;
 }
 
 
 void
 pgendStoreAllTransactions (PGBackend *be, Account *root)
 {
-   char *p;
-   ENTER ("be=%p, root=%p", be, root);
-   if (!be || !root) return;
+    char *p;
+    ENTER ("be=%p, root=%p", be, root);
+    if (!be || !root) return;
 
-   /* lock it up so that we store atomically */
-   p = "BEGIN;\n"
-       "LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncSplit IN EXCLUSIVE MODE;\n";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    /* lock it up so that we store atomically */
+    p = "BEGIN;\n"
+        "LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncSplit IN EXCLUSIVE MODE;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   /* Recursively walk transactions. Start by reseting the write 
-    * flags. We use this to avoid infinite recursion */
-   gnc_account_tree_begin_staged_transaction_traversals(root);
-   gnc_account_tree_staged_transaction_traversal (root, 1, trans_traverse_cb, be);
+    /* Recursively walk transactions. Start by reseting the write
+     * flags. We use this to avoid infinite recursion */
+    gnc_account_tree_begin_staged_transaction_traversals(root);
+    gnc_account_tree_staged_transaction_traversal (root, 1, trans_traverse_cb, be);
 
-   p = "COMMIT;\n"
-       "NOTIFY gncTransaction;";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    p = "COMMIT;\n"
+        "NOTIFY gncTransaction;";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   /* If this is the multi-user mode, we need to update the
-    * balances as well.  */
-   if ((MODE_POLL == be->session_mode) ||
-       (MODE_EVENT == be->session_mode))
-   {
-      pgendAccountTreeRecomputeAllCheckpoints(be, root);
-   }
-   LEAVE(" ");
+    /* If this is the multi-user mode, we need to update the
+     * balances as well.  */
+    if ((MODE_POLL == be->session_mode) ||
+            (MODE_EVENT == be->session_mode))
+    {
+        pgendAccountTreeRecomputeAllCheckpoints(be, root);
+    }
+    LEAVE(" ");
 }
 
 /* ============================================================= */
-/* 
- * The pgendCopyTransactionToEngine() routine 'copies' data out of 
- *    the SQL database and into the engine, for the indicated 
+/*
+ * The pgendCopyTransactionToEngine() routine 'copies' data out of
+ *    the SQL database and into the engine, for the indicated
  *    Transaction GUID.  It starts by looking for an existing
  *    transaction in the engine with such a GUID.  If found, then
  *    it compares the version of last update to what's in the sql DB.
- *    If the engine data is older, or the engine doesn't yet have 
+ *    If the engine data is older, or the engine doesn't yet have
  *    this transaction, then the full update happens.  The full
  *    update sets up the transaction structure, all of the splits
- *    in the transaction, and makes sure that all of the splits 
+ *    in the transaction, and makes sure that all of the splits
  *    are in the proper accounts.  If the pre-existing tranasaction
  *    in the engine has more splits than what's in the DB, then these
- *    are pruned so that the structure exactly matches what's in the 
+ *    are pruned so that the structure exactly matches what's in the
  *    DB.  This routine then returns -1.
  *
  *    If this routine finds a pre-existing transaction in the engine,
- *    and the version of last modification of this transaction is 
+ *    and the version of last modification of this transaction is
  *    equal to or *newer* then what the DB holds, then this routine
- *    returns 0 if equal, and +1 if newer, and does *not* perform any 
+ *    returns 0 if equal, and +1 if newer, and does *not* perform any
  *    update.  (Note that 0 is returned for various error conditions.
  *    Thus, testing for 0 is a bad idea.  This is a hack, and should
  *    probably be fixed.
@@ -416,429 +419,437 @@
 
 typedef struct
 {
-  Split * split;
-  GUID account_guid;
-  gint64 amount;
+    Split * split;
+    GUID account_guid;
+    gint64 amount;
 } SplitResolveInfo;
 
-void 
+void
 pgendCopySplitsToEngine (PGBackend *be, Transaction *trans)
 {
-   char *pbuff;
-   int i, j, nrows;
-   PGresult *result;
-   const GUID *trans_guid;
-   Account *acc, *previous_acc=NULL;
-   GList *node, *db_splits=NULL, *engine_splits, *delete_splits=NULL;
-   GList *unresolved_splits = NULL;
-   gnc_commodity *currency = NULL;
-   gint64 trans_frac = 0;
+    char *pbuff;
+    int i, j, nrows;
+    PGresult *result;
+    const GUID *trans_guid;
+    Account *acc, *previous_acc = NULL;
+    GList *node, *db_splits = NULL, *engine_splits, *delete_splits = NULL;
+    GList *unresolved_splits = NULL;
+    gnc_commodity *currency = NULL;
+    gint64 trans_frac = 0;
 
-   trans_guid = xaccTransGetGUID (trans);
-   currency = xaccTransGetCurrency (trans);
-   trans_frac = gnc_commodity_get_fraction (currency);
+    trans_guid = xaccTransGetGUID (trans);
+    currency = xaccTransGetCurrency (trans);
+    trans_frac = gnc_commodity_get_fraction (currency);
 
-   /* build the sql query the splits */
-   pbuff = be->buff;
-   pbuff[0] = 0;
-   pbuff = stpcpy (pbuff, 
-                   "SELECT * FROM gncSplit WHERE transGuid='");
-   pbuff = guid_to_string_buff(trans_guid, pbuff);
-   pbuff = stpcpy (pbuff, "';");
+    /* build the sql query the splits */
+    pbuff = be->buff;
+    pbuff[0] = 0;
+    pbuff = stpcpy (pbuff,
+                    "SELECT * FROM gncSplit WHERE transGuid='");
+    pbuff = guid_to_string_buff(trans_guid, pbuff);
+    pbuff = stpcpy (pbuff, "';");
 
-   SEND_QUERY (be,be->buff, );
-   i=0; nrows=0;
-   do {
-      GET_RESULTS (be->connection, result);
-      {
-         int j, jrows;
-         int ncols = PQnfields (result);
-         jrows = PQntuples (result);
-         nrows += jrows;
-         PINFO ("query result %d has %d rows and %d cols",
-                i, nrows, ncols);
+    SEND_QUERY (be, be->buff, );
+    i = 0;
+    nrows = 0;
+    do
+    {
+        GET_RESULTS (be->connection, result);
+        {
+            int j, jrows;
+            int ncols = PQnfields (result);
+            jrows = PQntuples (result);
+            nrows += jrows;
+            PINFO ("query result %d has %d rows and %d cols",
+                   i, nrows, ncols);
 
-         for (j=0; j<jrows; j++)
-         {
-            Split *s;
-            GUID guid;
-            Timespec ts;
-            gint64 num;
-            gnc_numeric value, amount;
-
-            /* --------------------------------------------- */
-            /* first, lets see if we've already got this one */
-            PINFO ("split GUID=%s", DB_GET_VAL("splitGuid",j));
-            guid = nullguid;  /* just in case the read fails ... */
-            string_to_guid (DB_GET_VAL("splitGuid",j), &guid);
-            s = pgendSplitLookup (be, &guid);
-            if (!s)
+            for (j = 0; j < jrows; j++)
             {
-               s = xaccMallocSplit(qof_instance_get_book(trans));
-               xaccSplitSetGUID(s, &guid);
-            }
+                Split *s;
+                GUID guid;
+                Timespec ts;
+                gint64 num;
+                gnc_numeric value, amount;
 
-            /* next, restore all split data */
-            xaccSplitSetMemo(s, DB_GET_VAL("memo",j));
-            xaccSplitSetAction(s, DB_GET_VAL("action",j));
-            ts = gnc_iso8601_to_timespec_gmt
-              (DB_GET_VAL("date_reconciled",j));
-            xaccSplitSetDateReconciledTS (s, &ts);
+                /* --------------------------------------------- */
+                /* first, lets see if we've already got this one */
+                PINFO ("split GUID=%s", DB_GET_VAL("splitGuid", j));
+                guid = nullguid;  /* just in case the read fails ... */
+                string_to_guid (DB_GET_VAL("splitGuid", j), &guid);
+                s = pgendSplitLookup (be, &guid);
+                if (!s)
+                {
+                    s = xaccMallocSplit(qof_instance_get_book(trans));
+                    xaccSplitSetGUID(s, &guid);
+                }
 
-            xaccSplitSetReconcile (s, (DB_GET_VAL("reconciled", j))[0]);
-            qof_instance_set_idata(s, atoi(DB_GET_VAL("iguid",j)));
+                /* next, restore all split data */
+                xaccSplitSetMemo(s, DB_GET_VAL("memo", j));
+                xaccSplitSetAction(s, DB_GET_VAL("action", j));
+                ts = gnc_iso8601_to_timespec_gmt
+                     (DB_GET_VAL("date_reconciled", j));
+                xaccSplitSetDateReconciledTS (s, &ts);
 
-            /* --------------------------------------------- */
-            /* next, find the account that this split goes into */
-            guid = nullguid;  /* just in case the read fails ... */
-            string_to_guid (DB_GET_VAL("accountGUID",j), &guid);
-            acc = pgendAccountLookup (be, &guid);
+                xaccSplitSetReconcile (s, (DB_GET_VAL("reconciled", j))[0]);
+                qof_instance_set_idata(s, atoi(DB_GET_VAL("iguid", j)));
 
-            if (!acc)
-            {
-              SplitResolveInfo *sri = g_new0 (SplitResolveInfo, 1);
+                /* --------------------------------------------- */
+                /* next, find the account that this split goes into */
+                guid = nullguid;  /* just in case the read fails ... */
+                string_to_guid (DB_GET_VAL("accountGUID", j), &guid);
+                acc = pgendAccountLookup (be, &guid);
 
-              sri->split = s;
-              sri->account_guid = guid;
-              sri->amount = strtoll (DB_GET_VAL("amount", j), NULL, 0);
+                if (!acc)
+                {
+                    SplitResolveInfo *sri = g_new0 (SplitResolveInfo, 1);
 
-              unresolved_splits = g_list_prepend (unresolved_splits, sri);
-            }
+                    sri->split = s;
+                    sri->account_guid = guid;
+                    sri->amount = strtoll (DB_GET_VAL("amount", j), NULL, 0);
 
-            xaccTransAppendSplit (trans, s);
+                    unresolved_splits = g_list_prepend (unresolved_splits, sri);
+                }
 
-            if (acc)
-            {
-              if (acc != previous_acc)
-              {
-                xaccAccountCommitEdit (previous_acc);
-                xaccAccountBeginEdit (acc);
-                previous_acc = acc;
-              }
+                xaccTransAppendSplit (trans, s);
 
-              xaccAccountInsertSplit(acc, s);
-            }
+                if (acc)
+                {
+                    if (acc != previous_acc)
+                    {
+                        xaccAccountCommitEdit (previous_acc);
+                        xaccAccountBeginEdit (acc);
+                        previous_acc = acc;
+                    }
 
-            /* It's ok to set value without an account, since
-             * the fraction depends on the transaction and not
-             * the account. */
-            num = strtoll (DB_GET_VAL("value", j), NULL, 0);
-            value = gnc_numeric_create (num, trans_frac);
-            xaccSplitSetValue (s, value);
+                    xaccAccountInsertSplit(acc, s);
+                }
 
-            if (acc)
-            {
-              int acct_frac;
+                /* It's ok to set value without an account, since
+                 * the fraction depends on the transaction and not
+                 * the account. */
+                num = strtoll (DB_GET_VAL("value", j), NULL, 0);
+                value = gnc_numeric_create (num, trans_frac);
+                xaccSplitSetValue (s, value);
 
-              num = strtoll (DB_GET_VAL("amount", j), NULL, 0);
-              acct_frac = xaccAccountGetCommoditySCU (acc);
-              amount = gnc_numeric_create (num, acct_frac);
-              xaccSplitSetAmount (s, amount);
+                if (acc)
+                {
+                    int acct_frac;
+
+                    num = strtoll (DB_GET_VAL("amount", j), NULL, 0);
+                    acct_frac = xaccAccountGetCommoditySCU (acc);
+                    amount = gnc_numeric_create (num, acct_frac);
+                    xaccSplitSetAmount (s, amount);
+                }
+
+                /* finally tally them up; we use this below to
+                 * clean out deleted splits */
+                db_splits = g_list_prepend (db_splits, s);
             }
+        }
+        i++;
+        PQclear (result);
+    }
+    while (result);
 
-            /* finally tally them up; we use this below to 
-             * clean out deleted splits */
-            db_splits = g_list_prepend (db_splits, s);
-         }
-      }
-      i++;
-      PQclear (result);
-   } while (result);
+    /* close out dangling edit session */
+    xaccAccountCommitEdit (previous_acc);
 
-   /* close out dangling edit session */
-   xaccAccountCommitEdit (previous_acc);
+    /* resolve any splits that didn't have accounts */
+    for (node = unresolved_splits; node; node = node->next)
+    {
+        SplitResolveInfo * sri = node->data;
+        Account * account;
 
-   /* resolve any splits that didn't have accounts */
-   for (node = unresolved_splits; node; node = node->next)
-   {
-     SplitResolveInfo * sri = node->data;
-     Account * account;
+        /* account could have been pulled in by a previous
+         * iteration of this loop. */
+        account = pgendAccountLookup (be, &sri->account_guid);
 
-     /* account could have been pulled in by a previous
-      * iteration of this loop. */
-     account = pgendAccountLookup (be, &sri->account_guid);
+        if (!account)
+        {
+            account = pgendCopyAccountToEngine (be, &sri->account_guid);
+        }
 
-     if (!account)
-     {
-       account = pgendCopyAccountToEngine (be, &sri->account_guid);
-     }
+        if (account)
+        {
+            gnc_numeric amount;
+            int acct_frac;
 
-     if (account)
-     {
-       gnc_numeric amount;
-       int acct_frac;
+            xaccAccountBeginEdit (account);
+            xaccAccountInsertSplit (account, sri->split);
+            xaccAccountCommitEdit (account);
 
-       xaccAccountBeginEdit (account);
-       xaccAccountInsertSplit (account, sri->split);
-       xaccAccountCommitEdit (account);
+            acct_frac = xaccAccountGetCommoditySCU (account);
+            amount = gnc_numeric_create (sri->amount, acct_frac);
+            xaccSplitSetAmount (sri->split, amount);
+        }
+        else
+        {
+            gchar str1[GUID_ENCODING_LENGTH+1];
+            gchar str2[GUID_ENCODING_LENGTH+1];
 
-       acct_frac = xaccAccountGetCommoditySCU (account);
-       amount = gnc_numeric_create (sri->amount, acct_frac);
-       xaccSplitSetAmount (sri->split, amount);
-     }
-     else
-     {
-       gchar str1[GUID_ENCODING_LENGTH+1];
-       gchar str2[GUID_ENCODING_LENGTH+1];
+            guid_to_string_buff(xaccSplitGetGUID (sri->split), str1);
+            guid_to_string_buff(&sri->account_guid, str2);
 
-       guid_to_string_buff(xaccSplitGetGUID (sri->split), str1);
-       guid_to_string_buff(&sri->account_guid, str2);
+            PERR ("account not found, will delete this split\n"
+                  "\t(split with  guid=%s\n"
+                  "\twants an acct with guid=%s)\n",
+                  str1, str2);
 
-       PERR ("account not found, will delete this split\n"
-             "\t(split with  guid=%s\n" 
-             "\twants an acct with guid=%s)\n", 
-	     str1, str2);
+            /* Remove the split from the list */
+            db_splits = g_list_remove (db_splits, sri->split);
 
-       /* Remove the split from the list */
-       db_splits = g_list_remove (db_splits, sri->split);
+            xaccSplitDestroy (sri->split);
+        }
 
-       xaccSplitDestroy (sri->split);
-     }
+        g_free (sri);
+        node->data = NULL;
+    }
 
-     g_free (sri);
-     node->data = NULL;
-   }
+    g_list_free (unresolved_splits);
+    unresolved_splits = NULL;
 
-   g_list_free (unresolved_splits);
-   unresolved_splits = NULL;
+    /* ------------------------------------------------- */
+    /* destroy any splits that the engine has that the DB didn't */
 
-   /* ------------------------------------------------- */
-   /* destroy any splits that the engine has that the DB didn't */
+    i = 0;
+    j = 0;
+    engine_splits = xaccTransGetSplitList(trans);
+    for (node = engine_splits; node; node = node->next)
+    {
+        /* if not found, mark for deletion */
+        if (NULL == g_list_find (db_splits, node->data))
+        {
+            delete_splits = g_list_prepend (delete_splits, node->data);
+            j++;
+        }
+        i++;
+    }
+    PINFO ("%d of %d splits marked for deletion", j, i);
 
-   i=0; j=0;
-   engine_splits = xaccTransGetSplitList(trans);
-   for (node = engine_splits; node; node=node->next)
-   {
-      /* if not found, mark for deletion */
-      if (NULL == g_list_find (db_splits, node->data))
-      {
-         delete_splits = g_list_prepend (delete_splits, node->data);
-         j++;
-      }
-      i++;
-   }
-   PINFO ("%d of %d splits marked for deletion", j, i);
+    /* now, delete them ... */
+    for (node = delete_splits; node; node = node->next)
+    {
+        xaccSplitDestroy ((Split *) node->data);
+    }
+    g_list_free (delete_splits);
+    g_list_free (db_splits);
 
-   /* now, delete them ... */
-   for (node=delete_splits; node; node=node->next)
-   {
-      xaccSplitDestroy ((Split *) node->data);
-   }
-   g_list_free (delete_splits);
-   g_list_free (db_splits);
-
 }
 
 int
 pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid)
 {
-   char *pbuff;
-   Transaction *trans;
-   PGresult *result;
-   gboolean do_set_guid=FALSE;
-   int engine_data_is_newer = 0;
-   int j;
-   GList *node, *engine_splits;
-   guint32 s_idata, t_idata;
-   
-   ENTER ("be=%p", be);
-   if (!be || !trans_guid) return 0;
+    char *pbuff;
+    Transaction *trans;
+    PGresult *result;
+    gboolean do_set_guid = FALSE;
+    int engine_data_is_newer = 0;
+    int j;
+    GList *node, *engine_splits;
+    guint32 s_idata, t_idata;
 
-   /* disable callbacks into the backend, and events to GUI */
-   qof_event_suspend();
-   pgendDisable(be);
+    ENTER ("be=%p", be);
+    if (!be || !trans_guid) return 0;
 
-   /* first, see if we already have such a transaction */
-   trans = pgendTransLookup (be, trans_guid);
-   if (!trans)
-   {
-      trans = xaccMallocTransaction(be->book);
-      do_set_guid=TRUE;
-      engine_data_is_newer = -1;
-   }
-   else 
-   {
-      /* save some performance, don't go to the
-         backend if the data is recent. */
-      if (MAX_VERSION_AGE >= be->version_check - qof_instance_get_version_check(trans)) 
-      {
-         PINFO ("fresh data, skip check");
-         pgendEnable(be);
-         qof_event_resume();
-         return 0;
-      }
-   }
+    /* disable callbacks into the backend, and events to GUI */
+    qof_event_suspend();
+    pgendDisable(be);
 
-   /* build the sql query to get the transaction */
-   pbuff = be->buff;
-   pbuff[0] = 0;
-   pbuff = stpcpy (pbuff, "SELECT * FROM gncTransaction WHERE transGuid='");
-   pbuff = guid_to_string_buff(trans_guid, pbuff);
-   pbuff = stpcpy (pbuff, "';");
+    /* first, see if we already have such a transaction */
+    trans = pgendTransLookup (be, trans_guid);
+    if (!trans)
+    {
+        trans = xaccMallocTransaction(be->book);
+        do_set_guid = TRUE;
+        engine_data_is_newer = -1;
+    }
+    else
+    {
+        /* save some performance, don't go to the
+           backend if the data is recent. */
+        if (MAX_VERSION_AGE >= be->version_check - qof_instance_get_version_check(trans))
+        {
+            PINFO ("fresh data, skip check");
+            pgendEnable(be);
+            qof_event_resume();
+            return 0;
+        }
+    }
 
-   EXEC_QUERY (be->connection, be->buff, result);
-   if (!result)
-     return 0;
+    /* build the sql query to get the transaction */
+    pbuff = be->buff;
+    pbuff[0] = 0;
+    pbuff = stpcpy (pbuff, "SELECT * FROM gncTransaction WHERE transGuid='");
+    pbuff = guid_to_string_buff(trans_guid, pbuff);
+    pbuff = stpcpy (pbuff, "';");
 
-   {
-     int ncols = PQnfields (result);
-     int nrows = PQntuples (result);
+    EXEC_QUERY (be->connection, be->buff, result);
+    if (!result)
+        return 0;
 
-     PINFO ("query result has %d rows and %d cols", nrows, ncols);
+    {
+        int ncols = PQnfields (result);
+        int nrows = PQntuples (result);
 
-     j = 0;
-     if (0 == nrows) 
-     {
-       PQclear (result);
-       /* I beleive its a programming error to get this case.
-        * Print a warning for now... */
-       PERR ("no such transaction in the database. This is unexpected ...\n");
-       qof_backend_set_error (&be->be, ERR_SQL_MISSING_DATA);
-       pgendEnable(be);
-       qof_event_resume();
-       return 0;
-     }
+        PINFO ("query result has %d rows and %d cols", nrows, ncols);
 
-     if (1 < nrows)
-     {
-       /* since the guid is primary key, this error is totally
-        * and completely impossible, theoretically ... */
-       PERR ("!!!!!!!!!!!SQL database is corrupt!!!!!!!\n"
-             "too many transactions with GUID=%s\n",
-             guid_to_string (trans_guid));
-       qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT);
-       pgendEnable(be);
-       qof_event_resume();
-       return 0;
-     }
+        j = 0;
+        if (0 == nrows)
+        {
+            PQclear (result);
+            /* I beleive its a programming error to get this case.
+             * Print a warning for now... */
+            PERR ("no such transaction in the database. This is unexpected ...\n");
+            qof_backend_set_error (&be->be, ERR_SQL_MISSING_DATA);
+            pgendEnable(be);
+            qof_event_resume();
+            return 0;
+        }
 
-     /* First order of business is to determine whose data is
-      * newer: the engine cache, or the database.  If the 
-      * database has newer stuff, we update the engine. If the
-      * engine is equal or newer, we do nothing in this routine.
-      * Of course, we know the database has newer data if this
-      * transaction doesn't exist in the engine yet.
-      */
-     if (!do_set_guid)
-     {
-       gint32 db_version, cache_version;
-       db_version = atoi (DB_GET_VAL("version",j));
-       cache_version = qof_instance_get_version (trans);
-       if (db_version == cache_version) {
-         engine_data_is_newer = 0;
-       } else 
-         if (db_version < cache_version) {
-           engine_data_is_newer = +1;
-         } else {
-           engine_data_is_newer = -1;
-         }
-     }
+        if (1 < nrows)
+        {
+            /* since the guid is primary key, this error is totally
+             * and completely impossible, theoretically ... */
+            PERR ("!!!!!!!!!!!SQL database is corrupt!!!!!!!\n"
+                  "too many transactions with GUID=%s\n",
+                  guid_to_string (trans_guid));
+            qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT);
+            pgendEnable(be);
+            qof_event_resume();
+            return 0;
+        }
 
-     /* if the DB data is newer, copy it to engine */
-     if (0 > engine_data_is_newer)
-     {
-       Timespec ts;
-       gnc_commodity *currency;
+        /* First order of business is to determine whose data is
+         * newer: the engine cache, or the database.  If the
+         * database has newer stuff, we update the engine. If the
+         * engine is equal or newer, we do nothing in this routine.
+         * Of course, we know the database has newer data if this
+         * transaction doesn't exist in the engine yet.
+         */
+        if (!do_set_guid)
+        {
+            gint32 db_version, cache_version;
+            db_version = atoi (DB_GET_VAL("version", j));
+            cache_version = qof_instance_get_version (trans);
+            if (db_version == cache_version)
+            {
+                engine_data_is_newer = 0;
+            }
+            else if (db_version < cache_version)
+            {
+                engine_data_is_newer = +1;
+            }
+            else
+            {
+                engine_data_is_newer = -1;
+            }
+        }
 
-       currency = gnc_string_to_commodity (DB_GET_VAL("currency",j), be->book);
-       if (!currency)
-       {
-         pgendGetCommodity (be, DB_GET_VAL("currency",j));
-         currency = gnc_string_to_commodity (DB_GET_VAL("currency",j),
-                                             be->book);
-       }
+        /* if the DB data is newer, copy it to engine */
+        if (0 > engine_data_is_newer)
+        {
+            Timespec ts;
+            gnc_commodity *currency;
 
-       if (!currency)
-       {
-         PERR ("currency not found: %s", DB_GET_VAL("currency",j));
-       }
+            currency = gnc_string_to_commodity (DB_GET_VAL("currency", j), be->book);
+            if (!currency)
+            {
+                pgendGetCommodity (be, DB_GET_VAL("currency", j));
+                currency = gnc_string_to_commodity (DB_GET_VAL("currency", j),
+                                                    be->book);
+            }
 
-       xaccTransBeginEdit (trans);
-       if (do_set_guid) xaccTransSetGUID (trans, trans_guid);
-       xaccTransSetNum (trans, DB_GET_VAL("num",j));
-       xaccTransSetDescription (trans, DB_GET_VAL("description",j));
-       ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted",j));
-       xaccTransSetDatePostedTS (trans, &ts);
-       ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_entered",j));
-       xaccTransSetDateEnteredTS (trans, &ts);
-       qof_instance_set_version (trans, atoi(DB_GET_VAL("version",j)));
-       xaccTransSetCurrency (trans, currency);
-       qof_instance_set_idata(trans, atoi(DB_GET_VAL("iguid",j)));
-     }
-   }
+            if (!currency)
+            {
+                PERR ("currency not found: %s", DB_GET_VAL("currency", j));
+            }
 
-   PQclear (result);
+            xaccTransBeginEdit (trans);
+            if (do_set_guid) xaccTransSetGUID (trans, trans_guid);
+            xaccTransSetNum (trans, DB_GET_VAL("num", j));
+            xaccTransSetDescription (trans, DB_GET_VAL("description", j));
+            ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted", j));
+            xaccTransSetDatePostedTS (trans, &ts);
+            ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_entered", j));
+            xaccTransSetDateEnteredTS (trans, &ts);
+            qof_instance_set_version (trans, atoi(DB_GET_VAL("version", j)));
+            xaccTransSetCurrency (trans, currency);
+            qof_instance_set_idata(trans, atoi(DB_GET_VAL("iguid", j)));
+        }
+    }
 
-   /* set timestamp as 'recent' for this data */
-   qof_instance_set_version_check(trans, be->version_check);
+    PQclear (result);
 
-   /* if engine data was newer, we are done */
-   if (0 <= engine_data_is_newer) 
-   {
-      pgendEnable(be);
-      qof_event_resume();
-      return engine_data_is_newer;
-   }
+    /* set timestamp as 'recent' for this data */
+    qof_instance_set_version_check(trans, be->version_check);
 
-   /* ------------------------------------------------- */
-   /* If we are here, then the sql database contains data that is
-    * newer than what we have in the engine.  And so, below, 
-    * we finish the job of yanking data out of the db.
-    */
-   pgendCopySplitsToEngine (be, trans);
+    /* if engine data was newer, we are done */
+    if (0 <= engine_data_is_newer)
+    {
+        pgendEnable(be);
+        qof_event_resume();
+        return engine_data_is_newer;
+    }
 
-   /* ------------------------------------------------- */
-   /* restore any kvp data associated with the transaction and splits */
+    /* ------------------------------------------------- */
+    /* If we are here, then the sql database contains data that is
+     * newer than what we have in the engine.  And so, below,
+     * we finish the job of yanking data out of the db.
+     */
+    pgendCopySplitsToEngine (be, trans);
 
-   t_idata = qof_instance_get_idata(trans);
-   if (0 != t_idata)
-   {
-      if (!kvp_frame_is_empty (trans->inst.kvp_data))
-      {
-        kvp_frame_delete (trans->inst.kvp_data);
-        trans->inst.kvp_data = kvp_frame_new ();
-      }
+    /* ------------------------------------------------- */
+    /* restore any kvp data associated with the transaction and splits */
 
-      trans->inst.kvp_data = pgendKVPFetch (be, t_idata, trans->inst.kvp_data);
-   }
+    t_idata = qof_instance_get_idata(trans);
+    if (0 != t_idata)
+    {
+        if (!kvp_frame_is_empty (trans->inst.kvp_data))
+        {
+            kvp_frame_delete (trans->inst.kvp_data);
+            trans->inst.kvp_data = kvp_frame_new ();
+        }
 
-   engine_splits = xaccTransGetSplitList(trans);
-   for (node = engine_splits; node; node=node->next)
-   {
-      Split *s = node->data;
-      s_idata = qof_instance_get_idata(s);
-      if (0 != s_idata)
-      {
-         if (!kvp_frame_is_empty (s->inst.kvp_data))
-         {
-           kvp_frame_delete (s->inst.kvp_data);
-           s->inst.kvp_data = kvp_frame_new ();
-         }
+        trans->inst.kvp_data = pgendKVPFetch (be, t_idata, trans->inst.kvp_data);
+    }
 
-         s->inst.kvp_data = pgendKVPFetch (be, s_idata, s->inst.kvp_data);
-      }
-   }
+    engine_splits = xaccTransGetSplitList(trans);
+    for (node = engine_splits; node; node = node->next)
+    {
+        Split *s = node->data;
+        s_idata = qof_instance_get_idata(s);
+        if (0 != s_idata)
+        {
+            if (!kvp_frame_is_empty (s->inst.kvp_data))
+            {
+                kvp_frame_delete (s->inst.kvp_data);
+                s->inst.kvp_data = kvp_frame_new ();
+            }
 
-   /* ------------------------------------------------- */
+            s->inst.kvp_data = pgendKVPFetch (be, s_idata, s->inst.kvp_data);
+        }
+    }
 
-   xaccTransCommitEdit (trans);
+    /* ------------------------------------------------- */
 
-   /* re-enable events to the backend and GUI */
-   pgendEnable(be);
-   qof_event_resume();
+    xaccTransCommitEdit (trans);
 
-   LEAVE (" ");
-   return -1;
+    /* re-enable events to the backend and GUI */
+    pgendEnable(be);
+    qof_event_resume();
+
+    LEAVE (" ");
+    return -1;
 }
 
 /* ============================================================= */
-/* This routine 'synchronizes' the Transaction structure 
+/* This routine 'synchronizes' the Transaction structure
  * associated with the GUID.  Data is pulled out of the database,
  * the versions are compared, and updates made, if needed.
  * The splits are handled as well ...
  *
- * hack alert unfinished, incomplete 
- * hack alert -- philosophically speaking, not clear that this is the 
+ * hack alert unfinished, incomplete
+ * hack alert -- philosophically speaking, not clear that this is the
  * right metaphor.  Its OK to poke date into the engine, but writing
  * data out to the database should make use of versioning, and this
  * routine doesn't.
@@ -855,44 +866,44 @@
 static void
 pgendSyncTransaction (PGBackend *be, GUID *trans_guid)
 {
-   Transaction *trans;
-   int engine_data_is_newer = 0;
-   
-   ENTER ("be=%p", be);
-   if (!be || !trans_guid) return;
+    Transaction *trans;
+    int engine_data_is_newer = 0;
 
-   /* disable callbacks into the backend, and events to GUI */
-   qof_event_suspend();
-   pgendDisable(be);
+    ENTER ("be=%p", be);
+    if (!be || !trans_guid) return;
 
-   engine_data_is_newer = xxxpgendCopyTransactionToEngine (be, trans_guid);
+    /* disable callbacks into the backend, and events to GUI */
+    qof_event_suspend();
+    pgendDisable(be);
 
-   /* if engine data was newer, we save to the db. */
-   if (0 < engine_data_is_newer) 
-   {
-      /* XXX hack alert -- fixme */
-      PERR ("Data in the local cache is newer than the data in\n"
-            "\tthe database.  Thus, the local data will be sent\n"
-            "\tto the database.  This mode of operation is\n"
-            "\tguarenteed to clobber other user's updates.\n");
+    engine_data_is_newer = xxxpgendCopyTransactionToEngine (be, trans_guid);
 
-      trans = pgendTransLookup (be, trans_guid);
+    /* if engine data was newer, we save to the db. */
+    if (0 < engine_data_is_newer)
+    {
+        /* XXX hack alert -- fixme */
+        PERR ("Data in the local cache is newer than the data in\n"
+              "\tthe database.  Thus, the local data will be sent\n"
+              "\tto the database.  This mode of operation is\n"
+              "\tguarenteed to clobber other user's updates.\n");
 
-      /* hack alert -- basically, we should use the pgend_commit_transaction
-       * routine instead, and in fact, 'StoreTransaction'
-       * pretty much shouldn't be allowed to exist in this
-       * framework */
-      pgendStoreTransaction (be, trans);
+        trans = pgendTransLookup (be, trans_guid);
 
-      qof_event_resume();
-      return;
-   }
+        /* hack alert -- basically, we should use the pgend_commit_transaction
+         * routine instead, and in fact, 'StoreTransaction'
+         * pretty much shouldn't be allowed to exist in this
+         * framework */
+        pgendStoreTransaction (be, trans);
 
-   /* re-enable events to the backend and GUI */
-   pgendEnable(be);
-   qof_event_resume();
+        qof_event_resume();
+        return;
+    }
 
-   LEAVE (" ");
+    /* re-enable events to the backend and GUI */
+    pgendEnable(be);
+    qof_event_resume();
+
+    LEAVE (" ");
 }
 
 #endif
@@ -908,148 +919,152 @@
 /* ============================================================= */
 
 void
-pgend_trans_commit_edit (QofBackend * bend, 
+pgend_trans_commit_edit (QofBackend * bend,
                          Transaction * trans,
                          Transaction * oldtrans)
 {
-   char * bufp;
-   int rollback=0;
-   PGBackend *be = (PGBackend *)bend;
+    char * bufp;
+    int rollback = 0;
+    PGBackend *be = (PGBackend *)bend;
 
-   ENTER ("be=%p, trans=%p", be, trans);
-   if (!be || !trans) return; 
+    ENTER ("be=%p, trans=%p", be, trans);
+    if (!be || !trans) return;
 
-   /* lock it up so that we query and store atomically */
-   bufp = "BEGIN;\n"
-          "LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n"
-          "LOCK TABLE gncSplit IN EXCLUSIVE MODE;\n";
-   SEND_QUERY (be,bufp, );
-   FINISH_QUERY(be->connection);
+    /* lock it up so that we query and store atomically */
+    bufp = "BEGIN;\n"
+           "LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n"
+           "LOCK TABLE gncSplit IN EXCLUSIVE MODE;\n";
+    SEND_QUERY (be, bufp, );
+    FINISH_QUERY(be->connection);
 
-   /* Check to see if this is a 'new' transaction, or not. 
-    * The hallmark of a 'new' transaction is that all the 
-    * fields are empty.  If its new, then we just go ahead 
-    * and commit.  If its old, then we need some consistency 
-    * checks.
-    */
-   if (FALSE == is_trans_empty (oldtrans))
-   {
-      /* See if the database is in the state that we last left it in.
-       * Basically, the database should contain the 'old transaction'.
-       * If it doesn't, then someone else has modified this transaction,
-       * and thus, any further action on our part would be unsafe.  It
-       * is recommended that this be spit back at the GUI, and let a 
-       * human decide what to do next.
-       *
-       * We could directly compare all of the data ... but instead,
-       * its more efficient to just compare the version number.
-       */
- 
+    /* Check to see if this is a 'new' transaction, or not.
+     * The hallmark of a 'new' transaction is that all the
+     * fields are empty.  If its new, then we just go ahead
+     * and commit.  If its old, then we need some consistency
+     * checks.
+     */
+    if (FALSE == is_trans_empty (oldtrans))
+    {
+        /* See if the database is in the state that we last left it in.
+         * Basically, the database should contain the 'old transaction'.
+         * If it doesn't, then someone else has modified this transaction,
+         * and thus, any further action on our part would be unsafe.  It
+         * is recommended that this be spit back at the GUI, and let a
+         * human decide what to do next.
+         *
+         * We could directly compare all of the data ... but instead,
+         * its more efficient to just compare the version number.
+         */
+
 #ifdef COMPARE_ALL_TRANSACTION_DATA
-      {
-      int ndiffs;
-      GList *start, *node;
+        {
+            int ndiffs;
+            GList *start, *node;
 
-      ndiffs = pgendCompareOneTransactionOnly (be, oldtrans); 
-      if (0 < ndiffs) rollback++;
+            ndiffs = pgendCompareOneTransactionOnly (be, oldtrans);
+            if (0 < ndiffs) rollback++;
 
-      /* be sure to check the old splits as well ... */
-      start = xaccTransGetSplitList (oldtrans);
-      for (node=start; node; node=node->next) 
-      {
-         Split * s = node->data;
-         ndiffs = pgendCompareOneSplitOnly (be, s);
-         if (0 < ndiffs) rollback++;
-      }
-      }
+            /* be sure to check the old splits as well ... */
+            start = xaccTransGetSplitList (oldtrans);
+            for (node = start; node; node = node->next)
+            {
+                Split * s = node->data;
+                ndiffs = pgendCompareOneSplitOnly (be, s);
+                if (0 < ndiffs) rollback++;
+            }
+        }
 #else
-      /* roll things back is sql version is newer */
-      if (0 < pgendTransactionCompareVersion (be, oldtrans)) { rollback = 1; }
+        /* roll things back is sql version is newer */
+        if (0 < pgendTransactionCompareVersion (be, oldtrans))
+        {
+            rollback = 1;
+        }
 
-      /* first, see if someone else has already deleted this transaction */
-      if (-1 < pgendTransactionGetDeletedVersion (be, oldtrans)) 
-      { 
-         if (rollback)
-         {
-            /* Although this situation should never happen, we'll try
-             * to gracefully handle it anyway, because otherwuise the 
-             * transaction becomes un-modifiable, undeleteable.
-             * (This situation might occur with the right combo of bugs 
-             * and crashes. We've fixed the bugs, but ...
-             */
-            char buf[80];
-            gnc_timespec_to_iso8601_buff (xaccTransRetDatePostedTS (trans),
-                                          buf);
+        /* first, see if someone else has already deleted this transaction */
+        if (-1 < pgendTransactionGetDeletedVersion (be, oldtrans))
+        {
+            if (rollback)
+            {
+                /* Although this situation should never happen, we'll try
+                 * to gracefully handle it anyway, because otherwuise the
+                 * transaction becomes un-modifiable, undeleteable.
+                 * (This situation might occur with the right combo of bugs
+                 * and crashes. We've fixed the bugs, but ...
+                 */
+                char buf[80];
+                gnc_timespec_to_iso8601_buff (xaccTransRetDatePostedTS (trans),
+                                              buf);
 
-            PERR ("The impossible has happened, and thats not good!\n"
-                  "\tThe SQL database contains an active transaction that\n"
-                  "\talso appears in the audit trail as deleted !!\n"
-                  "\tWill try to delete transaction for good\n"
-                  "\ttransaction is '%s' %s\n",
-                  xaccTransGetDescription (trans), buf);
-            rollback = 0;
-            qof_instance_set_destroying(trans, TRUE);
-         }
-         else
-         {
-            rollback = 1;
-         }
-      }
+                PERR ("The impossible has happened, and thats not good!\n"
+                      "\tThe SQL database contains an active transaction that\n"
+                      "\talso appears in the audit trail as deleted !!\n"
+                      "\tWill try to delete transaction for good\n"
+                      "\ttransaction is '%s' %s\n",
+                      xaccTransGetDescription (trans), buf);
+                rollback = 0;
+                qof_instance_set_destroying(trans, TRUE);
+            }
+            else
+            {
+                rollback = 1;
+            }
+        }
 #endif
-   
-      if (rollback) {
-         bufp = "ROLLBACK;";
-         SEND_QUERY (be,bufp,); 
-         FINISH_QUERY(be->connection);
 
-         PINFO ("old transaction didn't match DB, edit rolled back)\n");
+        if (rollback)
+        {
+            bufp = "ROLLBACK;";
+            SEND_QUERY (be, bufp,);
+            FINISH_QUERY(be->connection);
 
-         /* What happens here:  We return to the engine with an 
-          * error code.  This causes the engine to call 
-          * xaccTransRollback(), with then invokes our backend rollback 
-          * routine.  Our rollback routine updates from the latest in 
-          * the sql database, and voila! we are good to go. 
-          */
-         qof_backend_set_error (&be->be, ERR_BACKEND_MODIFIED);
-         return;
-      } 
-   }
+            PINFO ("old transaction didn't match DB, edit rolled back)\n");
 
-   /* if we are here, we are good to go */
-   pgendStoreTransactionNoLock (be, trans, FALSE);
+            /* What happens here:  We return to the engine with an
+             * error code.  This causes the engine to call
+             * xaccTransRollback(), with then invokes our backend rollback
+             * routine.  Our rollback routine updates from the latest in
+             * the sql database, and voila! we are good to go.
+             */
+            qof_backend_set_error (&be->be, ERR_BACKEND_MODIFIED);
+            return;
+        }
+    }
 
-   bufp = "COMMIT;\n"
-          "NOTIFY gncTransaction;";
-   SEND_QUERY (be,bufp,);
-   FINISH_QUERY(be->connection);
+    /* if we are here, we are good to go */
+    pgendStoreTransactionNoLock (be, trans, FALSE);
 
-   /* If this is the multi-user mode, we need to update the
-    * balances as well.  */
-   if ((MODE_POLL == be->session_mode) || 
-       (MODE_EVENT == be->session_mode))
-   {
-      GList *node;
+    bufp = "COMMIT;\n"
+           "NOTIFY gncTransaction;";
+    SEND_QUERY (be, bufp,);
+    FINISH_QUERY(be->connection);
 
-      /* loop over the old accounts, as they used to be. */
-      for (node = xaccTransGetSplitList(trans->orig); node; node=node->next)
-      {
-         Split *s = (Split *) node->data;
-         Account *acc = xaccSplitGetAccount (s);
-         pgendAccountRecomputeOneCheckpoint (be, acc,
-                                             trans->orig->date_posted);
-      }
+    /* If this is the multi-user mode, we need to update the
+     * balances as well.  */
+    if ((MODE_POLL == be->session_mode) ||
+            (MODE_EVENT == be->session_mode))
+    {
+        GList *node;
 
-      /* set checkpoints for the new accounts */
-      pgendTransactionRecomputeCheckpoints (be, trans);
-   }
+        /* loop over the old accounts, as they used to be. */
+        for (node = xaccTransGetSplitList(trans->orig); node; node = node->next)
+        {
+            Split *s = (Split *) node->data;
+            Account *acc = xaccSplitGetAccount (s);
+            pgendAccountRecomputeOneCheckpoint (be, acc,
+                                                trans->orig->date_posted);
+        }
 
-   LEAVE ("commited");
-   return;
+        /* set checkpoints for the new accounts */
+        pgendTransactionRecomputeCheckpoints (be, trans);
+    }
+
+    LEAVE ("commited");
+    return;
 }
 
 /* ============================================================= */
 /* transaction rollback routine.  This routine can be invoked
- * in one of two ways: if the user canceled an edited transaction 
+ * in one of two ways: if the user canceled an edited transaction
  * by hand, from the gui, or automatically, due to a multi-user
  * edit conflict.  In this latter case, the commit_edit routine
  * above failed, and returned to the engine.  Then the engine
@@ -1062,27 +1077,27 @@
 void
 pgend_trans_rollback_edit (QofBackend * bend, Transaction * trans)
 {
-   PGBackend *be = (PGBackend *)bend;
-   const GUID * trans_guid;
+    PGBackend *be = (PGBackend *)bend;
+    const GUID * trans_guid;
 
-   if (!be || !trans) return;
-   ENTER ("be=%p, trans=%p", be, trans);
+    if (!be || !trans) return;
+    ENTER ("be=%p, trans=%p", be, trans);
 
-   /* First, lets see if the other user had deleted this transaction.
-    * If so, then we want to delete it from the local cache as well.
-    */
-   if (-1 < pgendTransactionGetDeletedVersion (be, trans))
-   {
-      LEAVE ("destroyed");
-      qof_backend_set_error (&be->be, ERR_BACKEND_MOD_DESTROY);
-      return;
-   }
+    /* First, lets see if the other user had deleted this transaction.
+     * If so, then we want to delete it from the local cache as well.
+     */
+    if (-1 < pgendTransactionGetDeletedVersion (be, trans))
+    {
+        LEAVE ("destroyed");
+        qof_backend_set_error (&be->be, ERR_BACKEND_MOD_DESTROY);
+        return;
+    }
 
-   trans_guid = xaccTransGetGUID (trans);
-   pgendCopyTransactionToEngine (be, trans_guid);
+    trans_guid = xaccTransGetGUID (trans);
+    pgendCopyTransactionToEngine (be, trans_guid);
 
-   LEAVE ("rolled back");
-   return;
+    LEAVE ("rolled back");
+    return;
 }
 
 /* ======================== END OF FILE ======================== */

Modified: gnucash/trunk/src/backend/postgres/txn.h
===================================================================
--- gnucash/trunk/src/backend/postgres/txn.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/txn.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -19,7 +19,7 @@
  * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
 \********************************************************************/
 
-/* 
+/*
  * FILE:
  * txn.h
  *
@@ -41,7 +41,7 @@
 
 #include "PostgresBackend.h"
 
-int pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid); 
+int pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid);
 void pgendCopySplitsToEngine (PGBackend *be, Transaction *trans);
 
 void pgendStoreAllTransactions (PGBackend *be, Account *root);

Modified: gnucash/trunk/src/backend/postgres/txnmass.c
===================================================================
--- gnucash/trunk/src/backend/postgres/txnmass.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/txnmass.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -50,63 +50,64 @@
 static gpointer
 get_mass_trans_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   QofBook *book = data;
-   GList *xaction_list = be->tmp_return;
-   Transaction *trans;
-   gnc_commodity *currency = NULL;
-   Timespec ts;
-   GUID trans_guid;
+    QofBook *book = data;
+    GList *xaction_list = be->tmp_return;
+    Transaction *trans;
+    gnc_commodity *currency = NULL;
+    Timespec ts;
+    GUID trans_guid;
 
-   FIND_BOOK (book);
+    FIND_BOOK (book);
 
-   /* first, see if we already have such a transaction */
-   string_to_guid (DB_GET_VAL("transGUID",j), &trans_guid);
-   trans = xaccTransLookup (&trans_guid, book);
-   if (trans)
-   {
-      /* If transaction already exists, determine whose data is 
-       * newer: the engine cache, or the database.  If the
-       * engine has newer stuff, ignore the database contents.
-       */
+    /* first, see if we already have such a transaction */
+    string_to_guid (DB_GET_VAL("transGUID", j), &trans_guid);
+    trans = xaccTransLookup (&trans_guid, book);
+    if (trans)
+    {
+        /* If transaction already exists, determine whose data is
+         * newer: the engine cache, or the database.  If the
+         * engine has newer stuff, ignore the database contents.
+         */
 
-      gint32 db_version, cache_version;
-      db_version = atoi (DB_GET_VAL("version",j));
-      cache_version = qof_instance_get_version (trans);
-      if (db_version < cache_version) {
-         xaccTransBeginEdit (trans);
-         xaction_list = g_list_prepend (xaction_list, trans);
-         be->tmp_return = xaction_list;
-         return data;
-       }
-      xaccTransBeginEdit (trans);
-   }
-   else
-   {
-      trans = xaccMallocTransaction(book);
-      xaccTransBeginEdit (trans);
-      xaccTransSetGUID (trans, &trans_guid);
-   }
+        gint32 db_version, cache_version;
+        db_version = atoi (DB_GET_VAL("version", j));
+        cache_version = qof_instance_get_version (trans);
+        if (db_version < cache_version)
+        {
+            xaccTransBeginEdit (trans);
+            xaction_list = g_list_prepend (xaction_list, trans);
+            be->tmp_return = xaction_list;
+            return data;
+        }
+        xaccTransBeginEdit (trans);
+    }
+    else
+    {
+        trans = xaccMallocTransaction(book);
+        xaccTransBeginEdit (trans);
+        xaccTransSetGUID (trans, &trans_guid);
+    }
 
-   xaccTransSetNum (trans, DB_GET_VAL("num",j));
-   xaccTransSetDescription (trans, DB_GET_VAL("description",j));
-   ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted",j));
-   xaccTransSetDatePostedTS (trans, &ts);
-   ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_entered",j));
-   xaccTransSetDateEnteredTS (trans, &ts);
-   qof_instance_set_version (trans, atoi(DB_GET_VAL("version",j)));
-   qof_instance_set_idata(trans, atoi(DB_GET_VAL("iguid",j)));
+    xaccTransSetNum (trans, DB_GET_VAL("num", j));
+    xaccTransSetDescription (trans, DB_GET_VAL("description", j));
+    ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_posted", j));
+    xaccTransSetDatePostedTS (trans, &ts);
+    ts = gnc_iso8601_to_timespec_gmt (DB_GET_VAL("date_entered", j));
+    xaccTransSetDateEnteredTS (trans, &ts);
+    qof_instance_set_version (trans, atoi(DB_GET_VAL("version", j)));
+    qof_instance_set_idata(trans, atoi(DB_GET_VAL("iguid", j)));
 
-   currency = gnc_string_to_commodity (DB_GET_VAL("currency",j), book);
+    currency = gnc_string_to_commodity (DB_GET_VAL("currency", j), book);
 
-   xaccTransSetCurrency (trans, currency);
+    xaccTransSetCurrency (trans, currency);
 
-   /* set timestamp as 'recent' for this data */
-   qof_instance_set_version_check(trans, be->version_check);
+    /* set timestamp as 'recent' for this data */
+    qof_instance_set_version_check(trans, be->version_check);
 
-   xaction_list = g_list_prepend (xaction_list, trans);
+    xaction_list = g_list_prepend (xaction_list, trans);
 
-   be->tmp_return = xaction_list;
-   return data;
+    be->tmp_return = xaction_list;
+    return data;
 }
 
 /* ============================================================= */
@@ -114,96 +115,96 @@
 static gpointer
 get_mass_entry_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   QofBook *book = data;
-   Transaction *trans=NULL;
-   Account *acc;
-   Split *s;
-   GUID guid;
-   Timespec ts;
-   gnc_commodity *modity;
-   gint64 acct_frac;
-   gint64 num;
-   gnc_numeric value, amount;
-   gint64 trans_frac = 0;
+    QofBook *book = data;
+    Transaction *trans = NULL;
+    Account *acc;
+    Split *s;
+    GUID guid;
+    Timespec ts;
+    gnc_commodity *modity;
+    gint64 acct_frac;
+    gint64 num;
+    gnc_numeric value, amount;
+    gint64 trans_frac = 0;
 
-   FIND_BOOK (book);
+    FIND_BOOK (book);
 
-   /* --------------------------------------------- */
-   PINFO ("split GUID=%s", DB_GET_VAL("splitGuid",j));
-   guid = nullguid;  /* just in case the read fails ... */
-   string_to_guid (DB_GET_VAL("splitGuid",j), &guid);
-   s = xaccSplitLookup (&guid, book);
-   if (!s)
-   {
-      s = xaccMallocSplit(book);
-      xaccSplitSetGUID(s, &guid);
-   }
+    /* --------------------------------------------- */
+    PINFO ("split GUID=%s", DB_GET_VAL("splitGuid", j));
+    guid = nullguid;  /* just in case the read fails ... */
+    string_to_guid (DB_GET_VAL("splitGuid", j), &guid);
+    s = xaccSplitLookup (&guid, book);
+    if (!s)
+    {
+        s = xaccMallocSplit(book);
+        xaccSplitSetGUID(s, &guid);
+    }
 
-   /* next, restore all split data */
-   xaccSplitSetMemo(s, DB_GET_VAL("memo",j));
-   xaccSplitSetAction(s, DB_GET_VAL("action",j));
-   ts = gnc_iso8601_to_timespec_gmt
-     (DB_GET_VAL("date_reconciled",j));
-   xaccSplitSetDateReconciledTS (s, &ts);
+    /* next, restore all split data */
+    xaccSplitSetMemo(s, DB_GET_VAL("memo", j));
+    xaccSplitSetAction(s, DB_GET_VAL("action", j));
+    ts = gnc_iso8601_to_timespec_gmt
+         (DB_GET_VAL("date_reconciled", j));
+    xaccSplitSetDateReconciledTS (s, &ts);
 
-   xaccSplitSetReconcile (s, (DB_GET_VAL("reconciled", j))[0]);
-   qof_instance_set_idata(s, atoi(DB_GET_VAL("iguid",j)));
+    xaccSplitSetReconcile (s, (DB_GET_VAL("reconciled", j))[0]);
+    qof_instance_set_idata(s, atoi(DB_GET_VAL("iguid", j)));
 
-   guid = nullguid;  /* just in case the read fails ... */
-   string_to_guid (DB_GET_VAL("transGUID",j), &guid);
-   trans = xaccTransLookup (&guid, book);
-   if (!trans)
-   {
-      PERR ("trans not found, will delete this split\n"
-            "\t(split with  guid=%s\n"
-            "\twants a trans with guid=%s\n"
-            "\tin book with guid=%s)\n",
-            DB_GET_VAL("splitGuid",j),
-            DB_GET_VAL("transGUID",j),
-            DB_GET_VAL("bookGUID",j)
-            );
-      xaccSplitDestroy (s);
-      return data;
-   }
+    guid = nullguid;  /* just in case the read fails ... */
+    string_to_guid (DB_GET_VAL("transGUID", j), &guid);
+    trans = xaccTransLookup (&guid, book);
+    if (!trans)
+    {
+        PERR ("trans not found, will delete this split\n"
+              "\t(split with  guid=%s\n"
+              "\twants a trans with guid=%s\n"
+              "\tin book with guid=%s)\n",
+              DB_GET_VAL("splitGuid", j),
+              DB_GET_VAL("transGUID", j),
+              DB_GET_VAL("bookGUID", j)
+             );
+        xaccSplitDestroy (s);
+        return data;
+    }
 
-   xaccTransAppendSplit (trans, s);
+    xaccTransAppendSplit (trans, s);
 
-   /* --------------------------------------------- */
-   /* next, find the account that this split goes into */
-   guid = nullguid;  /* just in case the read fails ... */
-   string_to_guid (DB_GET_VAL("accountGUID",j), &guid);
-   acc = xaccAccountLookup (&guid, book);
-   if (!acc)
-   {
-      PERR ("account not found, will delete this split\n"
-            "\t(split with  guid=%s\n"
-            "\twants an acct with guid=%s\n"
-            "\tin book with guid=%s)\n",
-            DB_GET_VAL("splitGuid",j),
-            DB_GET_VAL("accountGUID",j),
-            DB_GET_VAL("bookGUID",j)
-            );
-      xaccSplitDestroy (s);
-      return data;
-   }
+    /* --------------------------------------------- */
+    /* next, find the account that this split goes into */
+    guid = nullguid;  /* just in case the read fails ... */
+    string_to_guid (DB_GET_VAL("accountGUID", j), &guid);
+    acc = xaccAccountLookup (&guid, book);
+    if (!acc)
+    {
+        PERR ("account not found, will delete this split\n"
+              "\t(split with  guid=%s\n"
+              "\twants an acct with guid=%s\n"
+              "\tin book with guid=%s)\n",
+              DB_GET_VAL("splitGuid", j),
+              DB_GET_VAL("accountGUID", j),
+              DB_GET_VAL("bookGUID", j)
+             );
+        xaccSplitDestroy (s);
+        return data;
+    }
 
-   /* We must set value after split has been inserted into account,
-    * since engine references the account SCU to set the value. */
-   xaccAccountInsertSplit(acc, s);
+    /* We must set value after split has been inserted into account,
+     * since engine references the account SCU to set the value. */
+    xaccAccountInsertSplit(acc, s);
 
-   /* we don't know the fraction until after we inserted into the account */
-   num = strtoll (DB_GET_VAL("amount", j), NULL, 0);
-   modity = xaccAccountGetCommodity (acc);
-   acct_frac = gnc_commodity_get_fraction (modity);
-   amount = gnc_numeric_create (num, acct_frac);
-   xaccSplitSetAmount (s, amount);
+    /* we don't know the fraction until after we inserted into the account */
+    num = strtoll (DB_GET_VAL("amount", j), NULL, 0);
+    modity = xaccAccountGetCommodity (acc);
+    acct_frac = gnc_commodity_get_fraction (modity);
+    amount = gnc_numeric_create (num, acct_frac);
+    xaccSplitSetAmount (s, amount);
 
-   num = strtoll (DB_GET_VAL("value", j), NULL, 0);
-   trans_frac = gnc_commodity_get_fraction (xaccTransGetCurrency(trans));
-   value = gnc_numeric_create (num, trans_frac);
-   xaccSplitSetValue (s, value);
+    num = strtoll (DB_GET_VAL("value", j), NULL, 0);
+    trans_frac = gnc_commodity_get_fraction (xaccTransGetCurrency(trans));
+    value = gnc_numeric_create (num, trans_frac);
+    xaccSplitSetValue (s, value);
 
-   return data;
+    return data;
 }
 
 /* ============================================================= */
@@ -211,80 +212,80 @@
 void
 pgendGetMassTransactions (PGBackend *be, QofBook *book)
 {
-   char *p, buff[900];
-   GList *node, *xaction_list = NULL;
-   Account *root;
-   guint32 t_idata, s_idata;
+    char *p, buff[900];
+    GList *node, *xaction_list = NULL;
+    Account *root;
+    guint32 t_idata, s_idata;
 
-   qof_event_suspend();
-   pgendDisable(be);
+    qof_event_suspend();
+    pgendDisable(be);
 
-   /* design note: someday, we might get a performance boost by adding
-    * a bookguid to the transaction table */
-   p = buff;
-   p = stpcpy (p, "SELECT DISTINCT gncTransaction.*, gncAccount.bookGuid as bookGuid "
-                  " FROM gncTransaction, gncSplit, gncAccount "
-                  " WHERE gncTransaction.transGuid = gncSplit.transGuid AND "
-                  " gncSplit.accountGuid = gncAccount.accountGuid AND "
-                  " gncAccount.bookGuid = '");
-   p = guid_to_string_buff(qof_book_get_guid (book), p);
-   p = stpcpy (p, "';");
-   SEND_QUERY (be, buff, );
+    /* design note: someday, we might get a performance boost by adding
+     * a bookguid to the transaction table */
+    p = buff;
+    p = stpcpy (p, "SELECT DISTINCT gncTransaction.*, gncAccount.bookGuid as bookGuid "
+                " FROM gncTransaction, gncSplit, gncAccount "
+                " WHERE gncTransaction.transGuid = gncSplit.transGuid AND "
+                " gncSplit.accountGuid = gncAccount.accountGuid AND "
+                " gncAccount.bookGuid = '");
+    p = guid_to_string_buff(qof_book_get_guid (book), p);
+    p = stpcpy (p, "';");
+    SEND_QUERY (be, buff, );
 
-   /* restore the transactions */
-   root = gnc_book_get_root_account (book);
-   xaccAccountBeginEdit (root);
+    /* restore the transactions */
+    root = gnc_book_get_root_account (book);
+    xaccAccountBeginEdit (root);
 
-   be->tmp_return = NULL;
-   pgendGetResults (be, get_mass_trans_cb, book);
-   xaction_list = be->tmp_return;
+    be->tmp_return = NULL;
+    pgendGetResults (be, get_mass_trans_cb, book);
+    xaction_list = be->tmp_return;
 
-   p = buff;
-   p = stpcpy (p, "SELECT gncSplit.*, gncAccount.bookGuid as bookGuid "
-                  " FROM gncSplit, gncAccount "
-                  " WHERE gncSplit.accountGuid = gncAccount.accountGuid AND "
-                  " gncAccount.bookGuid = '");
-   p = guid_to_string_buff(qof_book_get_guid (book), p);
-   p = stpcpy (p, "';");
-   SEND_QUERY (be, buff, );
-   pgendGetResults (be, get_mass_entry_cb, book);
+    p = buff;
+    p = stpcpy (p, "SELECT gncSplit.*, gncAccount.bookGuid as bookGuid "
+                " FROM gncSplit, gncAccount "
+                " WHERE gncSplit.accountGuid = gncAccount.accountGuid AND "
+                " gncAccount.bookGuid = '");
+    p = guid_to_string_buff(qof_book_get_guid (book), p);
+    p = stpcpy (p, "';");
+    SEND_QUERY (be, buff, );
+    pgendGetResults (be, get_mass_entry_cb, book);
 
-   for (node=xaction_list; node; node=node->next)
-   {
-      Transaction *trans = (Transaction *)node->data;
-      GList *splits, *snode;
+    for (node = xaction_list; node; node = node->next)
+    {
+        Transaction *trans = (Transaction *)node->data;
+        GList *splits, *snode;
 
-      /* ------------------------------------------------- */
-      /* Restore any kvp data associated with the transaction and splits.
-       * We won't do this en-mass, as there currently seems to be no
-       * performance advantage to doing so */
-   
-      t_idata = qof_instance_get_idata(trans);
-      if (t_idata)
-      {
-         trans->inst.kvp_data = pgendKVPFetch (be, t_idata, trans->inst.kvp_data);
-      }
-   
-      splits = xaccTransGetSplitList(trans);
-      for (snode = splits; snode; snode=snode->next)
-      {
-         Split *s = snode->data;
-         s_idata = qof_instance_get_idata(s);
-         if (s_idata)
-         {
-            s->inst.kvp_data = pgendKVPFetch (be, s_idata, s->inst.kvp_data);
-         }
-      }
+        /* ------------------------------------------------- */
+        /* Restore any kvp data associated with the transaction and splits.
+         * We won't do this en-mass, as there currently seems to be no
+         * performance advantage to doing so */
 
-      /* ------------------------------------------------- */
-      xaccTransCommitEdit (trans);
-   }
-   g_list_free(xaction_list);
+        t_idata = qof_instance_get_idata(trans);
+        if (t_idata)
+        {
+            trans->inst.kvp_data = pgendKVPFetch (be, t_idata, trans->inst.kvp_data);
+        }
 
-   xaccAccountCommitEdit (root);
+        splits = xaccTransGetSplitList(trans);
+        for (snode = splits; snode; snode = snode->next)
+        {
+            Split *s = snode->data;
+            s_idata = qof_instance_get_idata(s);
+            if (s_idata)
+            {
+                s->inst.kvp_data = pgendKVPFetch (be, s_idata, s->inst.kvp_data);
+            }
+        }
 
-   pgendEnable(be);
-   qof_event_resume();
+        /* ------------------------------------------------- */
+        xaccTransCommitEdit (trans);
+    }
+    g_list_free(xaction_list);
+
+    xaccAccountCommitEdit (root);
+
+    pgendEnable(be);
+    qof_event_resume();
 }
 
 /* ======================== END OF FILE ======================== */

Modified: gnucash/trunk/src/backend/postgres/upgrade.c
===================================================================
--- gnucash/trunk/src/backend/postgres/upgrade.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/upgrade.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -24,8 +24,8 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
-#include <libpq-fe.h> 
-#include <stdlib.h>  
+#include <libpq-fe.h>
+#include <stdlib.h>
 
 #include "PostgresBackend.h"
 #include "qof.h"
@@ -47,73 +47,74 @@
 static gpointer
 version_table_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   return GINT_TO_POINTER (TRUE);
+    return GINT_TO_POINTER (TRUE);
 }
 
 static void
 pgendVersionTable (PGBackend *be)
 {
-   char *p;
-   gboolean table_exists = FALSE;
-   
-   /* First, see if we can find the table that stores 
-    * the version info. */
+    char *p;
+    gboolean table_exists = FALSE;
 
-   p = "SELECT tablename FROM pg_tables WHERE tablename='gncversion';";
-   SEND_QUERY (be,p, );
-   table_exists = GPOINTER_TO_INT (pgendGetResults (be, version_table_cb,
-                                                    FALSE));
+    /* First, see if we can find the table that stores
+     * the version info. */
 
-   if (table_exists) return;
+    p = "SELECT tablename FROM pg_tables WHERE tablename='gncversion';";
+    SEND_QUERY (be, p, );
+    table_exists = GPOINTER_TO_INT (pgendGetResults (be, version_table_cb,
+                                    FALSE));
 
-   /* create the table if it doesn't exist */
-   p = "CREATE TABLE gncVersion (\n"
-       "  major    INT NOT NULL,\n"
-       "  minor    INT NOT NULL,\n"
-       "  rev      INT DEFAULT '0',\n"
-       "  name     TEXT UNIQUE NOT NULL CHECK (name <> ''),\n"
-       "  date     TIMESTAMP DEFAULT 'NOW' \n"
-       ");\n"
-       "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
-       " (1,0,0,'Version Table');";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    if (table_exists) return;
+
+    /* create the table if it doesn't exist */
+    p = "CREATE TABLE gncVersion (\n"
+        "  major    INT NOT NULL,\n"
+        "  minor    INT NOT NULL,\n"
+        "  rev      INT DEFAULT '0',\n"
+        "  name     TEXT UNIQUE NOT NULL CHECK (name <> ''),\n"
+        "  date     TIMESTAMP DEFAULT 'NOW' \n"
+        ");\n"
+        "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
+        " (1,0,0,'Version Table');";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 }
 
 /* ============================================================= */
 /* get the highest installed version number */
 
-typedef struct {
-   int major;
-   int minor;
-   int rev;
+typedef struct
+{
+    int major;
+    int minor;
+    int rev;
 } pgendVersion;
 
 static gpointer
 version_version_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   pgendVersion *v = (pgendVersion *) data;
-   v->major = atoi(DB_GET_VAL ("major", j));
-   v->minor = atoi(DB_GET_VAL ("minor", j));
-   v->rev = atoi(DB_GET_VAL ("rev", j));
-   return NULL;
+    pgendVersion *v = (pgendVersion *) data;
+    v->major = atoi(DB_GET_VAL ("major", j));
+    v->minor = atoi(DB_GET_VAL ("minor", j));
+    v->rev = atoi(DB_GET_VAL ("rev", j));
+    return NULL;
 }
 
 
 static pgendVersion
 pgendGetVersion (PGBackend *be)
 {
-   char * p;
-   pgendVersion vers;
-   
-   vers.major = 0;
-   vers.minor = 0;
-   vers.rev = 0;
-   p = "SELECT major,minor,rev FROM gncVersion ORDER BY "
-       " major DESC, minor DESC, rev DESC LIMIT 1;";
-   SEND_QUERY (be,p, vers);
-   pgendGetResults (be, version_version_cb, &vers);
-   return vers;
+    char * p;
+    pgendVersion vers;
+
+    vers.major = 0;
+    vers.minor = 0;
+    vers.rev = 0;
+    p = "SELECT major,minor,rev FROM gncVersion ORDER BY "
+        " major DESC, minor DESC, rev DESC LIMIT 1;";
+    SEND_QUERY (be, p, vers);
+    pgendGetResults (be, version_version_cb, &vers);
+    return vers;
 }
 
 /* ============================================================= */
@@ -122,147 +123,147 @@
 static gpointer
 get_iguid_cb (PGBackend *be, PGresult *result, int j, gpointer data)
 {
-   int fin = atoi(DB_GET_VAL ("iguid", j));
-   return GINT_TO_POINTER(fin);
+    int fin = atoi(DB_GET_VAL ("iguid", j));
+    return GINT_TO_POINTER(fin);
 }
 
 
 
-static void 
+static void
 put_iguid_in_tables (PGBackend *be)
 {
-   char *p, buff[200];
-   guint iguid;
+    char *p, buff[200];
+    guint iguid;
 
-   execQuery(be, "BEGIN");
-   p = "LOCK TABLE gncAccount IN ACCESS EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncEntry IN ACCESS EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncTransaction IN ACCESS EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncKVPValue IN ACCESS EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncVersion IN ACCESS EXCLUSIVE MODE;\n"
-       "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
-       " (1,1,0,'Start Put iGUID in Main Tables');";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    execQuery(be, "BEGIN");
+    p = "LOCK TABLE gncAccount IN ACCESS EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncEntry IN ACCESS EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncTransaction IN ACCESS EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncKVPValue IN ACCESS EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncVersion IN ACCESS EXCLUSIVE MODE;\n"
+        "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
+        " (1,1,0,'Start Put iGUID in Main Tables');";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   p = "SELECT iguid FROM gncGUIDCache ORDER BY iguid DESC LIMIT 1;";
-   SEND_QUERY (be,p, );
-   iguid = (guint32) GPOINTER_TO_UINT(pgendGetResults (be, get_iguid_cb, 0));
-   iguid ++;
+    p = "SELECT iguid FROM gncGUIDCache ORDER BY iguid DESC LIMIT 1;";
+    SEND_QUERY (be, p, );
+    iguid = (guint32) GPOINTER_TO_UINT(pgendGetResults (be, get_iguid_cb, 0));
+    iguid ++;
 
-   sprintf(buff, "CREATE SEQUENCE gnc_iguid_seq START %d;", iguid);
-   SEND_QUERY (be,buff, );
-   FINISH_QUERY(be->connection);
+    sprintf(buff, "CREATE SEQUENCE gnc_iguid_seq START %d;", iguid);
+    SEND_QUERY (be, buff, );
+    FINISH_QUERY(be->connection);
 
-   p = "ALTER TABLE gncEntry ADD COLUMN iguid INT4;\n"
-       "ALTER TABLE gncEntry ALTER COLUMN iguid set DEFAULT 0;\n"
-       "UPDATE gncEntry SET iguid = 0;\n" 
-       
-       "UPDATE gncEntry SET iguid = gncGUIDCache.iguid "
-       " FROM gncGUIDCache, gncKVPValue "
-       " WHERE gncGUIDCache.guid = gncEntry.entryGUID "
-       " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n"
+    p = "ALTER TABLE gncEntry ADD COLUMN iguid INT4;\n"
+        "ALTER TABLE gncEntry ALTER COLUMN iguid set DEFAULT 0;\n"
+        "UPDATE gncEntry SET iguid = 0;\n"
 
-       "ALTER TABLE gncEntryTrail ADD COLUMN iguid INT4;\n"
-       "ALTER TABLE gncEntryTrail ALTER COLUMN iguid set DEFAULT 0;\n"
-       "UPDATE gncEntryTrail SET iguid = 0;\n" 
-       
-       "UPDATE gncEntryTrail SET iguid = gncGUIDCache.iguid "
-       " FROM gncGUIDCache, gncKVPValue "
-       " WHERE gncGUIDCache.guid = gncEntryTrail.entryGUID "
-       " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
-   
-   p = "ALTER TABLE gncTransaction ADD COLUMN iguid INT4;\n"
-       "ALTER TABLE gncTransaction ALTER COLUMN iguid set DEFAULT 0;\n"
-       "UPDATE gncTransaction SET iguid = 0;\n" 
-       
-       "UPDATE gncTransaction SET iguid = gncGUIDCache.iguid "
-       " FROM gncGUIDCache, gncKVPValue "
-       " WHERE gncGUIDCache.guid = gncTransaction.transGUID "
-       " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n"
+        "UPDATE gncEntry SET iguid = gncGUIDCache.iguid "
+        " FROM gncGUIDCache, gncKVPValue "
+        " WHERE gncGUIDCache.guid = gncEntry.entryGUID "
+        " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n"
 
-       "ALTER TABLE gncTransactionTrail ADD COLUMN iguid INT4;\n"
-       "ALTER TABLE gncTransactionTrail ALTER COLUMN iguid set DEFAULT 0;\n"
-       "UPDATE gncTransactionTrail SET iguid = 0;\n" 
-       
-       "UPDATE gncTransactionTrail SET iguid = gncGUIDCache.iguid "
-       " FROM gncGUIDCache, gncKVPValue "
-       " WHERE gncGUIDCache.guid = gncTransactionTrail.transGUID "
-       " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
-	   
-   p = "ALTER TABLE gncAccount ADD COLUMN iguid INT4;\n"
-       "ALTER TABLE gncAccount ALTER COLUMN iguid set DEFAULT 0;\n"
-       "UPDATE gncAccount SET iguid = 0;\n" 
-       
-       "UPDATE gncAccount SET iguid = gncGUIDCache.iguid "
-       " FROM gncGUIDCache, gncKVPValue "
-       " WHERE gncGUIDCache.guid = gncAccount.accountGUID "
-       " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n"
+        "ALTER TABLE gncEntryTrail ADD COLUMN iguid INT4;\n"
+        "ALTER TABLE gncEntryTrail ALTER COLUMN iguid set DEFAULT 0;\n"
+        "UPDATE gncEntryTrail SET iguid = 0;\n"
 
-       "ALTER TABLE gncAccountTrail ADD COLUMN iguid INT4;\n"
-       "ALTER TABLE gncAccountTrail ALTER COLUMN iguid set DEFAULT 0;\n"
-       "UPDATE gncAccountTrail SET iguid = 0;\n" 
-       
-       "UPDATE gncAccountTrail SET iguid = gncGUIDCache.iguid "
-       " FROM gncGUIDCache, gncKVPValue "
-       " WHERE gncGUIDCache.guid = gncAccountTrail.accountGUID "
-       " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+        "UPDATE gncEntryTrail SET iguid = gncGUIDCache.iguid "
+        " FROM gncGUIDCache, gncKVPValue "
+        " WHERE gncGUIDCache.guid = gncEntryTrail.entryGUID "
+        " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   p = "DROP TABLE gncGUIDCache; \n"
-       "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
-       " (1,1,1,'End Put iGUID in Main Tables');";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    p = "ALTER TABLE gncTransaction ADD COLUMN iguid INT4;\n"
+        "ALTER TABLE gncTransaction ALTER COLUMN iguid set DEFAULT 0;\n"
+        "UPDATE gncTransaction SET iguid = 0;\n"
 
-   execQuery(be, "COMMIT");
+        "UPDATE gncTransaction SET iguid = gncGUIDCache.iguid "
+        " FROM gncGUIDCache, gncKVPValue "
+        " WHERE gncGUIDCache.guid = gncTransaction.transGUID "
+        " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n"
+
+        "ALTER TABLE gncTransactionTrail ADD COLUMN iguid INT4;\n"
+        "ALTER TABLE gncTransactionTrail ALTER COLUMN iguid set DEFAULT 0;\n"
+        "UPDATE gncTransactionTrail SET iguid = 0;\n"
+
+        "UPDATE gncTransactionTrail SET iguid = gncGUIDCache.iguid "
+        " FROM gncGUIDCache, gncKVPValue "
+        " WHERE gncGUIDCache.guid = gncTransactionTrail.transGUID "
+        " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+
+    p = "ALTER TABLE gncAccount ADD COLUMN iguid INT4;\n"
+        "ALTER TABLE gncAccount ALTER COLUMN iguid set DEFAULT 0;\n"
+        "UPDATE gncAccount SET iguid = 0;\n"
+
+        "UPDATE gncAccount SET iguid = gncGUIDCache.iguid "
+        " FROM gncGUIDCache, gncKVPValue "
+        " WHERE gncGUIDCache.guid = gncAccount.accountGUID "
+        " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n"
+
+        "ALTER TABLE gncAccountTrail ADD COLUMN iguid INT4;\n"
+        "ALTER TABLE gncAccountTrail ALTER COLUMN iguid set DEFAULT 0;\n"
+        "UPDATE gncAccountTrail SET iguid = 0;\n"
+
+        "UPDATE gncAccountTrail SET iguid = gncGUIDCache.iguid "
+        " FROM gncGUIDCache, gncKVPValue "
+        " WHERE gncGUIDCache.guid = gncAccountTrail.accountGUID "
+        " AND gncGUIDCache.iguid = gncKVPValue.iguid;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+
+    p = "DROP TABLE gncGUIDCache; \n"
+        "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
+        " (1,1,1,'End Put iGUID in Main Tables');";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+
+    execQuery(be, "COMMIT");
 }
 
 /* ============================================================= */
 
-static void 
+static void
 fix_reconciled_balance_func (PGBackend *be)
 {
-   char *p;
-   
-   execQuery(be, "BEGIN");
+    char *p;
 
-   p = "LOCK TABLE gncVersion IN ACCESS EXCLUSIVE MODE;\n "
-       "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
-       " (1,2,0,'Start Fix gncSubtotalReconedBalance');";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    execQuery(be, "BEGIN");
 
-   p = "DROP FUNCTION "
-       "gncSubtotalReconedBalance (CHAR(32), TIMESTAMP, TIMESTAMP);";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    p = "LOCK TABLE gncVersion IN ACCESS EXCLUSIVE MODE;\n "
+        "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
+        " (1,2,0,'Start Fix gncSubtotalReconedBalance');";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   p = "CREATE FUNCTION "
-       "gncSubtotalReconedBalance (CHAR(32), TIMESTAMP, TIMESTAMP)"
-         "RETURNS INT8 "
-         "AS 'SELECT INT8(sum(gncEntry.amount)) "
-           "FROM gncEntry, gncTransaction "
-           "WHERE "
-           "gncEntry.accountGuid = $1 AND "
-           "gncEntry.transGuid = gncTransaction.transGuid AND "
-           "gncTransaction.date_posted BETWEEN $2 AND $3 AND "
-           "(gncEntry.reconciled = \\'y\\' OR "
-           " gncEntry.reconciled = \\'f\\')' "
-         "LANGUAGE 'sql';";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    p = "DROP FUNCTION "
+        "gncSubtotalReconedBalance (CHAR(32), TIMESTAMP, TIMESTAMP);";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
-       " (1,2,1,'End Fix gncSubtotalReconedBalance');";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
-   execQuery(be, "COMMIT");
+    p = "CREATE FUNCTION "
+        "gncSubtotalReconedBalance (CHAR(32), TIMESTAMP, TIMESTAMP)"
+        "RETURNS INT8 "
+        "AS 'SELECT INT8(sum(gncEntry.amount)) "
+        "FROM gncEntry, gncTransaction "
+        "WHERE "
+        "gncEntry.accountGuid = $1 AND "
+        "gncEntry.transGuid = gncTransaction.transGuid AND "
+        "gncTransaction.date_posted BETWEEN $2 AND $3 AND "
+        "(gncEntry.reconciled = \\'y\\' OR "
+        " gncEntry.reconciled = \\'f\\')' "
+        "LANGUAGE 'sql';";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+
+    p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
+        " (1,2,1,'End Fix gncSubtotalReconedBalance');";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+    execQuery(be, "COMMIT");
 }
 
 /* ============================================================= */
@@ -270,37 +271,37 @@
 static void
 add_kvp_timespec_tables (PGBackend *be)
 {
-  char *p;
+    char *p;
 
-  execQuery(be, "BEGIN");
-   
-  p = "LOCK TABLE gncVersion IN ACCESS EXCLUSIVE MODE;\n "
-      "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
-      " (1,3,0,'Start Add kvp_timespec tables');";
-  SEND_QUERY (be,p, );
-  FINISH_QUERY(be->connection);
+    execQuery(be, "BEGIN");
 
-  p = "CREATE TABLE gncKVPvalue_timespec ( "
-      "  data		TIMESTAMP "
-      ") INHERITS (gncKVPvalue);";
-  SEND_QUERY (be,p, );
-  FINISH_QUERY(be->connection);
+    p = "LOCK TABLE gncVersion IN ACCESS EXCLUSIVE MODE;\n "
+        "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
+        " (1,3,0,'Start Add kvp_timespec tables');";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-  p = "CREATE TABLE gncKVPvalue_timespecTrail ( "
-      "  iguid		INT4, "
-      "  ipath		INT4, "
-      "  type		char(4), "
-      "  data		TIMESTAMP "
-      ") INHERITS (gncAuditTrail);";
-  SEND_QUERY (be,p, );
-  FINISH_QUERY(be->connection);
+    p = "CREATE TABLE gncKVPvalue_timespec ( "
+        "  data		TIMESTAMP "
+        ") INHERITS (gncKVPvalue);";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-  p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
-      " (1,3,1,'End Add kvp_timespec tables');";
-  SEND_QUERY (be,p, );
-  FINISH_QUERY(be->connection);
+    p = "CREATE TABLE gncKVPvalue_timespecTrail ( "
+        "  iguid		INT4, "
+        "  ipath		INT4, "
+        "  type		char(4), "
+        "  data		TIMESTAMP "
+        ") INHERITS (gncAuditTrail);";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-  execQuery(be, "COMMIT");
+    p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
+        " (1,3,1,'End Add kvp_timespec tables');";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+
+    execQuery(be, "COMMIT");
 }
 
 /* ============================================================= */
@@ -308,106 +309,113 @@
 static void
 add_multiple_book_support (PGBackend *be)
 {
-   gchar *buff;
-   gchar *p;
-   const gchar *guid;
-   
-   execQuery(be, "BEGIN");
-   
-   p = "LOCK TABLE gncAccount IN ACCESS EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncAccountTrail IN ACCESS EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncPrice IN ACCESS EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncPriceTrail IN ACCESS EXCLUSIVE MODE;\n"
-       "LOCK TABLE gncVersion IN ACCESS EXCLUSIVE MODE;\n"
-       "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
-       " (1,4,0,'Start Add multiple book support');";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
- 
-   p = "CREATE TABLE gncBook (  \n"
-       " bookGuid        CHAR(32) PRIMARY KEY, \n"
-       " book_open       CHAR DEFAULT 'n', \n"
-       " version         INT4 NOT NULL, \n"
-       " iguid           INT4 DEFAULT 0 \n"
-       ");";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
- 
-   p = "CREATE TABLE gncBookTrail ( \n"
-       " bookGuid        CHAR(32) NOT NULL, \n"
-       " book_open       CHAR DEFAULT 'n', \n"
-       " version         INT4 NOT NULL, \n"
-       " iguid           INT4 DEFAULT 0 \n"
-       ") INHERITS (gncAuditTrail); \n\n"
-       "CREATE INDEX gncBookTrail_book_idx ON gncBookTrail (bookGuid);" ;
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
- 
-   p = "ALTER TABLE gncAccount ADD COLUMN bookGuid CHAR(32);\n"
-       "ALTER TABLE gncAccountTrail ADD COLUMN bookGuid CHAR(32);\n"
-       "ALTER TABLE gncPrice ADD COLUMN bookGuid CHAR(32);\n"
-       "ALTER TABLE gncPriceTrail ADD COLUMN bookGuid CHAR(32);\n";
-   
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    gchar *buff;
+    gchar *p;
+    const gchar *guid;
 
-   guid = guid_to_string(qof_book_get_guid(pgendGetBook(be)));
-   PINFO("guid = %s", guid);
+    execQuery(be, "BEGIN");
 
-   buff = g_strdup_printf("UPDATE gncAccount SET bookGuid = '%s';\n"
-                          "UPDATE gncAccountTrail SET bookGuid = '%s';\n"
-                          "UPDATE gncPrice SET bookGuid = '%s';\n"
-                          "UPDATE gncPriceTrail SET bookGuid = '%s';\n",
-                          guid, guid, guid, guid);
-                          
-   SEND_QUERY (be,buff, );
-   FINISH_QUERY(be->connection);
+    p = "LOCK TABLE gncAccount IN ACCESS EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncAccountTrail IN ACCESS EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncPrice IN ACCESS EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncPriceTrail IN ACCESS EXCLUSIVE MODE;\n"
+        "LOCK TABLE gncVersion IN ACCESS EXCLUSIVE MODE;\n"
+        "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
+        " (1,4,0,'Start Add multiple book support');";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   g_free(buff);
+    p = "CREATE TABLE gncBook (  \n"
+        " bookGuid        CHAR(32) PRIMARY KEY, \n"
+        " book_open       CHAR DEFAULT 'n', \n"
+        " version         INT4 NOT NULL, \n"
+        " iguid           INT4 DEFAULT 0 \n"
+        ");";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   buff = g_strdup_printf("INSERT INTO gncBook (bookGuid, book_open, version, iguid) "
-                          "VALUES ('%s', 'y', 1, 0);", guid);
-   SEND_QUERY (be,buff, );
-   FINISH_QUERY(be->connection);
+    p = "CREATE TABLE gncBookTrail ( \n"
+        " bookGuid        CHAR(32) NOT NULL, \n"
+        " book_open       CHAR DEFAULT 'n', \n"
+        " version         INT4 NOT NULL, \n"
+        " iguid           INT4 DEFAULT 0 \n"
+        ") INHERITS (gncAuditTrail); \n\n"
+        "CREATE INDEX gncBookTrail_book_idx ON gncBookTrail (bookGuid);" ;
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   g_free(buff);
+    p = "ALTER TABLE gncAccount ADD COLUMN bookGuid CHAR(32);\n"
+        "ALTER TABLE gncAccountTrail ADD COLUMN bookGuid CHAR(32);\n"
+        "ALTER TABLE gncPrice ADD COLUMN bookGuid CHAR(32);\n"
+        "ALTER TABLE gncPriceTrail ADD COLUMN bookGuid CHAR(32);\n";
 
-   p = "ALTER TABLE gncAccount ALTER COLUMN bookGuid SET NOT NULL;\n"
-       "ALTER TABLE gncAccountTrail ALTER COLUMN bookGuid SET NOT NULL;\n"
-       "ALTER TABLE gncPrice ALTER COLUMN bookGuid SET NOT NULL;\n"
-       "ALTER TABLE gncPriceTrail ALTER COLUMN bookGuid SET NOT NULL;\n";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
 
-   p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
-       " (1,4,1,'End Add multiple book support');";
-   SEND_QUERY (be,p, );
-   FINISH_QUERY(be->connection);
+    guid = guid_to_string(qof_book_get_guid(pgendGetBook(be)));
+    PINFO("guid = %s", guid);
 
-   execQuery(be, "COMMIT");
+    buff = g_strdup_printf("UPDATE gncAccount SET bookGuid = '%s';\n"
+                           "UPDATE gncAccountTrail SET bookGuid = '%s';\n"
+                           "UPDATE gncPrice SET bookGuid = '%s';\n"
+                           "UPDATE gncPriceTrail SET bookGuid = '%s';\n",
+                           guid, guid, guid, guid);
+
+    SEND_QUERY (be, buff, );
+    FINISH_QUERY(be->connection);
+
+    g_free(buff);
+
+    buff = g_strdup_printf("INSERT INTO gncBook (bookGuid, book_open, version, iguid) "
+                           "VALUES ('%s', 'y', 1, 0);", guid);
+    SEND_QUERY (be, buff, );
+    FINISH_QUERY(be->connection);
+
+    g_free(buff);
+
+    p = "ALTER TABLE gncAccount ALTER COLUMN bookGuid SET NOT NULL;\n"
+        "ALTER TABLE gncAccountTrail ALTER COLUMN bookGuid SET NOT NULL;\n"
+        "ALTER TABLE gncPrice ALTER COLUMN bookGuid SET NOT NULL;\n"
+        "ALTER TABLE gncPriceTrail ALTER COLUMN bookGuid SET NOT NULL;\n";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+
+    p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
+        " (1,4,1,'End Add multiple book support');";
+    SEND_QUERY (be, p, );
+    FINISH_QUERY(be->connection);
+
+    execQuery(be, "COMMIT");
 }
 
 static void
-add_timezone_support(PGBackend *be) {
+add_timezone_support(PGBackend *be)
+{
 #include "newtables.h"
 
     ENTER(" ");
 
-    if (!be) { LEAVE("Backend is (null)"); return; }
-    if (!be->connection) {
+    if (!be)
+    {
+        LEAVE("Backend is (null)");
+        return;
+    }
+    if (!be->connection)
+    {
         qof_backend_set_message(&be->be, _("Backend connection is not available"));
         qof_backend_set_error(&be->be, ERR_BACKEND_CONN_LOST);
         return;
     }
-    
-	if (execQuery(be, "BEGIN WORK;\n") != PGRES_COMMAND_OK) {
+
+    if (execQuery(be, "BEGIN WORK;\n") != PGRES_COMMAND_OK)
+    {
         LEAVE("Failed at BEGIN WORK (1)");
         return;
     }
-    
+
     /* Drop the _old tables if the exist already from a previous
      * upgrage attempt, although
-     * the ROLLBACKs ought to ensure that they don't 
+     * the ROLLBACKs ought to ensure that they don't
      */
     execQuery(be, drop_old_tables);
     execQuery(be, "COMMIT");
@@ -418,100 +426,114 @@
      */
     qof_backend_set_message(&be->be, NULL);
     qof_backend_get_error(&be->be);
-    
+
     /* execQuery sets the backend error message if one occurs */
-	if (execQuery(be, "BEGIN WORK") != PGRES_COMMAND_OK) {
+    if (execQuery(be, "BEGIN WORK") != PGRES_COMMAND_OK)
+    {
         LEAVE("Failed at BEGIN WORK (2)");
         return;
     }
-    
-    if (execQuery(be, lock_tables) != PGRES_COMMAND_OK) {
+
+    if (execQuery(be, lock_tables) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at lock tables");
         return;
     }
-    if (execQuery(be, lock_entry) != PGRES_COMMAND_OK) {
+    if (execQuery(be, lock_entry) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at lock entry tables");
         return;
     }
-    
-    if (execQuery(be, drop_index) != PGRES_COMMAND_OK) {
+
+    if (execQuery(be, drop_index) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at drop indexes");
         return;
     }
-    if (execQuery(be, drop_functions) != PGRES_COMMAND_OK) {
+    if (execQuery(be, drop_functions) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at drop functions");
         return;
     }
-    if (execQuery(be, alter_tables) != PGRES_COMMAND_OK) {
+    if (execQuery(be, alter_tables) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at alter tables");
         return;
     }
 
-    if (execQuery(be, create_new_tables) != PGRES_COMMAND_OK) {
+    if (execQuery(be, create_new_tables) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at create new tables");
         return;
     }
-    if (execQuery(be, create_audits) != PGRES_COMMAND_OK) {
+    if (execQuery(be, create_audits) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at create audit tables");
         return;
     }
-    if (execQuery(be, create_indexes) != PGRES_COMMAND_OK) {
+    if (execQuery(be, create_indexes) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at create indexes");
         return;
     }
-    if (execQuery(be, create_functions) != PGRES_COMMAND_OK) {
+    if (execQuery(be, create_functions) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at create functions");
         return;
     }
-    
-    if (execQuery(be, lock_tables) != PGRES_COMMAND_OK) {
+
+    if (execQuery(be, lock_tables) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at lock tables (2)");
         return;
     }
-    if (execQuery(be, lock_split) != PGRES_COMMAND_OK) {
+    if (execQuery(be, lock_split) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at lock split");
         return;
     }
-    
-    if (execQuery(be, insert_new_data) != PGRES_COMMAND_OK) {
+
+    if (execQuery(be, insert_new_data) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at insert new data");
         return;
     }
-    if (execQuery(be, version_sql) != PGRES_COMMAND_OK) {
+    if (execQuery(be, version_sql) != PGRES_COMMAND_OK)
+    {
         execQuery(be, "ROLLBACK");
         LEAVE("Failed at insert version row");
         return;
     }
-    
+
     /* Everything worked thus far, commit it now! */
     execQuery(be, "COMMIT WORK");
 
-    /* Clean up crud, Drop the _old tables, vacuum to 
+    /* Clean up crud, Drop the _old tables, vacuum to
      * bring the indexes into use.
      */
     execQuery(be, "BEGIN WORK");
     execQuery(be, drop_old_tables);
     execQuery(be, "COMMIT WORK");
     execQuery(be, "VACUUM FULL ANALYZE");
-    
+
     /* Clear backend error messages.  Use _get_error, because
      * _set_error won't clear the backend error message if it
      * is already set.
      *
      * Cleanup failures don't necessarily mean we should error
-     * out, but it would be handy to have an informational 
+     * out, but it would be handy to have an informational
      * message to pass back to the user...
      */
     qof_backend_set_message(&be->be, NULL);
@@ -531,28 +553,28 @@
 int
 pgendDBVersionIsCurrent (PGBackend *be)
 {
-   pgendVersion vers;
+    pgendVersion vers;
 
-   pgendVersionTable(be);
-   vers = pgendGetVersion(be);
+    pgendVersionTable(be);
+    vers = pgendGetVersion(be);
 
-   if (1 > vers.major)
-   {
-      qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT);
-      return -1;
-   }
+    if (1 > vers.major)
+    {
+        qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT);
+        return -1;
+    }
 
-   if ((PGEND_CURRENT_MAJOR_VERSION == vers.major) &&
-       (PGEND_CURRENT_MINOR_VERSION <= vers.minor)) return 0;
+    if ((PGEND_CURRENT_MAJOR_VERSION == vers.major) &&
+            (PGEND_CURRENT_MINOR_VERSION <= vers.minor)) return 0;
 
-   /* check to see if this client can connect */
-   if (PGEND_CURRENT_MAJOR_VERSION < vers.major)
-   {
-      qof_backend_set_error (&be->be, ERR_BACKEND_TOO_NEW);
-      return -1;
-   }
+    /* check to see if this client can connect */
+    if (PGEND_CURRENT_MAJOR_VERSION < vers.major)
+    {
+        qof_backend_set_error (&be->be, ERR_BACKEND_TOO_NEW);
+        return -1;
+    }
 
-   return +1;
+    return +1;
 }
 
 /* ============================================================= */
@@ -560,34 +582,35 @@
 void
 pgendUpgradeDB (PGBackend *be)
 {
-   pgendVersion vers;
+    pgendVersion vers;
 
-   vers = pgendGetVersion(be);
+    vers = pgendGetVersion(be);
 
-   /* start adding features to bring database up to date */
-   if (vers.major == 1)
-   {
-      /* version 1.1.0 add iguids to transaction and entry tables */
-      if (vers.minor < 1)
-      {
-         put_iguid_in_tables(be);
-      }
-      if (vers.minor < 2)
-      {
-        fix_reconciled_balance_func (be);
-      }
-      if (vers.minor < 3)
-      {
-        add_kvp_timespec_tables (be);
-      }
-      if (vers.minor < 4)
-      {
-        add_multiple_book_support (be);
-      }
-      if (vers.minor < 5) {
-          add_timezone_support(be);
-      }
-   }
+    /* start adding features to bring database up to date */
+    if (vers.major == 1)
+    {
+        /* version 1.1.0 add iguids to transaction and entry tables */
+        if (vers.minor < 1)
+        {
+            put_iguid_in_tables(be);
+        }
+        if (vers.minor < 2)
+        {
+            fix_reconciled_balance_func (be);
+        }
+        if (vers.minor < 3)
+        {
+            add_kvp_timespec_tables (be);
+        }
+        if (vers.minor < 4)
+        {
+            add_multiple_book_support (be);
+        }
+        if (vers.minor < 5)
+        {
+            add_timezone_support(be);
+        }
+    }
 }
 
 /* ======================== END OF FILE ======================== */

Modified: gnucash/trunk/src/backend/postgres/upgrade.h
===================================================================
--- gnucash/trunk/src/backend/postgres/upgrade.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/postgres/upgrade.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -25,7 +25,7 @@
 
 #include "PostgresBackend.h"
 
-/* The pgendVersionIsCurrent() routine ... Are we up to date ? 
+/* The pgendVersionIsCurrent() routine ... Are we up to date ?
  *   Return 0 if we are at db version. Return +1 if we are newer.
  *   Return -1 if we are older and so we can't run.
  */

Modified: gnucash/trunk/src/backend/xml/gnc-account-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-account-xml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-account-xml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -90,7 +90,7 @@
 
     xmlAddChild(ret, text_to_dom_tree(act_name_string,
                                       xaccAccountGetName(act)));
-    
+
     xmlAddChild(ret, guid_to_dom_tree(act_id_string, xaccAccountGetGUID(act)));
 
     xmlAddChild(ret, text_to_dom_tree(
@@ -101,27 +101,27 @@
        would mean 2.2.x cannot read those files again. But we can
        enable writing these tags in 2.5.x or late in 2.4.x. */
     /*
-	xmlAddChild(ret, boolean_to_dom_tree(
-							act_hidden_string,
-							xaccAccountGetHidden(act)));
-	xmlAddChild(ret, boolean_to_dom_tree(
-							act_placeholder_string,
-							xaccAccountGetPlaceholder(act)));
+    xmlAddChild(ret, boolean_to_dom_tree(
+    						act_hidden_string,
+    						xaccAccountGetHidden(act)));
+    xmlAddChild(ret, boolean_to_dom_tree(
+    						act_placeholder_string,
+    						xaccAccountGetPlaceholder(act)));
     */
 
     acct_commodity = xaccAccountGetCommodity(act);
     if (acct_commodity != NULL)
     {
         xmlAddChild(ret, commodity_ref_to_dom_tree(act_commodity_string,
-                                                   acct_commodity));
-    
+                    acct_commodity));
+
         xmlAddChild(ret, int_to_dom_tree(act_commodity_scu_string,
                                          xaccAccountGetCommoditySCUi(act)));
-        
+
         if (xaccAccountGetNonStdSCU(act))
             xmlNewChild(ret, NULL, BAD_CAST act_non_standard_scu_string, NULL);
     }
-    
+
     str = xaccAccountGetCode(act);
     if (str && strlen(str) > 0)
     {
@@ -133,12 +133,12 @@
     {
         xmlAddChild(ret, text_to_dom_tree(act_description_string, str));
     }
-       
+
     kf = xaccAccountGetSlots(act);
-    if(kf)
+    if (kf)
     {
         xmlNodePtr kvpnode = kvp_frame_to_dom_tree(act_slots_string, kf);
-        if(kvpnode)
+        if (kvpnode)
         {
             xmlAddChild(ret, kvpnode);
         }
@@ -147,22 +147,22 @@
     parent = gnc_account_get_parent(act);
     if (parent)
     {
-      if (!gnc_account_is_root(parent) || allow_incompat)
-        xmlAddChild(ret, guid_to_dom_tree(act_parent_string,
-					  xaccAccountGetGUID(parent)));
+        if (!gnc_account_is_root(parent) || allow_incompat)
+            xmlAddChild(ret, guid_to_dom_tree(act_parent_string,
+                                              xaccAccountGetGUID(parent)));
     }
 
     lots = xaccAccountGetLotList (act);
     PINFO ("lot list=%p", lots);
     if (lots && !exporting)
     {
-       xmlNodePtr toaddto = xmlNewChild(ret, NULL, BAD_CAST act_lots_string, NULL);
+        xmlNodePtr toaddto = xmlNewChild(ret, NULL, BAD_CAST act_lots_string, NULL);
 
-       for (n = lots; n; n=n->next)
-       {
-          GNCLot * lot = n->data;
-          xmlAddChild(toaddto, gnc_lot_dom_tree_create(lot));
-       }
+        for (n = lots; n; n = n->next)
+        {
+            GNCLot * lot = n->data;
+            xmlAddChild(toaddto, gnc_lot_dom_tree_create(lot));
+        }
     }
     g_list_free(lots);
 
@@ -174,8 +174,8 @@
 
 struct account_pdata
 {
-  Account *account;
-  QofBook *book;
+    Account *account;
+    QofBook *book;
 };
 
 static inline gboolean
@@ -184,11 +184,11 @@
 {
     gchar* txt = dom_tree_to_text(node);
     g_return_val_if_fail(txt, FALSE);
-    
+
     func(act, txt);
 
     g_free(txt);
-    
+
     return TRUE;
 }
 
@@ -212,7 +212,7 @@
     xaccAccountSetGUID(pdata->account, guid);
 
     g_free(guid);
-    
+
     return TRUE;
 }
 
@@ -261,9 +261,9 @@
 account_hidden_handler (xmlNodePtr node, gpointer act_pdata)
 {
     struct account_pdata *pdata = act_pdata;
-	gboolean val;
+    gboolean val;
 
-	dom_tree_to_boolean(node, &val);
+    dom_tree_to_boolean(node, &val);
     xaccAccountSetHidden(pdata->account, val);
 
     return TRUE;
@@ -273,9 +273,9 @@
 account_placeholder_handler (xmlNodePtr node, gpointer act_pdata)
 {
     struct account_pdata *pdata = act_pdata;
-	gboolean val;
+    gboolean val;
 
-	dom_tree_to_boolean(node, &val);
+    dom_tree_to_boolean(node, &val);
     xaccAccountSetPlaceholder(pdata->account, val);
 
     return TRUE;
@@ -292,7 +292,7 @@
 }
 
 /* ============================================================== */
-/* The following deprecated routines are here only to service 
+/* The following deprecated routines are here only to service
  * older XML files. */
 
 static gboolean
@@ -301,7 +301,7 @@
     struct account_pdata *pdata = act_pdata;
     gnc_commodity *ref;
 
-    PWARN("Obsolete xml tag will not be preserved."); 
+    PWARN("Obsolete xml tag will not be preserved.");
     ref = dom_tree_to_commodity_ref_no_engine(node, pdata->book);
     DxaccAccountSetCurrency(pdata->account, ref);
 
@@ -311,7 +311,7 @@
 static gboolean
 deprecated_account_currency_scu_handler (xmlNodePtr node, gpointer act_pdata)
 {
-    PWARN("Obsolete xml tag will not be preserved."); 
+    PWARN("Obsolete xml tag will not be preserved.");
     return TRUE;
 }
 
@@ -321,8 +321,9 @@
     struct account_pdata *pdata = act_pdata;
     gnc_commodity *ref;
 
-    PWARN("Obsolete xml tag will not be preserved."); 
-    if (!xaccAccountGetCommodity(pdata->account)) {
+    PWARN("Obsolete xml tag will not be preserved.");
+    if (!xaccAccountGetCommodity(pdata->account))
+    {
         ref = dom_tree_to_commodity_ref_no_engine(node, pdata->book);
         xaccAccountSetCommodity(pdata->account, ref);
     }
@@ -336,8 +337,9 @@
     struct account_pdata *pdata = act_pdata;
     gint64 val;
 
-    PWARN("Obsolete xml tag will not be preserved."); 
-    if (!xaccAccountGetCommoditySCU(pdata->account)) {
+    PWARN("Obsolete xml tag will not be preserved.");
+    if (!xaccAccountGetCommoditySCU(pdata->account))
+    {
         dom_tree_to_integer(node, &val);
         xaccAccountSetCommoditySCU(pdata->account, val);
     }
@@ -353,7 +355,7 @@
     struct account_pdata *pdata = act_pdata;
 
     return dom_tree_to_kvp_frame_given
-        (node, xaccAccountGetSlots (pdata->account));
+           (node, xaccAccountGetSlots (pdata->account));
 }
 
 static gboolean
@@ -369,8 +371,8 @@
     parent = xaccAccountLookup(gid, pdata->book);
     if (!parent)
     {
-      g_free (gid);
-      g_return_val_if_fail(parent, FALSE);
+        g_free (gid);
+        g_return_val_if_fail(parent, FALSE);
     }
 
     gnc_account_append_child(parent, pdata->account);
@@ -405,16 +407,16 @@
     g_return_val_if_fail(node, FALSE);
     g_return_val_if_fail(node->xmlChildrenNode, FALSE);
 
-    for(mark = node->xmlChildrenNode; mark; mark = mark->next)
+    for (mark = node->xmlChildrenNode; mark; mark = mark->next)
     {
         GNCLot *lot;
-        
-        if(safe_strcmp("text", (char*) mark->name) == 0)
-          continue;
 
+        if (safe_strcmp("text", (char*) mark->name) == 0)
+            continue;
+
         lot = dom_tree_to_lot(mark, pdata->book);
 
-        if(lot)
+        if (lot)
         {
             xaccAccountInsertLot (pdata->account, lot);
         }
@@ -426,7 +428,8 @@
     return TRUE;
 }
 
-static struct dom_tree_handler account_handlers_v2[] = {
+static struct dom_tree_handler account_handlers_v2[] =
+{
     { act_name_string, account_name_handler, 1, 0 },
     { act_id_string, account_id_handler, 1, 0 },
     { act_type_string, account_type_handler, 1, 0 },
@@ -438,11 +441,11 @@
     { act_slots_string, account_slots_handler, 0, 0 },
     { act_parent_string, account_parent_handler, 0, 0 },
     { act_lots_string, account_lots_handler, 0, 0 },
-	{ act_hidden_string, account_hidden_handler, 0, 0 },
-	{ act_placeholder_string, account_placeholder_handler, 0, 0 },
-    
+    { act_hidden_string, account_hidden_handler, 0, 0 },
+    { act_placeholder_string, account_placeholder_handler, 0, 0 },
+
     /* These should not appear in  newer xml files; only in old
-     * (circa gnucash-1.6) xml files. We maintain them for backward 
+     * (circa gnucash-1.6) xml files. We maintain them for backward
      * compatibility. */
     { act_currency_string, deprecated_account_currency_handler, 0, 0 },
     { act_currency_scu_string, deprecated_account_currency_scu_handler, 0, 0 },
@@ -466,14 +469,14 @@
 
     successful = TRUE;
 
-    if(parent_data)
+    if (parent_data)
     {
         return TRUE;
     }
 
     /* OK.  For some messed up reason this is getting called again with a
        NULL tag.  So we ignore those cases */
-    if(!tag)
+    if (!tag)
     {
         return TRUE;
     }
@@ -481,7 +484,7 @@
     g_return_val_if_fail(tree, FALSE);
 
     acc = dom_tree_to_account(tree, book);
-    if(acc != NULL)
+    if (acc != NULL)
     {
         gdata->cb(tag, gdata->parsedata, acc);
         /*
@@ -491,17 +494,20 @@
          */
         xaccAccountBeginEdit(acc);
 
-	/* Backwards compatability.  If there's no parent, see if this
-	 * account is of type ROOT.  If not, find or create a ROOT
-	 * account and make that the parent. */
+        /* Backwards compatability.  If there's no parent, see if this
+         * account is of type ROOT.  If not, find or create a ROOT
+         * account and make that the parent. */
         parent = gnc_account_get_parent(acc);
-        if (parent == NULL) {
+        if (parent == NULL)
+        {
             type = xaccAccountGetType(acc);
-            if (type != ACCT_TYPE_ROOT) {
+            if (type != ACCT_TYPE_ROOT)
+            {
                 root = gnc_book_get_root_account(book);
-                if (root == NULL) {
-		  root = gnc_account_create_root(book);
-		}
+                if (root == NULL)
+                {
+                    root = gnc_account_create_root(book);
+                }
                 gnc_account_append_child(root, acc);
             }
         }
@@ -527,9 +533,12 @@
 
     successful = dom_tree_generic_parse (node, account_handlers_v2,
                                          &act_pdata);
-    if (successful) {
-      xaccAccountCommitEdit (accToRet);
-    } else {
+    if (successful)
+    {
+        xaccAccountCommitEdit (accToRet);
+    }
+    else
+    {
         PERR ("failed to parse account tree");
         xaccAccountDestroy (accToRet);
         accToRet = NULL;

Modified: gnucash/trunk/src/backend/xml/gnc-backend-xml.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-backend-xml.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-backend-xml.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -19,7 +19,7 @@
  * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
 \********************************************************************/
 /** @file gnc-backend-xml.c
- *  @brief load and save data to XML files 
+ *  @brief load and save data to XML files
  *  @author Copyright (c) 2000 Gnumatic Inc.
  *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
  *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
@@ -68,7 +68,7 @@
 
 static QofLogModule log_module = GNC_MOD_BACKEND;
 
-typedef enum 
+typedef enum
 {
     GNC_BOOK_NOT_OURS,
     GNC_BOOK_BIN_FILE,
@@ -105,31 +105,32 @@
     if (be->lockfd < 0)
     {
         /* oops .. we can't create the lockfile .. */
-        switch (errno) {
+        switch (errno)
+        {
         case EACCES:
         case EROFS:
         case ENOSPC:
-          be_err = ERR_BACKEND_READONLY;
-          break;
+            be_err = ERR_BACKEND_READONLY;
+            break;
         default:
-          be_err = ERR_BACKEND_LOCKED;
-          break;
+            be_err = ERR_BACKEND_LOCKED;
+            break;
         }
         qof_backend_set_error ((QofBackend*)be, be_err);
         return FALSE;
     }
 
-    /* OK, now work around some NFS atomic lock race condition 
-     * mumbo-jumbo.  We do this by linking a unique file, and 
-     * then examing the link count.  At least that's what the 
-     * NFS programmers guide suggests. 
+    /* OK, now work around some NFS atomic lock race condition
+     * mumbo-jumbo.  We do this by linking a unique file, and
+     * then examing the link count.  At least that's what the
+     * NFS programmers guide suggests.
      * Note: the "unique filename" must be unique for the
-     * triplet filename-host-process, otherwise accidental 
+     * triplet filename-host-process, otherwise accidental
      * aliases can occur.
      */
 
     /* apparently, even this code may not work for some NFS
-     * implementations. In the long run, I am told that 
+     * implementations. In the long run, I am told that
      * ftp.debian.org
      *  /pub/debian/dists/unstable/main/source/libs/liblockfile_0.1-6.tar.gz
      * provides a better long-term solution.
@@ -146,15 +147,15 @@
         /* If hard links aren't supported, just allow the lock. */
         if (errno == EPERM || errno == ENOSYS
 # ifdef EOPNOTSUPP
-            || errno == EOPNOTSUPP
+                || errno == EOPNOTSUPP
 # endif
 # ifdef ENOTSUP
-            || errno == ENOTSUP
+                || errno == ENOTSUP
 # endif
 # ifdef ENOSYS
-            || errno == ENOSYS
+                || errno == ENOSYS
 # endif
-            )
+           )
         {
             be->linkfile = NULL;
             return TRUE;
@@ -205,20 +206,20 @@
 #define FILE_URI_PREFIX "file://"
 
 static void
-xml_session_begin(QofBackend *be_start, QofSession *session, 
-                   const char *book_id,
-                   gboolean ignore_lock, gboolean create_if_nonexistent)
+xml_session_begin(QofBackend *be_start, QofSession *session,
+                  const char *book_id,
+                  gboolean ignore_lock, gboolean create_if_nonexistent)
 {
     FileBackend *be = (FileBackend*) be_start;
-	gchar* resolved_path;
+    gchar* resolved_path;
 
     ENTER (" ");
 
     /* Make sure the directory is there */
-	if (g_str_has_prefix(book_id, XML_URI_PREFIX))
-		book_id += strlen(XML_URI_PREFIX);
-	if (g_str_has_prefix(book_id, FILE_URI_PREFIX))
-		book_id += strlen(FILE_URI_PREFIX);
+    if (g_str_has_prefix(book_id, XML_URI_PREFIX))
+        book_id += strlen(XML_URI_PREFIX);
+    if (g_str_has_prefix(book_id, FILE_URI_PREFIX))
+        book_id += strlen(FILE_URI_PREFIX);
     be->fullpath = xaccResolveFilePath(book_id);
     if (NULL == be->fullpath)
     {
@@ -233,39 +234,45 @@
         struct stat statbuf;
         int rc;
 
-	/* Again check whether the directory can be accessed */
+        /* Again check whether the directory can be accessed */
         rc = g_stat (be->dirname, &statbuf);
         if (rc != 0 || !S_ISDIR(statbuf.st_mode))
         {
-	    /* Error on stat or if it isn't a directory means we
-	       cannot find this filename */
+            /* Error on stat or if it isn't a directory means we
+               cannot find this filename */
             qof_backend_set_error (be_start, ERR_FILEIO_FILE_NOT_FOUND);
-            g_free (be->fullpath); be->fullpath = NULL;
-            g_free (be->dirname); be->dirname = NULL;
+            g_free (be->fullpath);
+            be->fullpath = NULL;
+            g_free (be->dirname);
+            be->dirname = NULL;
             LEAVE("");
             return;
         }
 
-	/* Now check whether we can g_stat the file itself */
+        /* Now check whether we can g_stat the file itself */
         rc = g_stat (be->fullpath, &statbuf);
         if ((rc != 0) && (!create_if_nonexistent))
         {
-	    /* Error on stat means the file doesn't exist */
+            /* Error on stat means the file doesn't exist */
             qof_backend_set_error (be_start, ERR_FILEIO_FILE_NOT_FOUND);
-            g_free (be->fullpath); be->fullpath = NULL;
-            g_free (be->dirname); be->dirname = NULL;
+            g_free (be->fullpath);
+            be->fullpath = NULL;
+            g_free (be->dirname);
+            be->dirname = NULL;
             LEAVE("");
             return;
         }
         if (rc == 0 && S_ISDIR(statbuf.st_mode))
-       {
-	    /* FIXME: What is actually checked here? Whether the
-	       fullpath erroneously points to a directory or what? 
-	       Then the error message should be changed into something
-	       much more clear! */
+        {
+            /* FIXME: What is actually checked here? Whether the
+               fullpath erroneously points to a directory or what?
+               Then the error message should be changed into something
+               much more clear! */
             qof_backend_set_error (be_start, ERR_FILEIO_UNKNOWN_FILE_TYPE);
-            g_free (be->fullpath); be->fullpath = NULL;
-            g_free (be->dirname); be->dirname = NULL;
+            g_free (be->fullpath);
+            be->fullpath = NULL;
+            g_free (be->dirname);
+            be->dirname = NULL;
             LEAVE("");
             return;
         }
@@ -279,7 +286,8 @@
 
     if (!ignore_lock && !gnc_xml_be_get_file_lock (be))
     {
-        g_free (be->lockfile); be->lockfile = NULL;
+        g_free (be->lockfile);
+        be->lockfile = NULL;
         LEAVE("");
         return;
     }
@@ -302,17 +310,19 @@
     if (be->lockfd > 0)
         close (be->lockfd);
 
-    if (be->lockfile) {
+    if (be->lockfile)
+    {
         int rv;
 #ifdef G_OS_WIN32
-	/* On windows, we need to allow write-access before
-	   g_unlink() can succeed */
-    	rv = g_chmod (be->lockfile, S_IWRITE | S_IREAD);
+        /* On windows, we need to allow write-access before
+           g_unlink() can succeed */
+        rv = g_chmod (be->lockfile, S_IWRITE | S_IREAD);
 #endif
-	    rv = g_unlink (be->lockfile);
-        if (rv) {
-             PWARN("Error on g_unlink(%s): %d: %s", be->lockfile,
-                   errno, strerror(errno) ? strerror(errno) : "");
+        rv = g_unlink (be->lockfile);
+        if (rv)
+        {
+            PWARN("Error on g_unlink(%s): %d: %s", be->lockfile,
+                  errno, strerror(errno) ? strerror(errno) : "");
         }
     }
 
@@ -355,7 +365,7 @@
     char buf[buf_size];
     int orig_fd;
     int bkup_fd;
-    int flags=0;
+    int flags = 0;
     ssize_t count_write;
     ssize_t count_read;
 
@@ -364,12 +374,12 @@
 #endif
 
     orig_fd = g_open(orig, O_RDONLY | flags, 0);
-    if(orig_fd == -1)
+    if (orig_fd == -1)
     {
         return FALSE;
     }
     bkup_fd = g_open(bkup, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL | flags, 0600);
-    if(bkup_fd == -1)
+    if (bkup_fd == -1)
     {
         close(orig_fd);
         return FALSE;
@@ -378,68 +388,69 @@
     do
     {
         count_read = read(orig_fd, buf, buf_size);
-        if(count_read == -1 && errno != EINTR)
+        if (count_read == -1 && errno != EINTR)
         {
             close(orig_fd);
             close(bkup_fd);
             return FALSE;
         }
 
-        if(count_read > 0)
+        if (count_read > 0)
         {
             count_write = write(bkup_fd, buf, count_read);
-            if(count_write == -1)
+            if (count_write == -1)
             {
                 close(orig_fd);
                 close(bkup_fd);
                 return FALSE;
             }
         }
-    } while(count_read > 0);
+    }
+    while (count_read > 0);
 
     close(orig_fd);
     close(bkup_fd);
-    
+
     return TRUE;
 }
-        
+
 /* ================================================================= */
 
 static gboolean
 gnc_int_link_or_make_backup(FileBackend *be, const char *orig, const char *bkup)
 {
     gboolean copy_success = FALSE;
-    int err_ret = 
+    int err_ret =
 #ifdef HAVE_LINK
-      link (orig, bkup)
+        link (orig, bkup)
 #else
-      -1
+        - 1
 #endif
-      ;
-    if(err_ret != 0)
+        ;
+    if (err_ret != 0)
     {
 #ifdef HAVE_LINK
-        if(errno == EPERM || errno == ENOSYS
+        if (errno == EPERM || errno == ENOSYS
 # ifdef EOPNOTSUPP
-           || errno == EOPNOTSUPP
+                || errno == EOPNOTSUPP
 # endif
 # ifdef ENOTSUP
-           || errno == ENOTSUP
+                || errno == ENOTSUP
 # endif
 # ifdef ENOSYS
-           || errno == ENOSYS
+                || errno == ENOSYS
 # endif
-            )
+           )
 #endif
         {
             copy_success = copy_file(orig, bkup);
         }
 
-        if(!copy_success)
+        if (!copy_success)
         {
             qof_backend_set_error((QofBackend*)be, ERR_FILEIO_BACKUP_ERROR);
-            PWARN ("unable to make file backup from %s to %s: %s", 
-                    orig, bkup, strerror(errno) ? strerror(errno) : ""); 
+            PWARN ("unable to make file backup from %s to %s: %s",
+                   orig, bkup, strerror(errno) ? strerror(errno) : "");
             return FALSE;
         }
     }
@@ -452,45 +463,75 @@
 static QofBookFileType
 gnc_xml_be_determine_file_type(const char *path)
 {
-  gboolean with_encoding;
-  if (gnc_is_xml_data_file_v2(path, &with_encoding)) {
-    if (with_encoding) {
-      return GNC_BOOK_XML2_FILE;
-    } else {
-      return GNC_BOOK_XML2_FILE_NO_ENCODING;
+    gboolean with_encoding;
+    if (gnc_is_xml_data_file_v2(path, &with_encoding))
+    {
+        if (with_encoding)
+        {
+            return GNC_BOOK_XML2_FILE;
+        }
+        else
+        {
+            return GNC_BOOK_XML2_FILE_NO_ENCODING;
+        }
     }
-  } else if (gnc_is_xml_data_file(path)) {
-    return GNC_BOOK_XML1_FILE;
-  }
-  return GNC_BOOK_NOT_OURS;
+    else if (gnc_is_xml_data_file(path))
+    {
+        return GNC_BOOK_XML1_FILE;
+    }
+    return GNC_BOOK_NOT_OURS;
 }
 
 static gboolean
 gnc_determine_file_type (const char *path)
 {
-	struct stat sbuf;
-	int rc;
-	FILE *t;
+    struct stat sbuf;
+    int rc;
+    FILE *t;
 
-	if (!path) { return FALSE; }
+    if (!path)
+    {
+        return FALSE;
+    }
 
-	// Since this can be called with "xml:" as a prefix, remove it if it exists
-	if( g_str_has_prefix( path, "xml:" ) ) {
-	    path += 4;
-	}
+    // Since this can be called with "xml:" as a prefix, remove it if it exists
+    if ( g_str_has_prefix( path, "xml:" ) )
+    {
+        path += 4;
+    }
 
-	if (0 == safe_strcmp(path, QOF_STDOUT)) { return FALSE; }
-	t = g_fopen(path, "r");
-	if(!t) { PINFO (" new file"); return TRUE; }
-	fclose(t);
-	rc = g_stat(path, &sbuf);
-	if(rc < 0) { return FALSE; }
-	if (sbuf.st_size == 0)    { PINFO (" empty file"); return TRUE; }
-	if(gnc_is_xml_data_file_v2(path, NULL)) { return TRUE; } 
-	else if(gnc_is_xml_data_file(path))     { return TRUE; } 
-	PINFO (" %s is not a gnc XML file", path);
-	return FALSE;
-}	
+    if (0 == safe_strcmp(path, QOF_STDOUT))
+    {
+        return FALSE;
+    }
+    t = g_fopen(path, "r");
+    if (!t)
+    {
+        PINFO (" new file");
+        return TRUE;
+    }
+    fclose(t);
+    rc = g_stat(path, &sbuf);
+    if (rc < 0)
+    {
+        return FALSE;
+    }
+    if (sbuf.st_size == 0)
+    {
+        PINFO (" empty file");
+        return TRUE;
+    }
+    if (gnc_is_xml_data_file_v2(path, NULL))
+    {
+        return TRUE;
+    }
+    else if (gnc_is_xml_data_file(path))
+    {
+        return TRUE;
+    }
+    PINFO (" %s is not a gnc XML file", path);
+    return FALSE;
+}
 
 static gboolean
 gnc_xml_be_backup_file(FileBackend *be)
@@ -503,12 +544,12 @@
     int rc;
 
     datafile = be->fullpath;
-    
+
     rc = g_stat (datafile, &statbuf);
     if (rc)
-      return (errno == ENOENT);
+        return (errno == ENOENT);
 
-    if(gnc_xml_be_determine_file_type(datafile) == GNC_BOOK_BIN_FILE)
+    if (gnc_xml_be_determine_file_type(datafile) == GNC_BOOK_BIN_FILE)
     {
         /* make a more permament safer backup */
         const char *back = "-binfmt.bkup";
@@ -517,7 +558,7 @@
         strcat(bin_bkup, back);
         bkup_ret = gnc_int_link_or_make_backup(be, datafile, bin_bkup);
         g_free(bin_bkup);
-        if(!bkup_ret)
+        if (!bkup_ret)
         {
             return FALSE;
         }
@@ -538,12 +579,12 @@
 }
 
 /* ================================================================= */
- 
+
 static gboolean
-gnc_xml_be_write_to_file(FileBackend *fbe, 
-                          QofBook *book, 
-                          const gchar *datafile,
-                          gboolean make_backup)
+gnc_xml_be_write_to_file(FileBackend *fbe,
+                         QofBook *book,
+                         const gchar *datafile,
+                         gboolean make_backup)
 {
     QofBackend *be = &fbe->be;
     char *tmp_name;
@@ -561,93 +602,93 @@
     strcpy(tmp_name, datafile);
     strcat(tmp_name, ".tmp-XXXXXX");
 
-    if(!mktemp(tmp_name))
+    if (!mktemp(tmp_name))
     {
         qof_backend_set_error(be, ERR_BACKEND_MISC);
         LEAVE("");
         return FALSE;
     }
-  
-    if(make_backup)
+
+    if (make_backup)
     {
-        if(!gnc_xml_be_backup_file(fbe))
+        if (!gnc_xml_be_backup_file(fbe))
         {
             LEAVE("");
             return FALSE;
         }
     }
-  
+
     if (gnc_book_write_to_xml_file_v2(book, tmp_name, fbe->file_compression))
     {
         /* Record the file's permissions before g_unlinking it */
         rc = g_stat(datafile, &statbuf);
-        if(rc == 0)
+        if (rc == 0)
         {
             /* Use the permissions from the original data file */
-            if(g_chmod(tmp_name, statbuf.st_mode) != 0)
+            if (g_chmod(tmp_name, statbuf.st_mode) != 0)
             {
-	        /* qof_backend_set_error(be, ERR_BACKEND_PERM); */
-		/* Even if the chmod did fail, the save
-		   nevertheless completed successfully. It is
-		   therefore wrong to signal the ERR_BACKEND_PERM
-		   error here which implies that the saving itself
-		   failed. Instead, we simply ignore this. */
+                /* qof_backend_set_error(be, ERR_BACKEND_PERM); */
+                /* Even if the chmod did fail, the save
+                   nevertheless completed successfully. It is
+                   therefore wrong to signal the ERR_BACKEND_PERM
+                   error here which implies that the saving itself
+                   failed. Instead, we simply ignore this. */
                 PWARN("unable to chmod filename %s: %s",
-                        tmp_name ? tmp_name : "(null)", 
-                        strerror(errno) ? strerror(errno) : ""); 
+                      tmp_name ? tmp_name : "(null)",
+                      strerror(errno) ? strerror(errno) : "");
 #if VFAT_DOESNT_SUCK  /* chmod always fails on vfat/samba fs */
                 /* g_free(tmp_name); */
                 /* return FALSE; */
 #endif
             }
 #ifdef HAVE_CHOWN
-	    /* Don't try to change the owner. Only root can do
-	       that. */
-            if(chown(tmp_name, -1, statbuf.st_gid) != 0)
+            /* Don't try to change the owner. Only root can do
+               that. */
+            if (chown(tmp_name, -1, statbuf.st_gid) != 0)
             {
-	        /* qof_backend_set_error(be, ERR_BACKEND_PERM); */
-	        /* A failed chown doesn't mean that the saving itself
-		   failed. So don't abort with an error here! */
+                /* qof_backend_set_error(be, ERR_BACKEND_PERM); */
+                /* A failed chown doesn't mean that the saving itself
+                failed. So don't abort with an error here! */
                 PWARN("unable to chown filename %s: %s",
-                        tmp_name ? tmp_name : "(null)", 
-                        strerror(errno) ? strerror(errno) : ""); 
+                      tmp_name ? tmp_name : "(null)",
+                      strerror(errno) ? strerror(errno) : "");
 #if VFAT_DOESNT_SUCK /* chown always fails on vfat fs */
                 /* g_free(tmp_name);
-		   return FALSE; */
+                return FALSE; */
 #endif
             }
 #endif
         }
-        if(g_unlink(datafile) != 0 && errno != ENOENT)
+        if (g_unlink(datafile) != 0 && errno != ENOENT)
         {
             qof_backend_set_error(be, ERR_BACKEND_READONLY);
             PWARN("unable to unlink filename %s: %s",
-                  datafile ? datafile : "(null)", 
-                  strerror(errno) ? strerror(errno) : ""); 
+                  datafile ? datafile : "(null)",
+                  strerror(errno) ? strerror(errno) : "");
             g_free(tmp_name);
             LEAVE("");
             return FALSE;
         }
-        if(!gnc_int_link_or_make_backup(fbe, tmp_name, datafile))
+        if (!gnc_int_link_or_make_backup(fbe, tmp_name, datafile))
         {
             qof_backend_set_error(be, ERR_FILEIO_BACKUP_ERROR);
             g_free(tmp_name);
             LEAVE("");
             return FALSE;
         }
-        if(g_unlink(tmp_name) != 0)
+        if (g_unlink(tmp_name) != 0)
         {
             qof_backend_set_error(be, ERR_BACKEND_PERM);
-            PWARN("unable to unlink temp filename %s: %s", 
-                   tmp_name ? tmp_name : "(null)", 
-                   strerror(errno) ? strerror(errno) : ""); 
+            PWARN("unable to unlink temp filename %s: %s",
+                  tmp_name ? tmp_name : "(null)",
+                  strerror(errno) ? strerror(errno) : "");
             g_free(tmp_name);
             LEAVE("");
             return FALSE;
         }
         g_free(tmp_name);
 
-        /* Since we successfully saved the book, 
+        /* Since we successfully saved the book,
          * we should mark it clean. */
         qof_book_mark_saved (book);
         LEAVE (" sucessful save of book=%p to file=%s", book, datafile);
@@ -655,23 +696,24 @@
     }
     else
     {
-        if(g_unlink(tmp_name) != 0)
+        if (g_unlink(tmp_name) != 0)
         {
-            switch (errno) {
+            switch (errno)
+            {
             case ENOENT:     /* tmp_name doesn't exist?  Assume "RO" error */
             case EACCES:
             case EPERM:
             case ENOSYS:
             case EROFS:
-              be_err = ERR_BACKEND_READONLY;
-              break;
+                be_err = ERR_BACKEND_READONLY;
+                break;
             default:
-              be_err = ERR_BACKEND_MISC;
+                be_err = ERR_BACKEND_MISC;
             }
             qof_backend_set_error(be, be_err);
-            PWARN("unable to unlink temp_filename %s: %s", 
-                   tmp_name ? tmp_name : "(null)", 
-                   strerror(errno) ? strerror(errno) : ""); 
+            PWARN("unable to unlink temp_filename %s: %s",
+                  tmp_name ? tmp_name : "(null)",
+                  strerror(errno) ? strerror(errno) : "");
             /* already in an error just flow on through */
         }
         g_free(tmp_name);
@@ -728,30 +770,31 @@
         return;
 
     now = time(NULL);
-    while((dent = g_dir_read_name(dir)) != NULL) {
+    while ((dent = g_dir_read_name(dir)) != NULL)
+    {
         char *name;
         int len;
 
         if (gnc_xml_be_select_files (dent) == 0)
-             continue;
+            continue;
 
         name = g_build_filename(be->dirname, dent, (gchar*)NULL);
         len = strlen(name) - 4;
 
         /* Is this file associated with the current data file */
-        if (strncmp(name, be->fullpath, pathlen) == 0) 
+        if (strncmp(name, be->fullpath, pathlen) == 0)
         {
             if ((safe_strcmp(name + len, ".LNK") == 0) &&
-                /* Is a lock file. Skip the active lock file */
-                (safe_strcmp(name, be->linkfile) != 0) &&
-                /* Only delete lock files older than the active one */
-                (g_stat(name, &statbuf) == 0) &&
-                (statbuf.st_mtime <lockstatbuf.st_mtime)) 
+                    /* Is a lock file. Skip the active lock file */
+                    (safe_strcmp(name, be->linkfile) != 0) &&
+                    /* Only delete lock files older than the active one */
+                    (g_stat(name, &statbuf) == 0) &&
+                    (statbuf.st_mtime < lockstatbuf.st_mtime))
             {
                 PINFO ("unlink lock file: %s", name);
                 g_unlink(name);
-            } 
-            else if (be->file_retention_days > 0) 
+            }
+            else if (be->file_retention_days > 0)
             {
                 time_t file_time;
                 struct tm file_tm;
@@ -762,17 +805,17 @@
 
                 /* Is the backup file old enough to delete */
                 memset(&file_tm, 0, sizeof(file_tm));
-                res = strptime(name+pathlen+1, "%Y%m%d%H%M%S", &file_tm);
+                res = strptime(name + pathlen + 1, "%Y%m%d%H%M%S", &file_tm);
                 file_time = mktime(&file_tm);
                 days = (int)(difftime(now, file_time) / 86400);
 
-                
+
                 if (res
-                    && res != name+pathlen+1
-                    && (strcmp(res, ".xac") == 0
-                        || strcmp(res, ".log") == 0)
-                    && file_time > 0
-                    && days > be->file_retention_days)
+                        && res != name + pathlen + 1
+                        && (strcmp(res, ".xac") == 0
+                            || strcmp(res, ".log") == 0)
+                        && file_time > 0
+                        && days > be->file_retention_days)
                 {
                     PINFO ("g_unlink stale (%d days old) file: %s", days, name);
                     g_unlink(name);
@@ -824,7 +867,7 @@
     str = g_new (char, len);
     strcpy (str, fbe->fullpath);
 
-    /* XXX it would be nice for the user if we made the book 
+    /* XXX it would be nice for the user if we made the book
      * closing date and/or title part of the file-name. */
     p = strrchr (str, G_DIR_SEPARATOR);
     p++;
@@ -860,8 +903,8 @@
     }
     /* XXX To be anal about it, we should really be checking to see
      * if there already is a file with this book GUID, and disallowing
-     * further progress.  This is because we are not allowed to 
-     * modify books that are closed (They should be treated as 
+     * further progress.  This is because we are not allowed to
+     * modify books that are closed (They should be treated as
      * 'read-only').
      */
 #endif
@@ -881,10 +924,11 @@
 static void
 xml_commit_edit (QofBackend *be, QofInstance *inst)
 {
-    if (qof_instance_get_dirty(inst) && qof_get_alt_dirty_mode() && 
-        !(qof_instance_get_infant(inst) && qof_instance_get_destroying(inst))) {
-      qof_collection_mark_dirty(qof_instance_get_collection(inst));
-      qof_book_mark_dirty(qof_instance_get_book(inst));
+    if (qof_instance_get_dirty(inst) && qof_get_alt_dirty_mode() &&
+            !(qof_instance_get_infant(inst) && qof_instance_get_destroying(inst)))
+    {
+        qof_collection_mark_dirty(qof_instance_get_collection(inst));
+        qof_book_mark_dirty(qof_instance_get_book(inst));
     }
 #if BORKEN_FOR_NOW
     FileBackend *fbe = (FileBackend *) be;
@@ -920,7 +964,7 @@
     gboolean rc;
     FileBackend *be = (FileBackend *) bend;
 
-	if (loadType != LOAD_TYPE_INITIAL_LOAD) return;
+    if (loadType != LOAD_TYPE_INITIAL_LOAD) return;
 
     error = ERR_BACKEND_NO_ERR;
     be->primary_book = book;
@@ -941,27 +985,27 @@
         break;
     default:
         /* If file type wasn't known, check errno again to give the
-	   user some more useful feedback for some particular error
-	   conditions. */
+        user some more useful feedback for some particular error
+        conditions. */
         switch (errno)
-	{
-	case EACCES: /* No read permission */
-	  PWARN("No read permission to file");
-	  error = ERR_FILEIO_FILE_EACCES;
-	  break;
-	case EISDIR: /* File is a directory - but on this error we don't arrive here */
-	  PWARN("Filename is a directory");
-	  error = ERR_FILEIO_FILE_NOT_FOUND;
-	  break;
-	default:
-	  PWARN("File not any known type");
-	  error = ERR_FILEIO_UNKNOWN_FILE_TYPE;
-	  break;
-	}
+        {
+        case EACCES: /* No read permission */
+            PWARN("No read permission to file");
+            error = ERR_FILEIO_FILE_EACCES;
+            break;
+        case EISDIR: /* File is a directory - but on this error we don't arrive here */
+            PWARN("Filename is a directory");
+            error = ERR_FILEIO_FILE_NOT_FOUND;
+            break;
+        default:
+            PWARN("File not any known type");
+            error = ERR_FILEIO_UNKNOWN_FILE_TYPE;
+            break;
+        }
         break;
     }
 
-    if(error != ERR_BACKEND_NO_ERR) 
+    if (error != ERR_BACKEND_NO_ERR)
     {
         qof_backend_set_error(bend, error);
     }
@@ -975,13 +1019,13 @@
 static gboolean
 gnc_xml_be_save_may_clobber_data (QofBackend *bend)
 {
-  struct stat statbuf;
-  if (!bend->fullpath) return FALSE;
+    struct stat statbuf;
+    if (!bend->fullpath) return FALSE;
 
-  /* FIXME: Make sure this doesn't need more sophisticated semantics
-   * in the face of special file, devices, pipes, symlinks, etc. */
-  if (g_stat(bend->fullpath, &statbuf) == 0) return TRUE;
-  return FALSE;
+    /* FIXME: Make sure this doesn't need more sophisticated semantics
+     * in the face of special file, devices, pipes, symlinks, etc. */
+    if (g_stat(bend->fullpath, &statbuf) == 0) return TRUE;
+    return FALSE;
 }
 
 
@@ -1015,65 +1059,65 @@
 static void
 retain_changed_cb(GConfEntry *entry, gpointer user_data)
 {
-        FileBackend *be = (FileBackend*)user_data;
-        g_return_if_fail(be != NULL);
-        be->file_retention_days = (int)gnc_gconf_get_float("general", "retain_days", NULL);
+    FileBackend *be = (FileBackend*)user_data;
+    g_return_if_fail(be != NULL);
+    be->file_retention_days = (int)gnc_gconf_get_float("general", "retain_days", NULL);
 }
 
 static void
 compression_changed_cb(GConfEntry *entry, gpointer user_data)
 {
-        FileBackend *be = (FileBackend*)user_data;
-        g_return_if_fail(be != NULL);
-        be->file_compression = gnc_gconf_get_bool("general", "file_compression", NULL);
+    FileBackend *be = (FileBackend*)user_data;
+    g_return_if_fail(be != NULL);
+    be->file_compression = gnc_gconf_get_bool("general", "file_compression", NULL);
 }
 
 static QofBackend*
 gnc_backend_new(void)
 {
-	FileBackend *gnc_be;
-	QofBackend *be;
+    FileBackend *gnc_be;
+    QofBackend *be;
 
-	gnc_be = g_new0(FileBackend, 1);
-	be = (QofBackend*) gnc_be;
-	qof_backend_init(be);
+    gnc_be = g_new0(FileBackend, 1);
+    be = (QofBackend*) gnc_be;
+    qof_backend_init(be);
 
-	be->session_begin = xml_session_begin;
-	be->session_end = xml_session_end;
-	be->destroy_backend = xml_destroy_backend;
+    be->session_begin = xml_session_begin;
+    be->session_end = xml_session_end;
+    be->destroy_backend = xml_destroy_backend;
 
-	be->load = gnc_xml_be_load_from_file;
-	be->save_may_clobber_data = gnc_xml_be_save_may_clobber_data;
+    be->load = gnc_xml_be_load_from_file;
+    be->save_may_clobber_data = gnc_xml_be_save_may_clobber_data;
 
-	/* The file backend treats accounting periods transactionally. */
-	be->begin = xml_begin_edit;
-	be->commit = xml_commit_edit;
-	be->rollback = xml_rollback_edit;
+    /* The file backend treats accounting periods transactionally. */
+    be->begin = xml_begin_edit;
+    be->commit = xml_commit_edit;
+    be->rollback = xml_rollback_edit;
 
-	/* The file backend always loads all data ... */
-	be->compile_query = NULL;
-	be->free_query = NULL;
-	be->run_query = NULL;
+    /* The file backend always loads all data ... */
+    be->compile_query = NULL;
+    be->free_query = NULL;
+    be->run_query = NULL;
 
-	be->counter = NULL;
+    be->counter = NULL;
 
-	/* The file backend will never be multi-user... */
-	be->events_pending = NULL;
-	be->process_events = NULL;
+    /* The file backend will never be multi-user... */
+    be->events_pending = NULL;
+    be->process_events = NULL;
 
-	be->sync = xml_sync_all;
-	be->load_config = NULL;
-	be->get_config = NULL;
+    be->sync = xml_sync_all;
+    be->load_config = NULL;
+    be->get_config = NULL;
 
     be->export = gnc_xml_be_write_accounts_to_file;
 
-	gnc_be->dirname = NULL;
-	gnc_be->fullpath = NULL;
-	gnc_be->lockfile = NULL;
-	gnc_be->linkfile = NULL;
-	gnc_be->lockfd = -1;
+    gnc_be->dirname = NULL;
+    gnc_be->fullpath = NULL;
+    gnc_be->lockfile = NULL;
+    gnc_be->linkfile = NULL;
+    gnc_be->lockfd = -1;
 
-	gnc_be->primary_book = NULL;
+    gnc_be->primary_book = NULL;
 
     gnc_be->file_retention_days = (int)gnc_gconf_get_float("general", "retain_days", NULL);
     gnc_be->file_compression = gnc_gconf_get_bool("general", "file_compression", NULL);
@@ -1081,38 +1125,38 @@
     gnc_gconf_general_register_cb("retain_days", retain_changed_cb, be);
     gnc_gconf_general_register_cb("file_compression", compression_changed_cb, be);
 
-	return be;
+    return be;
 }
 
 static void
 gnc_provider_free (QofBackendProvider *prov)
 {
-        prov->provider_name = NULL;
-        prov->access_method = NULL;
-        g_free (prov);
+    prov->provider_name = NULL;
+    prov->access_method = NULL;
+    g_free (prov);
 }
 
 G_MODULE_EXPORT void
 qof_backend_module_init(void)
 {
-        QofBackendProvider *prov;
-        prov = g_new0 (QofBackendProvider, 1);
-        prov->provider_name = "GnuCash File Backend Version 2";
-        prov->access_method = "file";
-        prov->partial_book_supported = FALSE;
-        prov->backend_new = gnc_backend_new;
-        prov->provider_free = gnc_provider_free;
-        prov->check_data_type = gnc_determine_file_type;
-        qof_backend_register_provider (prov);
+    QofBackendProvider *prov;
+    prov = g_new0 (QofBackendProvider, 1);
+    prov->provider_name = "GnuCash File Backend Version 2";
+    prov->access_method = "file";
+    prov->partial_book_supported = FALSE;
+    prov->backend_new = gnc_backend_new;
+    prov->provider_free = gnc_provider_free;
+    prov->check_data_type = gnc_determine_file_type;
+    qof_backend_register_provider (prov);
 
-        prov = g_new0 (QofBackendProvider, 1);
-        prov->provider_name = "GnuCash File Backend Version 2";
-        prov->access_method = "xml";
-        prov->partial_book_supported = FALSE;
-        prov->backend_new = gnc_backend_new;
-        prov->provider_free = gnc_provider_free;
-        prov->check_data_type = gnc_determine_file_type;
-        qof_backend_register_provider (prov);
+    prov = g_new0 (QofBackendProvider, 1);
+    prov->provider_name = "GnuCash File Backend Version 2";
+    prov->access_method = "xml";
+    prov->partial_book_supported = FALSE;
+    prov->backend_new = gnc_backend_new;
+    prov->provider_free = gnc_provider_free;
+    prov->check_data_type = gnc_determine_file_type;
+    qof_backend_register_provider (prov);
 }
 
 /* ========================== END OF FILE ===================== */

Modified: gnucash/trunk/src/backend/xml/gnc-backend-xml.h
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-backend-xml.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-backend-xml.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -19,7 +19,7 @@
  * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
 \********************************************************************/
 /** @file gnc-backend-xml.h
- *  @brief load and save data to files 
+ *  @brief load and save data to files
  *  @author Copyright (c) 2000 Gnumatic Inc.
  *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
  *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
@@ -37,18 +37,18 @@
 #include "qofbackend-p.h"
 struct FileBackend_struct
 {
-  QofBackend be;
+    QofBackend be;
 
-  char *dirname;
-  char *fullpath;  /* Fully qualified path to book */
-  char *lockfile;
-  char *linkfile;
-  int lockfd;
+    char *dirname;
+    char *fullpath;  /* Fully qualified path to book */
+    char *lockfile;
+    char *linkfile;
+    int lockfd;
 
-  QofBook *primary_book;  /* The primary, main open book */
-  
-  int file_retention_days;
-  gboolean file_compression;
+    QofBook *primary_book;  /* The primary, main open book */
+
+    int file_retention_days;
+    gboolean file_compression;
 };
 
 typedef struct FileBackend_struct FileBackend;

Modified: gnucash/trunk/src/backend/xml/gnc-book-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-book-xml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-book-xml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -63,13 +63,13 @@
 
 static void
 append_account_tree (xmlNodePtr parent,
-		     Account *account,
-		     gboolean allow_incompat)
+                     Account *account,
+                     gboolean allow_incompat)
 {
     GList *children, *node;
 
     children = gnc_account_get_children(account);
-    for (node = children; node; node = node->next) 
+    for (node = children; node; node = node->next)
     {
         xmlNodePtr accnode;
         Account *account;
@@ -106,46 +106,48 @@
     ret = xmlNewNode(NULL, BAD_CAST gnc_book_string);
     xmlSetProp(ret, BAD_CAST "version", BAD_CAST gnc_v2_book_version_string);
 
-    xmlAddChild(ret, guid_to_dom_tree(book_id_string, 
+    xmlAddChild(ret, guid_to_dom_tree(book_id_string,
                                       qof_book_get_guid(book)));
 
-    if (qof_book_get_slots(book)) {
+    if (qof_book_get_slots(book))
+    {
         xmlNodePtr kvpnode = kvp_frame_to_dom_tree(book_slots_string,
-                                                   qof_book_get_slots(book));
+                             qof_book_get_slots(book));
         if (kvpnode)
             xmlAddChild(ret, kvpnode);
     }
 
 #ifdef IMPLEMENT_BOOK_DOM_TREES_LATER
     /* theoretically, we should be adding all the below to the book
-     * but in fact, there's enough brain damage in the code already 
+     * but in fact, there's enough brain damage in the code already
      * that we are only going to hand-edit the file at a higher layer.
      * And that's OK, since its probably a performance boost anyway.
      */
     xmlAddChild(ret, gnc_commodity_dom_tree_create(
                     gnc_book_get_commodity_table(book)));
     xmlAddChild(ret, gnc_pricedb_dom_tree_create(gnc_book_get_pricedb(book)));
-    if (allow_incompat) {
-      accnode = gnc_account_dom_tree_create(account, FALSE);
-      xmlAddChild (ret, rootAccNode);
+    if (allow_incompat)
+    {
+        accnode = gnc_account_dom_tree_create(account, FALSE);
+        xmlAddChild (ret, rootAccNode);
     }
     append_account_tree (ret, gnc_book_get_root(book));
 
     xaccAccountTreeForEachTransaction (gnc_book_get_root_account(book),
-				       traverse_txns, ret);
+                                       traverse_txns, ret);
 
-    /* xxx FIXME hack alert how are we going to handle 
+    /* xxx FIXME hack alert how are we going to handle
      *  gnc_book_get_template_group handled ???   */
     xmlAddChild(ret, gnc_schedXaction_dom_tree_create(
                     gnc_book_get_schedxactions(book)));
 
-#endif 
+#endif
 
     return ret;
 }
 
 /* ================================================================ */
-/* same as above, but we write out directly.  Only handle the guid 
+/* same as above, but we write out directly.  Only handle the guid
  * and slots, everything else is handled elsewhere */
 
 void
@@ -155,18 +157,21 @@
 
     domnode = guid_to_dom_tree(book_id_string, qof_book_get_guid(book));
     xmlElemDump(out, NULL, domnode);
-    if (fprintf(out, "\n") < 0) {
-        qof_backend_set_error(qof_book_get_backend(book), 
+    if (fprintf(out, "\n") < 0)
+    {
+        qof_backend_set_error(qof_book_get_backend(book),
                               ERR_FILEIO_WRITE_ERROR);
         xmlFreeNode(domnode);
         return;
     }
     xmlFreeNode (domnode);
 
-    if (qof_book_get_slots(book)) {
+    if (qof_book_get_slots(book))
+    {
         xmlNodePtr kvpnode = kvp_frame_to_dom_tree(book_slots_string,
-                                                   qof_book_get_slots(book));
-        if(kvpnode) {
+                             qof_book_get_slots(book));
+        if (kvpnode)
+        {
             xmlElemDump(out, NULL, kvpnode);
             fprintf(out, "\n");
             xmlFreeNode(kvpnode);
@@ -186,7 +191,7 @@
     guid = dom_tree_to_guid(node);
     qof_instance_set_guid(QOF_INSTANCE(book), guid);
     g_free(guid);
-    
+
     return TRUE;
 }
 
@@ -196,17 +201,18 @@
     QofBook *book = book_pdata;
     gboolean success;
 
-    /* the below works only because the get is gaurenteed to return 
+    /* the below works only because the get is gaurenteed to return
      * a frame, even if its empty */
     success = dom_tree_to_kvp_frame_given (node, qof_book_get_slots (book));
 
     g_return_val_if_fail(success, FALSE);
-    
+
     return TRUE;
 }
 
 
-static struct dom_tree_handler book_handlers_v2[] = {
+static struct dom_tree_handler book_handlers_v2[] =
+{
     { book_id_string, book_id_handler, 1, 0 },
     { book_slots_string, book_slots_handler, 0, 0 },
     { NULL, 0, 0, 0 }
@@ -293,7 +299,8 @@
 
     successful = dom_tree_generic_parse (node, book_handlers_v2,
                                          book);
-    if (!successful) {
+    if (!successful)
+    {
         PERR ("failed to parse book");
         book = NULL;
     }

Modified: gnucash/trunk/src/backend/xml/gnc-budget-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-budget-xml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-budget-xml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -72,7 +72,7 @@
                                       gnc_budget_get_name(bgt)));
     /* field: char* description */
     xmlAddChild(ret, text_to_dom_tree(bgt_description_string,
-				      gnc_budget_get_description(bgt)));
+                                      gnc_budget_get_description(bgt)));
     /* field: guint num_periods */
     xmlAddChild(ret, guint_to_dom_tree(bgt_num_periods_string,
                                        gnc_budget_get_num_periods(bgt)));
@@ -81,7 +81,8 @@
                                             gnc_budget_get_recurrence(bgt)));
     /* slots */
     kf = qof_instance_get_slots(QOF_INSTANCE(bgt));
-    if (kf) {
+    if (kf)
+    {
         xmlNodePtr kvpnode = kvp_frame_to_dom_tree(bgt_slots_string, kf);
         if (kvpnode)
             xmlAddChild(ret, kvpnode);
@@ -94,7 +95,7 @@
 /***********************************************************************/
 static inline gboolean
 set_string(xmlNodePtr node, GncBudget* bgt,
-	       void (*func)(GncBudget *bgt, const gchar *txt))
+           void (*func)(GncBudget *bgt, const gchar *txt))
 {
     gchar* txt = dom_tree_to_text(node);
     g_return_val_if_fail(txt, FALSE);
@@ -133,34 +134,37 @@
 {
     guint num_periods;
 
-    if (dom_tree_to_guint(node, &num_periods)) {
+    if (dom_tree_to_guint(node, &num_periods))
+    {
         gnc_budget_set_num_periods(GNC_BUDGET(bgt), num_periods);
         return TRUE;
-    } else
+    }
+    else
         return FALSE;
 }
 
 static gboolean
 budget_recurrence_handler (xmlNodePtr node, gpointer bgt)
 {
-  Recurrence *r;
+    Recurrence *r;
 
-  if ((r = dom_tree_to_recurrence(node)) == NULL)
-      return FALSE;
+    if ((r = dom_tree_to_recurrence(node)) == NULL)
+        return FALSE;
 
-  gnc_budget_set_recurrence(GNC_BUDGET(bgt), r);
-  g_free(r);
-  return TRUE;
+    gnc_budget_set_recurrence(GNC_BUDGET(bgt), r);
+    g_free(r);
+    return TRUE;
 }
 
 static gboolean
 budget_slots_handler (xmlNodePtr node, gpointer bgt)
 {
     return dom_tree_to_kvp_frame_given(
-        node, qof_instance_get_slots(QOF_INSTANCE(bgt)));
+               node, qof_instance_get_slots(QOF_INSTANCE(bgt)));
 }
 
-static struct dom_tree_handler budget_handlers[] = {
+static struct dom_tree_handler budget_handlers[] =
+{
     { bgt_id_string, budget_id_handler, 1, 0 },
     { bgt_name_string, budget_name_handler, 0, 0 },
     { bgt_description_string, budget_description_handler, 0, 0 },
@@ -181,13 +185,15 @@
     gxpf_data *gdata = (gxpf_data*)global_data;
     QofBook *book = gdata->bookdata;
 
-    if (parent_data) {
+    if (parent_data)
+    {
         return TRUE;
     }
 
     /* OK.  For some messed up reason this is getting called again with a
        NULL tag.  So we ignore those cases */
-    if(!tag) {
+    if (!tag)
+    {
         return TRUE;
     }
 
@@ -195,7 +201,8 @@
 
     bgt = dom_tree_to_budget(tree, book);
     xmlFreeNode(tree);
-    if(bgt != NULL) {
+    if (bgt != NULL)
+    {
         /* ends up calling book_callback */
         gdata->cb(tag, gdata->parsedata, bgt);
     }
@@ -210,7 +217,8 @@
     GncBudget *bgt;
 
     bgt = gnc_budget_new(book);
-    if (!dom_tree_generic_parse (node, budget_handlers, bgt)) {
+    if (!dom_tree_generic_parse (node, budget_handlers, bgt))
+    {
         PERR ("failed to parse budget tree");
         gnc_budget_destroy(bgt);
         bgt = NULL;

Modified: gnucash/trunk/src/backend/xml/gnc-commodity-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-commodity-xml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-commodity-xml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -67,53 +67,55 @@
     xmlNodePtr ret;
     gboolean currency = gnc_commodity_is_iso(com);
     xmlNodePtr kvpnode =
-      kvp_frame_to_dom_tree(cmdty_slots,
-			    qof_instance_get_slots(QOF_INSTANCE(com)));
+        kvp_frame_to_dom_tree(cmdty_slots,
+                              qof_instance_get_slots(QOF_INSTANCE(com)));
 
     if (currency && !gnc_commodity_get_quote_flag(com) && !kvpnode)
-      return NULL;
+        return NULL;
 
     ret = xmlNewNode(NULL, BAD_CAST gnc_commodity_string);
 
     xmlSetProp(ret, BAD_CAST "version", BAD_CAST commodity_version_string);
-    
+
     xmlAddChild(ret, text_to_dom_tree(cmdty_namespace,
                                       gnc_commodity_get_namespace_compat(com)));
     xmlAddChild(ret, text_to_dom_tree(cmdty_id,
                                       gnc_commodity_get_mnemonic(com)));
 
-    if (!currency) {
-      if(gnc_commodity_get_fullname(com))
-      {
-      	  xmlAddChild(ret, text_to_dom_tree(cmdty_name,
-                                            gnc_commodity_get_fullname(com)));
-      }
-      
-      if(gnc_commodity_get_cusip(com) &&
-         strlen(gnc_commodity_get_cusip(com)) > 0)
-      {
-          xmlAddChild(ret, text_to_dom_tree(
-                          cmdty_xcode,
-                          gnc_commodity_get_cusip(com)));
-      }
-      
-      xmlAddChild(ret, int_to_dom_tree(cmdty_fraction,
-                                       gnc_commodity_get_fraction(com)));
+    if (!currency)
+    {
+        if (gnc_commodity_get_fullname(com))
+        {
+            xmlAddChild(ret, text_to_dom_tree(cmdty_name,
+                                              gnc_commodity_get_fullname(com)));
+        }
+
+        if (gnc_commodity_get_cusip(com) &&
+                strlen(gnc_commodity_get_cusip(com)) > 0)
+        {
+            xmlAddChild(ret, text_to_dom_tree(
+                            cmdty_xcode,
+                            gnc_commodity_get_cusip(com)));
+        }
+
+        xmlAddChild(ret, int_to_dom_tree(cmdty_fraction,
+                                         gnc_commodity_get_fraction(com)));
     }
 
-    if (gnc_commodity_get_quote_flag(com)) {
-      xmlNewChild(ret, NULL, BAD_CAST cmdty_get_quotes, NULL);
-      source = gnc_commodity_get_quote_source(com);
-      if (source)
-	xmlAddChild(ret, text_to_dom_tree(cmdty_quote_source,
-					  gnc_quote_source_get_internal_name(source)));
-      string = gnc_commodity_get_quote_tz(com);
-      if (string)
-	xmlAddChild(ret, text_to_dom_tree(cmdty_quote_tz, string));
+    if (gnc_commodity_get_quote_flag(com))
+    {
+        xmlNewChild(ret, NULL, BAD_CAST cmdty_get_quotes, NULL);
+        source = gnc_commodity_get_quote_source(com);
+        if (source)
+            xmlAddChild(ret, text_to_dom_tree(cmdty_quote_source,
+                                              gnc_quote_source_get_internal_name(source)));
+        string = gnc_commodity_get_quote_tz(com);
+        if (string)
+            xmlAddChild(ret, text_to_dom_tree(cmdty_quote_tz, string));
     }
 
     if (kvpnode)
-      xmlAddChild(ret, kvpnode);
+        xmlAddChild(ret, kvpnode);
 
     return ret;
 }
@@ -126,7 +128,8 @@
     void(*func)(gnc_commodity *com, const char*val);
 };
 
-struct com_char_handler com_handlers[] = {
+struct com_char_handler com_handlers[] =
+{
     { cmdty_namespace,    gnc_commodity_set_namespace },
     { cmdty_id,           gnc_commodity_set_mnemonic },
     { cmdty_name,         gnc_commodity_set_fullname },
@@ -138,47 +141,47 @@
 static void
 set_commodity_value(xmlNodePtr node, gnc_commodity* com)
 {
-    if(safe_strcmp((char*) node->name, cmdty_fraction) == 0)
+    if (safe_strcmp((char*) node->name, cmdty_fraction) == 0)
     {
         gint64 val;
         char *string;
 
         string = (char*) xmlNodeGetContent (node->xmlChildrenNode);
-        if(string_to_gint64(string, &val))
+        if (string_to_gint64(string, &val))
         {
             gnc_commodity_set_fraction(com, val);
         }
         xmlFree (string);
     }
-    else if(safe_strcmp((char*)node->name, cmdty_get_quotes) == 0)
+    else if (safe_strcmp((char*)node->name, cmdty_get_quotes) == 0)
     {
-	gnc_commodity_set_quote_flag(com, TRUE);
+        gnc_commodity_set_quote_flag(com, TRUE);
     }
-    else if(safe_strcmp((char*)node->name, cmdty_quote_source) == 0)
+    else if (safe_strcmp((char*)node->name, cmdty_quote_source) == 0)
     {
         gnc_quote_source *source;
         char *string;
 
         string = (char*) xmlNodeGetContent (node->xmlChildrenNode);
-	source = gnc_quote_source_lookup_by_internal(string);
-	if (!source)
-	  source = gnc_quote_source_add_new(string, FALSE);
-	gnc_commodity_set_quote_source(com, source);
+        source = gnc_quote_source_lookup_by_internal(string);
+        if (!source)
+            source = gnc_quote_source_add_new(string, FALSE);
+        gnc_commodity_set_quote_source(com, source);
         xmlFree (string);
     }
-    else if(safe_strcmp((char*)node->name, cmdty_slots) == 0)
+    else if (safe_strcmp((char*)node->name, cmdty_slots) == 0)
     {
-      /* We ignore the results here */
-      dom_tree_to_kvp_frame_given(node,
-				  qof_instance_get_slots(QOF_INSTANCE(com)));
+        /* We ignore the results here */
+        dom_tree_to_kvp_frame_given(node,
+                                    qof_instance_get_slots(QOF_INSTANCE(com)));
     }
-    else 
+    else
     {
         struct com_char_handler *mark;
 
-        for(mark = com_handlers; mark->tag; mark++)
+        for (mark = com_handlers; mark->tag; mark++)
         {
-            if(safe_strcmp(mark->tag, (char*)node->name) == 0)
+            if (safe_strcmp(mark->tag, (char*)node->name) == 0)
             {
                 gchar* val = dom_tree_to_text(node);
                 g_strstrip(val);
@@ -193,17 +196,17 @@
 static gboolean
 valid_commodity(gnc_commodity *com)
 {
-    if(gnc_commodity_get_namespace(com) == NULL)
+    if (gnc_commodity_get_namespace(com) == NULL)
     {
         PWARN("Invalid commodity: no namespace");
         return FALSE;
     }
-    if(gnc_commodity_get_mnemonic(com) == NULL)
+    if (gnc_commodity_get_mnemonic(com) == NULL)
     {
         PWARN("Invalid commodity: no mnemonic");
         return FALSE;
     }
-    if(gnc_commodity_get_fraction(com) == 0)
+    if (gnc_commodity_get_fraction(com) == 0)
     {
         PWARN("Invalid commodity: 0 fraction");
         return FALSE;
@@ -219,26 +222,26 @@
     gchar *exchange = NULL, *mnemonic = NULL;
     xmlNodePtr node;
 
-    for(node = tree->xmlChildrenNode; node; node = node->next)
+    for (node = tree->xmlChildrenNode; node; node = node->next)
     {
-      if (safe_strcmp((char*) node->name, cmdty_namespace) == 0)
-	exchange = (gchar*) xmlNodeGetContent (node->xmlChildrenNode);
-      if (safe_strcmp((char*) node->name, cmdty_id) == 0)
-	mnemonic = (gchar*) xmlNodeGetContent (node->xmlChildrenNode);
+        if (safe_strcmp((char*) node->name, cmdty_namespace) == 0)
+            exchange = (gchar*) xmlNodeGetContent (node->xmlChildrenNode);
+        if (safe_strcmp((char*) node->name, cmdty_id) == 0)
+            mnemonic = (gchar*) xmlNodeGetContent (node->xmlChildrenNode);
     }
 
     if (exchange
-        && gnc_commodity_namespace_is_iso(exchange)
-        && mnemonic)
+            && gnc_commodity_namespace_is_iso(exchange)
+            && mnemonic)
     {
-      table = gnc_commodity_table_get_table(book);
-      currency = gnc_commodity_table_lookup(table, exchange, mnemonic);
+        table = gnc_commodity_table_get_table(book);
+        currency = gnc_commodity_table_lookup(table, exchange, mnemonic);
     }
 
     if (exchange)
-      xmlFree(exchange);
+        xmlFree(exchange);
     if (mnemonic)
-      xmlFree(mnemonic);
+        xmlFree(mnemonic);
 
     return currency;
 }
@@ -255,31 +258,31 @@
     gxpf_data *gdata = (gxpf_data*)global_data;
     QofBook *book = gdata->bookdata;
 
-    if(parent_data)
+    if (parent_data)
     {
         return TRUE;
     }
 
     /* OK.  For some messed up reason this is getting called again with a
        NULL tag.  So we ignore those cases */
-    if(!tag)
+    if (!tag)
     {
         return TRUE;
     }
-    
+
     g_return_val_if_fail(tree, FALSE);
 
-    com = gnc_commodity_new(book, NULL, NULL, NULL, NULL, 0); 
+    com = gnc_commodity_new(book, NULL, NULL, NULL, NULL, 0);
     old_com = gnc_commodity_find_currency(book, tree);
     if (old_com)
         gnc_commodity_copy(com, old_com);
 
-    for(achild = tree->xmlChildrenNode; achild; achild = achild->next)
+    for (achild = tree->xmlChildrenNode; achild; achild = achild->next)
     {
         set_commodity_value(achild, com);
     }
 
-    if(!valid_commodity(com))
+    if (!valid_commodity(com))
     {
         PWARN("Invalid commodity parsed");
         xmlElemDump(stdout, NULL, tree);
@@ -292,7 +295,7 @@
     gdata->cb(tag, gdata->parsedata, com);
 
     xmlFreeNode(tree);
-    
+
     return TRUE;
 }
 

Modified: gnucash/trunk/src/backend/xml/gnc-freqspec-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-freqspec-xml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-freqspec-xml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -48,12 +48,14 @@
 
 const gchar *freqspec_version_string = "1.0.0";
 
-struct freqTypeTuple {
+struct freqTypeTuple
+{
     char         *str;
     FreqType        ft;
 };
 
-struct freqTypeTuple freqTypeStrs[] = {
+struct freqTypeTuple freqTypeStrs[] =
+{
     { "none",             INVALID },
     { "once",             ONCE },
     { "daily",            DAILY },
@@ -64,12 +66,14 @@
     { NULL,               -1 },
 };
 
-struct uiFreqTypeTuple {
+struct uiFreqTypeTuple
+{
     char        *str;
     UIFreqType        uift;
 };
 
-struct uiFreqTypeTuple uiFreqTypeStrs[] = {
+struct uiFreqTypeTuple uiFreqTypeStrs[] =
+{
     { "none",         UIFREQ_NONE },
     { "once",         UIFREQ_ONCE },
     { "daily",        UIFREQ_DAILY },
@@ -90,37 +94,37 @@
  **/
 typedef struct
 {
-        QofBook         *book;            /* Book we're loading into. */
+    QofBook         *book;            /* Book we're loading into. */
 
-        Recurrence *recurrence;
-        GList *recurrence_list;
+    Recurrence *recurrence;
+    GList *recurrence_list;
 
-        /* fields used in the union of unions... :) */
-        GDate                 once_day;     /* once */
-        gint64                interval;     /* all [except once] */
-        gint64                offset;       /* all [except once] */
-        gint64                day;          /* monthly or month-relative */
-        gint64                occurrence;   /* month-relative */
-        gint64                weekend_adj;  /* monthly/yearly */
-        GList                *list;         /* composite */
-        UIFreqType            uift;
+    /* fields used in the union of unions... :) */
+    GDate                 once_day;     /* once */
+    gint64                interval;     /* all [except once] */
+    gint64                offset;       /* all [except once] */
+    gint64                day;          /* monthly or month-relative */
+    gint64                occurrence;   /* month-relative */
+    gint64                weekend_adj;  /* monthly/yearly */
+    GList                *list;         /* composite */
+    UIFreqType            uift;
 } fsParseData;
 
 static void
 fspd_init( fsParseData *fspd )
 {
-        fspd->list    = NULL;
-        fspd->book    = NULL;
-        fspd->recurrence = g_new0(Recurrence, 1);
-        fspd->recurrence_list = NULL;
-        fspd->uift = UIFREQ_NONE;
-        fspd->interval
-                = fspd->offset
-                = fspd->day
-                = fspd->occurrence
-                = 0;
-        fspd->weekend_adj = WEEKEND_ADJ_NONE;
-        g_date_clear( &fspd->once_day, 1 );
+    fspd->list    = NULL;
+    fspd->book    = NULL;
+    fspd->recurrence = g_new0(Recurrence, 1);
+    fspd->recurrence_list = NULL;
+    fspd->uift = UIFREQ_NONE;
+    fspd->interval
+    = fspd->offset
+      = fspd->day
+        = fspd->occurrence
+          = 0;
+    fspd->weekend_adj = WEEKEND_ADJ_NONE;
+    g_date_clear( &fspd->once_day, 1 );
 }
 
 static struct dom_tree_handler fs_dom_handlers[];
@@ -129,313 +133,318 @@
 gboolean
 gnc_fs_handler( xmlNodePtr node, gpointer d )
 {
-  return dom_tree_generic_parse( node, fs_dom_handlers, d );
+    return dom_tree_generic_parse( node, fs_dom_handlers, d );
 }
 
 static
 gboolean
 fs_uift_handler( xmlNodePtr node, gpointer data)
 {
-        fsParseData *fspd = data;
-        int            i;
-        char        *nodeTxt;
-        char            *tmp;
+    fsParseData *fspd = data;
+    int            i;
+    char        *nodeTxt;
+    char            *tmp;
 
-        nodeTxt = dom_tree_to_text( node );
+    nodeTxt = dom_tree_to_text( node );
 
-        g_return_val_if_fail( nodeTxt, FALSE );
-        for ( i=0; (tmp = uiFreqTypeStrs[i].str) != NULL; i++ ) {
-                if ( safe_strcmp( nodeTxt, tmp ) == 0 ) {
-                        fspd->uift = uiFreqTypeStrs[i].uift;
-                        g_free( nodeTxt );
-                        return TRUE;
-                }
+    g_return_val_if_fail( nodeTxt, FALSE );
+    for ( i = 0; (tmp = uiFreqTypeStrs[i].str) != NULL; i++ )
+    {
+        if ( safe_strcmp( nodeTxt, tmp ) == 0 )
+        {
+            fspd->uift = uiFreqTypeStrs[i].uift;
+            g_free( nodeTxt );
+            return TRUE;
         }
-        g_free( nodeTxt );
-        return FALSE;
+    }
+    g_free( nodeTxt );
+    return FALSE;
 }
 
 static
 gboolean
 fs_date_handler( xmlNodePtr node, gpointer data )
 {
-        fsParseData *fspd = data;
-        GDate                *foo;
-        foo = dom_tree_to_gdate( node );
-        if ( foo == NULL )
-                return FALSE;
-        fspd->once_day = *foo;
-        g_date_free( foo );
-        return TRUE;
+    fsParseData *fspd = data;
+    GDate                *foo;
+    foo = dom_tree_to_gdate( node );
+    if ( foo == NULL )
+        return FALSE;
+    fspd->once_day = *foo;
+    g_date_free( foo );
+    return TRUE;
 }
 
 static
 gboolean
 fs_interval_handler( xmlNodePtr node, gpointer data )
 {
-        fsParseData *fspd = data;
-        gboolean        ret;
-        gint64          foo;
+    fsParseData *fspd = data;
+    gboolean        ret;
+    gint64          foo;
 
-        ret = dom_tree_to_integer( node, &foo );
-        if ( ! ret ) {
-                return ret;
-        }
-        fspd->interval = foo;
-        return TRUE;
+    ret = dom_tree_to_integer( node, &foo );
+    if ( ! ret )
+    {
+        return ret;
+    }
+    fspd->interval = foo;
+    return TRUE;
 }
 
 static
 gboolean
 fs_offset_handler( xmlNodePtr node, gpointer data )
 {
-        fsParseData *fspd = data;
-        gboolean        ret;
-        gint64          foo;
+    fsParseData *fspd = data;
+    gboolean        ret;
+    gint64          foo;
 
-        ret = dom_tree_to_integer( node, &foo );
-        if ( ! ret )
-                return ret;
-        fspd->offset = foo;
-        return TRUE;
+    ret = dom_tree_to_integer( node, &foo );
+    if ( ! ret )
+        return ret;
+    fspd->offset = foo;
+    return TRUE;
 }
 
 static
 gboolean
 fs_day_handler( xmlNodePtr node, gpointer data )
 {
-        fsParseData *fspd = data;
-        gboolean        ret;
-        gint64          foo;
+    fsParseData *fspd = data;
+    gboolean        ret;
+    gint64          foo;
 
-        ret = dom_tree_to_integer( node, &foo );
-        if ( ! ret )
-                return ret;
-        fspd->day = foo;
-        return TRUE;
+    ret = dom_tree_to_integer( node, &foo );
+    if ( ! ret )
+        return ret;
+    fspd->day = foo;
+    return TRUE;
 }
 
 static
 gboolean
 fs_weekday_handler( xmlNodePtr node, gpointer data)
 {
-        fsParseData *fspd = data;
-        gboolean        ret;
-        gint64          foo;
-        ret = dom_tree_to_integer( node, &foo );
-        if ( !ret )
-                return ret;
-        fspd->day = foo;
-        return TRUE;
+    fsParseData *fspd = data;
+    gboolean        ret;
+    gint64          foo;
+    ret = dom_tree_to_integer( node, &foo );
+    if ( !ret )
+        return ret;
+    fspd->day = foo;
+    return TRUE;
 }
 
 static
 gboolean
 fs_occurrence_handler( xmlNodePtr node, gpointer data )
 {
-        fsParseData *fspd = data;
-        gboolean        ret;
-        gint64          foo;
-        ret = dom_tree_to_integer( node, &foo );
-        if ( !ret )
-                return ret;
-        fspd->occurrence = foo;
-        return TRUE;
+    fsParseData *fspd = data;
+    gboolean        ret;
+    gint64          foo;
+    ret = dom_tree_to_integer( node, &foo );
+    if ( !ret )
+        return ret;
+    fspd->occurrence = foo;
+    return TRUE;
 }
 
 static
 gboolean
 fs_weekend_adj_handler( xmlNodePtr node, gpointer data )
 {
-        fsParseData *fspd = data;
-        gboolean        ret;
-        gint64          foo;
-        ret = dom_tree_to_integer( node, &foo );
-        if ( !ret )
-                return ret;
-        fspd->weekend_adj = foo;
-        return TRUE;
+    fsParseData *fspd = data;
+    gboolean        ret;
+    gint64          foo;
+    ret = dom_tree_to_integer( node, &foo );
+    if ( !ret )
+        return ret;
+    fspd->weekend_adj = foo;
+    return TRUE;
 }
 
 static
 gboolean
 fs_subelement_handler( xmlNodePtr node, gpointer data )
 {
-        fsParseData *fspd = data;
-        GList *recurrences;
+    fsParseData *fspd = data;
+    GList *recurrences;
 
-        recurrences = dom_tree_freqSpec_to_recurrences(node, fspd->book);
-        if (recurrences == NULL)
-                return FALSE;
+    recurrences = dom_tree_freqSpec_to_recurrences(node, fspd->book);
+    if (recurrences == NULL)
+        return FALSE;
 
+    {
+        GList *r_iter;
+        for (r_iter = recurrences; r_iter != NULL; r_iter = r_iter->next)
         {
-            GList *r_iter;
-            for (r_iter = recurrences; r_iter != NULL; r_iter = r_iter->next)
+            Recurrence *r = (Recurrence*)r_iter->data;
+            GDate recurrence_date;
+            if (fspd->uift == UIFREQ_SEMI_MONTHLY)
             {
-                Recurrence *r = (Recurrence*)r_iter->data;
-                GDate recurrence_date;
-                if (fspd->uift == UIFREQ_SEMI_MONTHLY)
-                {
-                    // complementry hack around 'once' freqspects not being valid. :/
-                    recurrence_date = recurrenceGetDate(r);
-                    recurrenceSet(r, recurrenceGetMultiplier(r), PERIOD_MONTH, &recurrence_date, recurrenceGetWeekendAdjust(r));
-                }
-                fspd->recurrence_list = g_list_append(fspd->recurrence_list, r);
+                // complementry hack around 'once' freqspects not being valid. :/
+                recurrence_date = recurrenceGetDate(r);
+                recurrenceSet(r, recurrenceGetMultiplier(r), PERIOD_MONTH, &recurrence_date, recurrenceGetWeekendAdjust(r));
             }
+            fspd->recurrence_list = g_list_append(fspd->recurrence_list, r);
         }
-        return TRUE;
+    }
+    return TRUE;
 }
 
-struct dom_tree_handler fs_union_dom_handlers[] = {
-        { "fs:date",        fs_date_handler,        0, 0 },
-        { "fs:interval",    fs_interval_handler,    0, 0 },
-        { "fs:offset",      fs_offset_handler,      0, 0 },
-        { "fs:day",         fs_day_handler,         0, 0 },
-        { "fs:weekday",     fs_weekday_handler,     0, 0 },
-        { "fs:occurrence",  fs_occurrence_handler,  0, 0 },
-        { "fs:weekend_adj", fs_weekend_adj_handler, 0, 0 },
-        { "gnc:freqspec",   fs_subelement_handler,  0, 0 },
-        { NULL, NULL, 0, 0 },
+struct dom_tree_handler fs_union_dom_handlers[] =
+{
+    { "fs:date",        fs_date_handler,        0, 0 },
+    { "fs:interval",    fs_interval_handler,    0, 0 },
+    { "fs:offset",      fs_offset_handler,      0, 0 },
+    { "fs:day",         fs_day_handler,         0, 0 },
+    { "fs:weekday",     fs_weekday_handler,     0, 0 },
+    { "fs:occurrence",  fs_occurrence_handler,  0, 0 },
+    { "fs:weekend_adj", fs_weekend_adj_handler, 0, 0 },
+    { "gnc:freqspec",   fs_subelement_handler,  0, 0 },
+    { NULL, NULL, 0, 0 },
 };
 
 static gboolean
 fs_none_handler( xmlNodePtr node, gpointer data )
 {
-        fsParseData *fspd = data;
-        gboolean	successful;
-        successful = dom_tree_generic_parse( node,
-                                             fs_union_dom_handlers,
-                                             fspd );
-        return successful;
+    fsParseData *fspd = data;
+    gboolean	successful;
+    successful = dom_tree_generic_parse( node,
+                                         fs_union_dom_handlers,
+                                         fspd );
+    return successful;
 }
 
 static
 gboolean
 fs_once_handler( xmlNodePtr node, gpointer data )
 {
-        fsParseData *fspd = data;
-        gboolean        successful;
+    fsParseData *fspd = data;
+    gboolean        successful;
 
-        successful = dom_tree_generic_parse( node,
-                                             fs_union_dom_handlers,
-                                             fspd );
-        if ( !successful )
-                return FALSE;
-        recurrenceSet(fspd->recurrence, 0, PERIOD_ONCE, &fspd->once_day, WEEKEND_ADJ_NONE);
-        
-        return TRUE;
+    successful = dom_tree_generic_parse( node,
+                                         fs_union_dom_handlers,
+                                         fspd );
+    if ( !successful )
+        return FALSE;
+    recurrenceSet(fspd->recurrence, 0, PERIOD_ONCE, &fspd->once_day, WEEKEND_ADJ_NONE);
+
+    return TRUE;
 }
 
 static gboolean
 fs_daily_handler(xmlNodePtr node, gpointer data)
 {
-        fsParseData *fspd = data;
-        GDate offset_date;
-        gboolean        successful;
-        successful = dom_tree_generic_parse(node, fs_union_dom_handlers, fspd );
-        if (!successful)
-             return FALSE;
+    fsParseData *fspd = data;
+    GDate offset_date;
+    gboolean        successful;
+    successful = dom_tree_generic_parse(node, fs_union_dom_handlers, fspd );
+    if (!successful)
+        return FALSE;
 
-        g_date_clear(&offset_date, 1);
-        g_date_set_julian(&offset_date, fspd->offset == 0 ? 7 : fspd->offset);
-        recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_DAY, &offset_date, WEEKEND_ADJ_NONE);
+    g_date_clear(&offset_date, 1);
+    g_date_set_julian(&offset_date, fspd->offset == 0 ? 7 : fspd->offset);
+    recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_DAY, &offset_date, WEEKEND_ADJ_NONE);
 
-        return TRUE;
+    return TRUE;
 }
 
 static
 gboolean
 fs_weekly_handler( xmlNodePtr node, gpointer data )
 {
-        fsParseData *fspd = data;
-        GDate offset_date;
-        gboolean        successful;
-        successful = dom_tree_generic_parse( node,
-                                             fs_union_dom_handlers,
-                                             fspd );
-        if ( !successful )
-                return FALSE;
+    fsParseData *fspd = data;
+    GDate offset_date;
+    gboolean        successful;
+    successful = dom_tree_generic_parse( node,
+                                         fs_union_dom_handlers,
+                                         fspd );
+    if ( !successful )
+        return FALSE;
 
-        g_date_clear(&offset_date, 1);
-        g_date_set_julian(&offset_date, fspd->offset == 0 ? 7 : fspd->offset);
-        recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_WEEK, &offset_date, WEEKEND_ADJ_NONE);
+    g_date_clear(&offset_date, 1);
+    g_date_set_julian(&offset_date, fspd->offset == 0 ? 7 : fspd->offset);
+    recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_WEEK, &offset_date, WEEKEND_ADJ_NONE);
 
-        return TRUE;
+    return TRUE;
 }
 
 static
 gboolean
 fs_monthly_handler( xmlNodePtr node, gpointer data)
 {
-        fsParseData *fspd = data;
-        GDate offset_date;
-        gboolean        successful;
-        successful = dom_tree_generic_parse( node,
-                                             fs_union_dom_handlers,
-                                             fspd );
-        if ( !successful )
-                return FALSE;
+    fsParseData *fspd = data;
+    GDate offset_date;
+    gboolean        successful;
+    successful = dom_tree_generic_parse( node,
+                                         fs_union_dom_handlers,
+                                         fspd );
+    if ( !successful )
+        return FALSE;
 
 
-        g_date_clear(&offset_date, 1);
-        g_date_set_julian(&offset_date, 1);
-        g_date_add_months(&offset_date, fspd->offset);
-        g_date_set_day(&offset_date, fspd->day);
-        if (fspd->uift == UIFREQ_ONCE)
-        {
-            // hack...
-            recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_ONCE, &offset_date, WEEKEND_ADJ_NONE);
-        }
-        else
-        {
-            recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_MONTH, &offset_date, fspd->weekend_adj);
-        }
-        
-        return successful;
+    g_date_clear(&offset_date, 1);
+    g_date_set_julian(&offset_date, 1);
+    g_date_add_months(&offset_date, fspd->offset);
+    g_date_set_day(&offset_date, fspd->day);
+    if (fspd->uift == UIFREQ_ONCE)
+    {
+        // hack...
+        recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_ONCE, &offset_date, WEEKEND_ADJ_NONE);
+    }
+    else
+    {
+        recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_MONTH, &offset_date, fspd->weekend_adj);
+    }
+
+    return successful;
 }
 
 static
 gboolean
 fs_month_relative_handler( xmlNodePtr node, gpointer data)
 {
-        g_critical("this was never supported, how is it in the datafile?");
-        return FALSE;
+    g_critical("this was never supported, how is it in the datafile?");
+    return FALSE;
 }
 
 static
 gboolean
 fs_guid_handler( xmlNodePtr node, gpointer data)
 {
-        fsParseData *fspd = data;
-        GUID        *guid;
-        guid = dom_tree_to_guid( node );
-        return TRUE;
+    fsParseData *fspd = data;
+    GUID        *guid;
+    guid = dom_tree_to_guid( node );
+    return TRUE;
 }
 
 static
 gboolean
 fs_composite_handler( xmlNodePtr node, gpointer data)
 {
-        fsParseData *fspd = data;
-        gboolean        successful;
-        successful = dom_tree_generic_parse( node,
-                                             fs_union_dom_handlers,
-                                             fspd );
-        return successful;
+    fsParseData *fspd = data;
+    gboolean        successful;
+    successful = dom_tree_generic_parse( node,
+                                         fs_union_dom_handlers,
+                                         fspd );
+    return successful;
 }
 
-static struct dom_tree_handler fs_dom_handlers[] = {
-        { "gnc:freqspec",      gnc_fs_handler,            0, 0 },
-        { "fs:ui_type",        fs_uift_handler,           1, 0 },
-        { "fs:id",             fs_guid_handler,           1, 0 },
-        { "fs:none",           fs_none_handler,           0, 0 },
-        { "fs:once",           fs_once_handler,           0, 0 },
-        { "fs:daily",          fs_daily_handler,          0, 0 },
-        { "fs:weekly",         fs_weekly_handler,         0, 0 },
-        { "fs:monthly",        fs_monthly_handler,        0, 0 },
-        { "fs:month_relative", fs_month_relative_handler, 0, 0 },
-        { "fs:composite",      fs_composite_handler,      0, 0 },
-        { NULL, NULL, 0, 0 }
+static struct dom_tree_handler fs_dom_handlers[] =
+{
+    { "gnc:freqspec",      gnc_fs_handler,            0, 0 },
+    { "fs:ui_type",        fs_uift_handler,           1, 0 },
+    { "fs:id",             fs_guid_handler,           1, 0 },
+    { "fs:none",           fs_none_handler,           0, 0 },
+    { "fs:once",           fs_once_handler,           0, 0 },
+    { "fs:daily",          fs_daily_handler,          0, 0 },
+    { "fs:weekly",         fs_weekly_handler,         0, 0 },
+    { "fs:monthly",        fs_monthly_handler,        0, 0 },
+    { "fs:month_relative", fs_month_relative_handler, 0, 0 },
+    { "fs:composite",      fs_composite_handler,      0, 0 },
+    { NULL, NULL, 0, 0 }
 };
 
 static
@@ -445,32 +454,33 @@
                          gpointer parent_data, gpointer global_data,
                          gpointer *result, const gchar *tag)
 {
-        fsParseData                fspd;
-        gboolean                successful = FALSE;
-        xmlNodePtr                tree = (xmlNodePtr)data_for_children;
-        sixtp_gdv2                *globaldata = (sixtp_gdv2*)global_data;
+    fsParseData                fspd;
+    gboolean                successful = FALSE;
+    xmlNodePtr                tree = (xmlNodePtr)data_for_children;
+    sixtp_gdv2                *globaldata = (sixtp_gdv2*)global_data;
 
-        fspd_init( &fspd );
-        fspd.book = globaldata->book;
+    fspd_init( &fspd );
+    fspd.book = globaldata->book;
 
-        /* this won't actually get invoked [FreqSpecs aren't top-level
-           elements]; see dom_tree_to_freqSpec(), below. */
-        if ( parent_data )
-                return TRUE;
+    /* this won't actually get invoked [FreqSpecs aren't top-level
+       elements]; see dom_tree_to_freqSpec(), below. */
+    if ( parent_data )
+        return TRUE;
 
-        if ( !tag )
-                return TRUE;
+    if ( !tag )
+        return TRUE;
 
-        g_return_val_if_fail( tree, FALSE );
+    g_return_val_if_fail( tree, FALSE );
 
-        successful = dom_tree_generic_parse( tree, fs_dom_handlers, &fspd );
-        if (!successful) {
-                xmlElemDump( stdout, NULL, tree );
-        }
+    successful = dom_tree_generic_parse( tree, fs_dom_handlers, &fspd );
+    if (!successful)
+    {
+        xmlElemDump( stdout, NULL, tree );
+    }
 
-        xmlFreeNode(tree);
+    xmlFreeNode(tree);
 
-        return successful;
+    return successful;
 }
 
 sixtp*

Modified: gnucash/trunk/src/backend/xml/gnc-lot-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-lot-xml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-lot-xml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -70,7 +70,7 @@
     if (kf)
     {
         xmlNodePtr kvpnode = kvp_frame_to_dom_tree(lot_slots_string, kf);
-        if(kvpnode)
+        if (kvpnode)
         {
             xmlAddChild(ret, kvpnode);
         }
@@ -84,8 +84,8 @@
 
 struct lot_pdata
 {
-  GNCLot  *lot;
-  QofBook *book;
+    GNCLot  *lot;
+    QofBook *book;
 };
 
 static gboolean
@@ -99,7 +99,7 @@
     gnc_lot_set_guid(pdata->lot, *guid);
 
     g_free(guid);
-    
+
     LEAVE("");
     return TRUE;
 }
@@ -112,7 +112,7 @@
 
     ENTER("(lot=%p)", pdata->lot);
     success = dom_tree_to_kvp_frame_given
-         (node, gnc_lot_get_slots (pdata->lot));
+              (node, gnc_lot_get_slots (pdata->lot));
 
     LEAVE("");
     g_return_val_if_fail(success, FALSE);
@@ -120,7 +120,8 @@
 }
 
 
-static struct dom_tree_handler lot_handlers_v2[] = {
+static struct dom_tree_handler lot_handlers_v2[] =
+{
     { lot_id_string, lot_id_handler, 1, 0 },
     { lot_slots_string, lot_slots_handler, 0, 0 },
     { NULL, 0, 0, 0 }
@@ -128,9 +129,9 @@
 
 static gboolean
 gnc_lot_end_handler(gpointer data_for_children,
-                        GSList* data_from_children, GSList* sibling_data,
-                        gpointer parent_data, gpointer global_data,
-                        gpointer *result, const gchar *tag)
+                    GSList* data_from_children, GSList* sibling_data,
+                    gpointer parent_data, gpointer global_data,
+                    gpointer *result, const gchar *tag)
 {
     int successful;
     GNCLot *lot;
@@ -140,14 +141,14 @@
 
     successful = TRUE;
 
-    if(parent_data)
+    if (parent_data)
     {
         return TRUE;
     }
 
     /* OK.  For some messed up reason this is getting called again with a
        NULL tag.  So we ignore those cases */
-    if(!tag)
+    if (!tag)
     {
         return TRUE;
     }
@@ -156,7 +157,7 @@
 
     lot = dom_tree_to_lot(tree, book);
     ENTER("(lot=%p)", lot);
-    if(lot != NULL)
+    if (lot != NULL)
     {
         gdata->cb(tag, gdata->parsedata, lot);
     }

Modified: gnucash/trunk/src/backend/xml/gnc-pricedb-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-pricedb-xml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-pricedb-xml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -80,51 +80,64 @@
   Returns a GNCPrice * in result.
 
   Right now, a price is legitimate even if all of it's fields are not
-  set.  We may need to change that later, but at the moment.  
+  set.  We may need to change that later, but at the moment.
 
 */
 
 static gboolean
 price_parse_xml_sub_node(GNCPrice *p, xmlNodePtr sub_node, QofBook *book)
 {
-  if(!p || !sub_node) return FALSE;
+    if (!p || !sub_node) return FALSE;
 
-  gnc_price_begin_edit (p);
-  if(safe_strcmp("price:id", (char*)sub_node->name) == 0) {
-    GUID *c = dom_tree_to_guid(sub_node);
-    if(!c) return FALSE; 
-    gnc_price_set_guid(p, c);
-    g_free(c);
-  } else if(safe_strcmp("price:commodity", (char*)sub_node->name) == 0) {
-    gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, book);
-    if(!c) return FALSE;
-    gnc_price_set_commodity(p, c);
-  } else if(safe_strcmp("price:currency", (char*)sub_node->name) == 0) {
-    gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, book);
-    if(!c) return FALSE;
-    gnc_price_set_currency(p, c);
-  } else if(safe_strcmp("price:time", (char*)sub_node->name) == 0) {
-    Timespec t = dom_tree_to_timespec(sub_node);
-    if (!dom_tree_valid_timespec(&t, sub_node->name)) return FALSE;
-    gnc_price_set_time(p, t);
-  } else if(safe_strcmp("price:source", (char*)sub_node->name) == 0) {
-    char *text = dom_tree_to_text(sub_node);
-    if(!text) return FALSE;
-    gnc_price_set_source(p, text);
-    g_free(text);
-  } else if(safe_strcmp("price:type", (char*)sub_node->name) == 0) {
-    char *text = dom_tree_to_text(sub_node);
-    if(!text) return FALSE;
-    gnc_price_set_typestr(p, text);
-    g_free(text);
-  } else if(safe_strcmp("price:value", (char*)sub_node->name) == 0) {
-    gnc_numeric *value = dom_tree_to_gnc_numeric(sub_node);
-    if(!value) return FALSE;
-    gnc_price_set_value(p, *value);
-    g_free(value);
-  }  
-  gnc_price_commit_edit (p);
-  return TRUE;
+    gnc_price_begin_edit (p);
+    if (safe_strcmp("price:id", (char*)sub_node->name) == 0)
+    {
+        GUID *c = dom_tree_to_guid(sub_node);
+        if (!c) return FALSE;
+        gnc_price_set_guid(p, c);
+        g_free(c);
+    }
+    else if (safe_strcmp("price:commodity", (char*)sub_node->name) == 0)
+    {
+        gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, book);
+        if (!c) return FALSE;
+        gnc_price_set_commodity(p, c);
+    }
+    else if (safe_strcmp("price:currency", (char*)sub_node->name) == 0)
+    {
+        gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, book);
+        if (!c) return FALSE;
+        gnc_price_set_currency(p, c);
+    }
+    else if (safe_strcmp("price:time", (char*)sub_node->name) == 0)
+    {
+        Timespec t = dom_tree_to_timespec(sub_node);
+        if (!dom_tree_valid_timespec(&t, sub_node->name)) return FALSE;
+        gnc_price_set_time(p, t);
+    }
+    else if (safe_strcmp("price:source", (char*)sub_node->name) == 0)
+    {
+        char *text = dom_tree_to_text(sub_node);
+        if (!text) return FALSE;
+        gnc_price_set_source(p, text);
+        g_free(text);
+    }
+    else if (safe_strcmp("price:type", (char*)sub_node->name) == 0)
+    {
+        char *text = dom_tree_to_text(sub_node);
+        if (!text) return FALSE;
+        gnc_price_set_typestr(p, text);
+        g_free(text);
+    }
+    else if (safe_strcmp("price:value", (char*)sub_node->name) == 0)
+    {
+        gnc_numeric *value = dom_tree_to_gnc_numeric(sub_node);
+        if (!value) return FALSE;
+        gnc_price_set_value(p, *value);
+        g_free(value);
+    }
+    gnc_price_commit_edit (p);
+    return TRUE;
 }
 
 static gboolean
@@ -136,80 +149,102 @@
                             gpointer *result,
                             const gchar *tag)
 {
-  gboolean ok = TRUE;
-  xmlNodePtr price_xml = (xmlNodePtr) data_for_children;
-  xmlNodePtr child;
-  GNCPrice *p = NULL;
-  gxpf_data *gdata = global_data;
-  QofBook *book = gdata->bookdata;
+    gboolean ok = TRUE;
+    xmlNodePtr price_xml = (xmlNodePtr) data_for_children;
+    xmlNodePtr child;
+    GNCPrice *p = NULL;
+    gxpf_data *gdata = global_data;
+    QofBook *book = gdata->bookdata;
 
-  /* we haven't been handed the *top* level node yet... */
-  if(parent_data) return TRUE;
+    /* we haven't been handed the *top* level node yet... */
+    if (parent_data) return TRUE;
 
-  *result = NULL;
+    *result = NULL;
 
-  if(!price_xml) return FALSE;
-  if(price_xml->next) { ok = FALSE; goto cleanup_and_exit; }
-  if(price_xml->prev) { ok = FALSE; goto cleanup_and_exit; }
-  if(!price_xml->xmlChildrenNode) { ok = FALSE; goto cleanup_and_exit; }
+    if (!price_xml) return FALSE;
+    if (price_xml->next)
+    {
+        ok = FALSE;
+        goto cleanup_and_exit;
+    }
+    if (price_xml->prev)
+    {
+        ok = FALSE;
+        goto cleanup_and_exit;
+    }
+    if (!price_xml->xmlChildrenNode)
+    {
+        ok = FALSE;
+        goto cleanup_and_exit;
+    }
 
-  p = gnc_price_create(book);
-  if(!p) { ok = FALSE; goto cleanup_and_exit; }
-  
-  for(child = price_xml->xmlChildrenNode; child; child = child->next) {
-    switch(child->type) {
-    case XML_COMMENT_NODE:
-    case XML_TEXT_NODE:
-      break;
-    case XML_ELEMENT_NODE:
-      if(!price_parse_xml_sub_node(p, child, book)) {
+    p = gnc_price_create(book);
+    if (!p)
+    {
         ok = FALSE;
         goto cleanup_and_exit;
-      }
-      break;
-    default:
-      PERR("Unknown node type (%d) while parsing gnc-price xml.", child->type);
-      child = NULL;
-      ok = FALSE;
-      goto cleanup_and_exit;
-      break;
     }
-  }
-  
- cleanup_and_exit:
-  if(ok) {
-    *result = p;
-  } else {
-    *result = NULL;
-    gnc_price_unref(p);
-  }
-  xmlFreeNode(price_xml);
-  return ok;
+
+    for (child = price_xml->xmlChildrenNode; child; child = child->next)
+    {
+        switch (child->type)
+        {
+        case XML_COMMENT_NODE:
+        case XML_TEXT_NODE:
+            break;
+        case XML_ELEMENT_NODE:
+            if (!price_parse_xml_sub_node(p, child, book))
+            {
+                ok = FALSE;
+                goto cleanup_and_exit;
+            }
+            break;
+        default:
+            PERR("Unknown node type (%d) while parsing gnc-price xml.", child->type);
+            child = NULL;
+            ok = FALSE;
+            goto cleanup_and_exit;
+            break;
+        }
+    }
+
+cleanup_and_exit:
+    if (ok)
+    {
+        *result = p;
+    }
+    else
+    {
+        *result = NULL;
+        gnc_price_unref(p);
+    }
+    xmlFreeNode(price_xml);
+    return ok;
 }
 
 static void
 cleanup_gnc_price(sixtp_child_result *result)
 {
-  if(result->data) gnc_price_unref((GNCPrice *) result->data);
+    if (result->data) gnc_price_unref((GNCPrice *) result->data);
 }
 
 static sixtp *
 gnc_price_parser_new (void)
 {
-  return sixtp_dom_parser_new(price_parse_xml_end_handler,
-                              cleanup_gnc_price,
-                              cleanup_gnc_price);
+    return sixtp_dom_parser_new(price_parse_xml_end_handler,
+                                cleanup_gnc_price,
+                                cleanup_gnc_price);
 }
 
 
 /****************************************************************************/
 /* <pricedb> (lineage <ledger-data>)
-   
+
    restores a pricedb.  We allocate the new db in the start block, the
    children add to it, and it gets returned in result.  Note that the
    cleanup handler will destroy the pricedb, so the parent needs to
    stop that if desired.
- 
+
    result: GNCPriceDB*
 
    start: create new GNCPriceDB*, and leave in *data_for_children.
@@ -227,13 +262,13 @@
                       const gchar *tag,
                       gchar **attrs)
 {
-  gxpf_data *gdata = global_data;
-  QofBook *book = gdata->bookdata;
-  GNCPriceDB *db = gnc_book_get_pricedb(book);
-  g_return_val_if_fail(db, FALSE);
-  gnc_pricedb_set_bulk_update(db, TRUE);
-  *result = db;
-  return(TRUE);
+    gxpf_data *gdata = global_data;
+    QofBook *book = gdata->bookdata;
+    GNCPriceDB *db = gnc_book_get_pricedb(book);
+    g_return_val_if_fail(db, FALSE);
+    gnc_pricedb_set_bulk_update(db, TRUE);
+    *result = db;
+    return(TRUE);
 }
 
 static gboolean
@@ -247,41 +282,42 @@
                             const gchar *child_tag,
                             sixtp_child_result *child_result)
 {
-  GNCPriceDB *db = (GNCPriceDB *) *result;
+    GNCPriceDB *db = (GNCPriceDB *) * result;
 
-  g_return_val_if_fail(db, FALSE);
+    g_return_val_if_fail(db, FALSE);
 
-  /* right now children have to produce results :> */
-  if(!child_result) return(FALSE);
-  if(child_result->type != SIXTP_CHILD_RESULT_NODE) return(FALSE);
+    /* right now children have to produce results :> */
+    if (!child_result) return(FALSE);
+    if (child_result->type != SIXTP_CHILD_RESULT_NODE) return(FALSE);
 
-  if(strcmp(child_result->tag, "price") == 0) 
-  {
-    GNCPrice *p = (GNCPrice *) child_result->data;
+    if (strcmp(child_result->tag, "price") == 0)
+    {
+        GNCPrice *p = (GNCPrice *) child_result->data;
 
-    g_return_val_if_fail(p, FALSE);
-    gnc_pricedb_add_price(db, p);
-    /* can't do this because the v1 parser doesn't use this data
-       structure as global data */
-    /* ((sixtp_gdv2*)global_data)->counter.prices_loaded++; */
-    return TRUE;
-  } 
-  else 
-  {
-    PERR ("unexpected tag %s\n", child_result->tag);
+        g_return_val_if_fail(p, FALSE);
+        gnc_pricedb_add_price(db, p);
+        /* can't do this because the v1 parser doesn't use this data
+           structure as global data */
+        /* ((sixtp_gdv2*)global_data)->counter.prices_loaded++; */
+        return TRUE;
+    }
+    else
+    {
+        PERR ("unexpected tag %s\n", child_result->tag);
+        return FALSE;
+    }
     return FALSE;
-  }
-  return FALSE;
 }
 
 static void
 pricedb_cleanup_result_handler(sixtp_child_result *result)
 {
-  if(result->data) {
-    GNCPriceDB *db = (GNCPriceDB *) result->data;
-    if(db) gnc_pricedb_destroy(db);
-    result->data = NULL;
-  }
+    if (result->data)
+    {
+        GNCPriceDB *db = (GNCPriceDB *) result->data;
+        if (db) gnc_pricedb_destroy(db);
+        result->data = NULL;
+    }
 }
 
 static gboolean
@@ -293,16 +329,16 @@
     GNCPriceDB *db = *result;
     gxpf_data *gdata = (gxpf_data*)global_data;
 
-    if(parent_data)
+    if (parent_data)
     {
         return TRUE;
     }
 
-    if(!tag)
+    if (!tag)
     {
         return TRUE;
     }
-    
+
     gdata->cb(tag, gdata->parsedata, db);
     *result = NULL;
 
@@ -312,33 +348,34 @@
 }
 
 static sixtp*
-gnc_pricedb_parser_new(void) 
+gnc_pricedb_parser_new(void)
 {
-  sixtp *top_level;
-  sixtp *price_parser;
+    sixtp *top_level;
+    sixtp *price_parser;
 
-  top_level = 
-    sixtp_set_any(sixtp_new(), TRUE,
-                  SIXTP_START_HANDLER_ID, pricedb_start_handler,
-                  SIXTP_AFTER_CHILD_HANDLER_ID, pricedb_after_child_handler,
-                  SIXTP_CHARACTERS_HANDLER_ID,
-                  allow_and_ignore_only_whitespace,
-                  SIXTP_RESULT_FAIL_ID, pricedb_cleanup_result_handler,
-                  SIXTP_CLEANUP_RESULT_ID, pricedb_cleanup_result_handler,
-                  SIXTP_NO_MORE_HANDLERS);
+    top_level =
+        sixtp_set_any(sixtp_new(), TRUE,
+                      SIXTP_START_HANDLER_ID, pricedb_start_handler,
+                      SIXTP_AFTER_CHILD_HANDLER_ID, pricedb_after_child_handler,
+                      SIXTP_CHARACTERS_HANDLER_ID,
+                      allow_and_ignore_only_whitespace,
+                      SIXTP_RESULT_FAIL_ID, pricedb_cleanup_result_handler,
+                      SIXTP_CLEANUP_RESULT_ID, pricedb_cleanup_result_handler,
+                      SIXTP_NO_MORE_HANDLERS);
 
-  if(!top_level) return NULL;
+    if (!top_level) return NULL;
 
-  price_parser = gnc_price_parser_new();
+    price_parser = gnc_price_parser_new();
 
-  if(!price_parser) {
-    sixtp_destroy(top_level);
-    return NULL;
-  }
+    if (!price_parser)
+    {
+        sixtp_destroy(top_level);
+        return NULL;
+    }
 
-  sixtp_add_sub_parser(top_level, "price", price_parser);
+    sixtp_add_sub_parser(top_level, "price", price_parser);
 
-  return top_level;
+    return top_level;
 }
 
 sixtp*
@@ -358,108 +395,114 @@
 static gboolean
 add_child_or_kill_parent(xmlNodePtr parent, xmlNodePtr child)
 {
-  if(!child) {
-    xmlFreeNode(parent);
-    return FALSE;
-  }
-  xmlAddChild(parent, child);
-  return TRUE;
+    if (!child)
+    {
+        xmlFreeNode(parent);
+        return FALSE;
+    }
+    xmlAddChild(parent, child);
+    return TRUE;
 }
 
 static xmlNodePtr
 gnc_price_to_dom_tree(const xmlChar *tag, GNCPrice *price)
-{  
-  xmlNodePtr price_xml;
-  const gchar *typestr, *sourcestr;
-  xmlNodePtr tmpnode;
-  gnc_commodity *commodity;
-  gnc_commodity *currency;
-  Timespec timesp;
-  gnc_numeric value;
+{
+    xmlNodePtr price_xml;
+    const gchar *typestr, *sourcestr;
+    xmlNodePtr tmpnode;
+    gnc_commodity *commodity;
+    gnc_commodity *currency;
+    Timespec timesp;
+    gnc_numeric value;
 
-  if (!(tag && price)) return NULL;
-  
-  price_xml = xmlNewNode(NULL, tag);
-  if(!price_xml) return NULL;
+    if (!(tag && price)) return NULL;
 
-  commodity = gnc_price_get_commodity(price);
-  currency = gnc_price_get_currency(price);
+    price_xml = xmlNewNode(NULL, tag);
+    if (!price_xml) return NULL;
 
-  if(!(commodity && currency)) return NULL;
+    commodity = gnc_price_get_commodity(price);
+    currency = gnc_price_get_currency(price);
 
-  tmpnode = guid_to_dom_tree("price:id", gnc_price_get_guid(price));
-  if(!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
+    if (!(commodity && currency)) return NULL;
 
-  tmpnode = commodity_ref_to_dom_tree("price:commodity", commodity);
-  if(!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
+    tmpnode = guid_to_dom_tree("price:id", gnc_price_get_guid(price));
+    if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
 
-  tmpnode = commodity_ref_to_dom_tree("price:currency", currency);
-  if(!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
+    tmpnode = commodity_ref_to_dom_tree("price:commodity", commodity);
+    if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
 
-  timesp = gnc_price_get_time(price);
-  tmpnode = timespec_to_dom_tree("price:time", &timesp);
-  if(!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
+    tmpnode = commodity_ref_to_dom_tree("price:currency", currency);
+    if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
 
-  sourcestr = gnc_price_get_source(price);
-  if(sourcestr && (strlen(sourcestr) != 0)) {
-    tmpnode = text_to_dom_tree("price:source", sourcestr);
-    if(!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
-  }
-    
-  typestr = gnc_price_get_typestr(price);
-  if(typestr && (strlen(typestr) != 0)) {
-    tmpnode = text_to_dom_tree("price:type", typestr);
-    if(!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
-  }
-    
-  value = gnc_price_get_value(price);
-  tmpnode = gnc_numeric_to_dom_tree("price:value", &value);
-  if(!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
-  
-  return price_xml;
+    timesp = gnc_price_get_time(price);
+    tmpnode = timespec_to_dom_tree("price:time", &timesp);
+    if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
+
+    sourcestr = gnc_price_get_source(price);
+    if (sourcestr && (strlen(sourcestr) != 0))
+    {
+        tmpnode = text_to_dom_tree("price:source", sourcestr);
+        if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
+    }
+
+    typestr = gnc_price_get_typestr(price);
+    if (typestr && (strlen(typestr) != 0))
+    {
+        tmpnode = text_to_dom_tree("price:type", typestr);
+        if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
+    }
+
+    value = gnc_price_get_value(price);
+    tmpnode = gnc_numeric_to_dom_tree("price:value", &value);
+    if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
+
+    return price_xml;
 }
 
 static gboolean
 xml_add_gnc_price_adapter(GNCPrice *p, gpointer data)
 {
-  xmlNodePtr xml_node = (xmlNodePtr) data;
-  
-  if(p) {
-    xmlNodePtr price_xml = gnc_price_to_dom_tree(BAD_CAST "price", p);
-    if(!price_xml) return FALSE;
-    xmlAddChild(xml_node, price_xml);
-    return TRUE;
-  } else {
-    return TRUE;
-  }
+    xmlNodePtr xml_node = (xmlNodePtr) data;
+
+    if (p)
+    {
+        xmlNodePtr price_xml = gnc_price_to_dom_tree(BAD_CAST "price", p);
+        if (!price_xml) return FALSE;
+        xmlAddChild(xml_node, price_xml);
+        return TRUE;
+    }
+    else
+    {
+        return TRUE;
+    }
 }
 
 static xmlNodePtr
 gnc_pricedb_to_dom_tree(const xmlChar *tag, GNCPriceDB *db)
 {
-  xmlNodePtr db_xml = NULL;
+    xmlNodePtr db_xml = NULL;
 
-  if(!tag) return NULL;
+    if (!tag) return NULL;
 
-  db_xml= xmlNewNode(NULL, tag);
-  if(!db_xml) return NULL;
+    db_xml = xmlNewNode(NULL, tag);
+    if (!db_xml) return NULL;
 
-  xmlSetProp(db_xml, BAD_CAST "version", BAD_CAST "1");
+    xmlSetProp(db_xml, BAD_CAST "version", BAD_CAST "1");
 
-  if(!gnc_pricedb_foreach_price(db, xml_add_gnc_price_adapter, db_xml, TRUE))
-  {
-    xmlFreeNode(db_xml);
-    return NULL;
-  }
+    if (!gnc_pricedb_foreach_price(db, xml_add_gnc_price_adapter, db_xml, TRUE))
+    {
+        xmlFreeNode(db_xml);
+        return NULL;
+    }
 
-  /* if no children have been added just return NULL */
-  if(!db_xml->xmlChildrenNode)
-  {
-      xmlFreeNode(db_xml);
-      return NULL;
-  }
-  
-  return db_xml;
+    /* if no children have been added just return NULL */
+    if (!db_xml->xmlChildrenNode)
+    {
+        xmlFreeNode(db_xml);
+        return NULL;
+    }
+
+    return db_xml;
 }
 
 xmlNodePtr

Modified: gnucash/trunk/src/backend/xml/gnc-recurrence-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-recurrence-xml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-recurrence-xml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -92,13 +92,14 @@
 
     nodeTxt = dom_tree_to_text(node);
     g_return_val_if_fail(nodeTxt, FALSE);
-    wadj= recurrenceWeekendAdjustFromString(nodeTxt);
+    wadj = recurrenceWeekendAdjustFromString(nodeTxt);
     ((Recurrence *) d)->wadj = wadj;
     g_free(nodeTxt);
     return (wadj != -1);
 }
 
-static struct dom_tree_handler recurrence_dom_handlers[] = {
+static struct dom_tree_handler recurrence_dom_handlers[] =
+{
     { recurrence_mult, recurrence_mult_handler, 1, 0 },
     { recurrence_period_type, recurrence_period_type_handler, 1, 0 },
     { recurrence_start, recurrence_start_date_handler, 1, 0 },
@@ -116,7 +117,8 @@
     /* In case the file doesn't have a weekend adjustment element */
     r->wadj = WEEKEND_ADJ_NONE;
     successful = dom_tree_generic_parse (node, recurrence_dom_handlers, r);
-    if (!successful) {
+    if (!successful)
+    {
         PERR ("failed to parse recurrence node");
         xmlElemDump(stdout, NULL, node);
         g_free(r);
@@ -145,14 +147,14 @@
     wadj = recurrenceGetWeekendAdjust(r);
     if (wadj != WEEKEND_ADJ_NONE)
     {
-      /* In r17725 and r17751, I introduced this extra XML child
-	 element, but this means a gnucash-2.2.x cannot read the SX
-	 recurrence of a >=2.3.x file anymore, which is bad. In order
-	 to improve this broken backward compatibility for most of the
-	 cases, we don't write out this XML element as long as it is
-	 only "none". */
-      xmlAddChild(n, text_to_dom_tree(recurrence_weekend_adj,
-				      recurrenceWeekendAdjustToString(wadj)));
+        /* In r17725 and r17751, I introduced this extra XML child
+        element, but this means a gnucash-2.2.x cannot read the SX
+        recurrence of a >=2.3.x file anymore, which is bad. In order
+        to improve this broken backward compatibility for most of the
+        cases, we don't write out this XML element as long as it is
+        only "none". */
+        xmlAddChild(n, text_to_dom_tree(recurrence_weekend_adj,
+                                        recurrenceWeekendAdjustToString(wadj)));
     }
     return n;
 }

Modified: gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -62,7 +62,7 @@
 #define SX_NUM_OCCUR            "sx:num-occur"
 #define SX_REM_OCCUR            "sx:rem-occur"
 #define SX_END                  "sx:end"
-#define SX_TEMPL_ACCT           "sx:templ-acct" 
+#define SX_TEMPL_ACCT           "sx:templ-acct"
 #define SX_FREQSPEC             "sx:freqspec"
 #define SX_SCHEDULE             "sx:schedule"
 #define SX_SLOTS                "sx:slots"
@@ -116,7 +116,7 @@
     xmlNewTextChild( ret, NULL, BAD_CAST SX_AUTOCREATE_NOTIFY,
                      BAD_CAST ( sx->autoCreateNotify ? "y" : "n" ) );
     xmlAddChild(ret, int_to_dom_tree(SX_ADVANCE_CREATE_DAYS,
-                                      sx->advanceCreateDays));
+                                     sx->advanceCreateDays));
     xmlAddChild(ret, int_to_dom_tree(SX_ADVANCE_REMIND_DAYS,
                                      sx->advanceRemindDays));
 
@@ -129,32 +129,36 @@
                                     xaccSchedXactionGetStartDate(sx) ) );
 
     date = xaccSchedXactionGetLastOccurDate(sx);
-    if ( g_date_valid( date ) ) {
-            xmlAddChild( ret, gdate_to_dom_tree( SX_LAST, date ) );
+    if ( g_date_valid( date ) )
+    {
+        xmlAddChild( ret, gdate_to_dom_tree( SX_LAST, date ) );
     }
 
-    if ( xaccSchedXactionHasOccurDef(sx) ) {
+    if ( xaccSchedXactionHasOccurDef(sx) )
+    {
 
         xmlAddChild(ret, int_to_dom_tree( SX_NUM_OCCUR,
                                           xaccSchedXactionGetNumOccur(sx)));
         xmlAddChild(ret, int_to_dom_tree( SX_REM_OCCUR,
                                           xaccSchedXactionGetRemOccur(sx)));
 
-    } else if ( xaccSchedXactionHasEndDate(sx) ) {
-            xmlAddChild( ret,
-                         gdate_to_dom_tree( SX_END,
-                                            xaccSchedXactionGetEndDate(sx) ) );
     }
+    else if ( xaccSchedXactionHasEndDate(sx) )
+    {
+        xmlAddChild( ret,
+                     gdate_to_dom_tree( SX_END,
+                                        xaccSchedXactionGetEndDate(sx) ) );
+    }
 
     /* output template account GUID */
-    xmlAddChild( ret, 
-		 guid_to_dom_tree(SX_TEMPL_ACCT,
-				  templ_acc_guid));
+    xmlAddChild( ret,
+                 guid_to_dom_tree(SX_TEMPL_ACCT,
+                                  templ_acc_guid));
 
     if (allow_2_2_incompat)
     {
         xmlNodePtr schedule_node = xmlNewNode(NULL,
-                                   BAD_CAST "sx:schedule");
+                                              BAD_CAST "sx:schedule");
         GList *schedule = gnc_sx_get_schedule(sx);
         for (; schedule != NULL; schedule = schedule->next)
         {
@@ -162,35 +166,36 @@
         }
         xmlAddChild(ret, schedule_node);
     }
-				  
+
     /* Output deferred-instance list. */
     {
-            xmlNodePtr instNode;
-            temporalStateData *tsd;
-            GList *l;
+        xmlNodePtr instNode;
+        temporalStateData *tsd;
+        GList *l;
 
-            for ( l = gnc_sx_get_defer_instances( sx ); l; l = l->next ) {
-                    tsd = (temporalStateData*)l->data;
+        for ( l = gnc_sx_get_defer_instances( sx ); l; l = l->next )
+        {
+            tsd = (temporalStateData*)l->data;
 
-                    instNode = xmlNewNode( NULL, BAD_CAST SX_DEFER_INSTANCE );
-                    if ( g_date_valid( &tsd->last_date ) )
-                    {
-                      xmlAddChild( instNode, gdate_to_dom_tree( SX_LAST,
-                                                                &tsd->last_date ) );
-                    }
-                    xmlAddChild( instNode, int_to_dom_tree( SX_REM_OCCUR,
-                                                            tsd->num_occur_rem ) );
-                    xmlAddChild( instNode, int_to_dom_tree( SX_INSTANCE_COUNT,
-                                                            tsd->num_inst ) );
-                    xmlAddChild( ret, instNode );
+            instNode = xmlNewNode( NULL, BAD_CAST SX_DEFER_INSTANCE );
+            if ( g_date_valid( &tsd->last_date ) )
+            {
+                xmlAddChild( instNode, gdate_to_dom_tree( SX_LAST,
+                             &tsd->last_date ) );
             }
+            xmlAddChild( instNode, int_to_dom_tree( SX_REM_OCCUR,
+                                                    tsd->num_occur_rem ) );
+            xmlAddChild( instNode, int_to_dom_tree( SX_INSTANCE_COUNT,
+                                                    tsd->num_inst ) );
+            xmlAddChild( ret, instNode );
+        }
     }
-    
+
     /* output kvp_frame */
     {
         xmlNodePtr kvpnode =
-                kvp_frame_to_dom_tree( SX_SLOTS,
-                                       xaccSchedXactionGetSlots(sx) );
+            kvp_frame_to_dom_tree( SX_SLOTS,
+                                   xaccSchedXactionGetSlots(sx) );
         if ( kvpnode )
         {
             xmlAddChild(ret, kvpnode);
@@ -202,10 +207,10 @@
 
 struct sx_pdata
 {
-  SchedXaction *sx;
-  QofBook *book;
-  gboolean saw_freqspec;
-  gboolean saw_recurrence;
+    SchedXaction *sx;
+    QofBook *book;
+    gboolean saw_freqspec;
+    gboolean saw_recurrence;
 };
 
 static
@@ -280,8 +285,9 @@
     SchedXaction *sx = pdata->sx;
     gint64 advCreate;
 
-    if ( ! dom_tree_to_integer( node, &advCreate ) ) {
-      return FALSE;
+    if ( ! dom_tree_to_integer( node, &advCreate ) )
+    {
+        return FALSE;
     }
 
     xaccSchedXactionSetAdvanceCreation( sx, advCreate );
@@ -295,8 +301,9 @@
     SchedXaction *sx = pdata->sx;
     gint64 advRemind;
 
-    if ( ! dom_tree_to_integer( node, &advRemind ) ) {
-      return FALSE;
+    if ( ! dom_tree_to_integer( node, &advRemind ) )
+    {
+        return FALSE;
     }
 
     xaccSchedXactionSetAdvanceReminder( sx, advRemind );
@@ -321,16 +328,17 @@
 gboolean
 sx_instcount_handler( xmlNodePtr node, gpointer sx_pdata )
 {
-  struct sx_pdata *pdata = sx_pdata;
-  SchedXaction *sx = pdata->sx;
-  gint64 instanceNum;
+    struct sx_pdata *pdata = sx_pdata;
+    SchedXaction *sx = pdata->sx;
+    gint64 instanceNum;
 
-  if ( ! dom_tree_to_integer( node, &instanceNum ) ) {
-    return FALSE;
-  }
+    if ( ! dom_tree_to_integer( node, &instanceNum ) )
+    {
+        return FALSE;
+    }
 
-  gnc_sx_set_instance_count( sx, instanceNum );
-  return TRUE;
+    gnc_sx_set_instance_count( sx, instanceNum );
+    return TRUE;
 }
 
 static
@@ -367,7 +375,8 @@
 _fixup_recurrence_start_dates(GDate *sx_start_date, GList *schedule)
 {
     GList *iter;
-    for (iter = schedule; iter != NULL; iter = iter->next) {
+    for (iter = schedule; iter != NULL; iter = iter->next)
+    {
         Recurrence *r;
         GDate start, next;
 
@@ -394,13 +403,13 @@
 
         recurrenceSet(r,
                       recurrenceGetMultiplier(r),
-                      recurrenceGetPeriodType(r), 
+                      recurrenceGetPeriodType(r),
                       &next,
                       recurrenceGetWeekendAdjust(r));
     }
 
     if (g_list_length(schedule) == 1
-        && recurrenceGetPeriodType((Recurrence*)g_list_nth_data(schedule, 0)) == PERIOD_ONCE)
+            && recurrenceGetPeriodType((Recurrence*)g_list_nth_data(schedule, 0)) == PERIOD_ONCE)
     {
         char date_buf[128];
         Recurrence *fixup = (Recurrence*)g_list_nth_data(schedule, 0);
@@ -416,7 +425,7 @@
     struct sx_pdata *pdata = sx_pdata;
     SchedXaction *sx = pdata->sx;
     GList *schedule;
-	gchar* debug_str;
+    gchar* debug_str;
 
     g_return_val_if_fail( node, FALSE );
 
@@ -424,7 +433,7 @@
     gnc_sx_set_schedule(sx, schedule);
     debug_str = recurrenceListToString(schedule);
     g_debug("parsed from freqspec [%s]", debug_str);
-	g_free(debug_str);
+    g_free(debug_str);
 
     _fixup_recurrence_start_dates(xaccSchedXactionGetStartDate(sx), schedule);
     pdata->saw_freqspec = TRUE;
@@ -436,17 +445,18 @@
 sx_schedule_recurrence_handler(xmlNodePtr node, gpointer parsing_data)
 {
     GList **schedule = (GList**)parsing_data;
-	gchar* sched_str;
+    gchar* sched_str;
     Recurrence *r = dom_tree_to_recurrence(node);
     g_return_val_if_fail(r, FALSE);
     sched_str = recurrenceToString(r);
     g_debug("parsed recurrence [%s]", sched_str);
-	g_free(sched_str);
+    g_free(sched_str);
     *schedule = g_list_append(*schedule, r);
     return TRUE;
 }
 
-struct dom_tree_handler sx_recurrence_list_handlers[] = {
+struct dom_tree_handler sx_recurrence_list_handlers[] =
+{
     { "gnc:recurrence", sx_schedule_recurrence_handler, 0, 0 },
     { NULL, NULL, 0, 0 }
 };
@@ -456,8 +466,8 @@
 {
     struct sx_pdata *parsing_data = _pdata;
     GList *schedule = NULL;
-	gchar* debug_str;
-     
+    gchar* debug_str;
+
     g_return_val_if_fail(node, FALSE);
 
     if (!dom_tree_generic_parse(node, sx_recurrence_list_handlers, &schedule))
@@ -465,7 +475,7 @@
     // g_return_val_if_fail(schedule, FALSE);
     debug_str = recurrenceListToString(schedule);
     g_debug("setting freshly-parsed schedule: [%s]", debug_str);
-	g_free(debug_str);
+    g_free(debug_str);
     gnc_sx_set_schedule(parsing_data->sx, schedule);
     parsing_data->saw_recurrence = TRUE;
     return TRUE;
@@ -475,79 +485,83 @@
 gboolean
 sx_defer_last_handler( xmlNodePtr node, gpointer gpTSD )
 {
-        GDate *gd;
-        temporalStateData *tsd = (temporalStateData*)gpTSD;
+    GDate *gd;
+    temporalStateData *tsd = (temporalStateData*)gpTSD;
 
-        g_return_val_if_fail( node, FALSE );
-        gd = dom_tree_to_gdate( node );
-        g_return_val_if_fail( gd, FALSE );
-        tsd->last_date = *gd;
-        g_date_free( gd );
-        return TRUE;
+    g_return_val_if_fail( node, FALSE );
+    gd = dom_tree_to_gdate( node );
+    g_return_val_if_fail( gd, FALSE );
+    tsd->last_date = *gd;
+    g_date_free( gd );
+    return TRUE;
 }
 
 static
 gboolean
 sx_defer_rem_occur_handler( xmlNodePtr node, gpointer gpTSD )
 {
-        gint64 remOccur;
-        temporalStateData *tsd = (temporalStateData*)gpTSD;
-        g_return_val_if_fail( node, FALSE );
+    gint64 remOccur;
+    temporalStateData *tsd = (temporalStateData*)gpTSD;
+    g_return_val_if_fail( node, FALSE );
 
-        if ( ! dom_tree_to_integer( node, &remOccur ) ) {
-                return FALSE;
-        }
-        tsd->num_occur_rem = remOccur;
-        return TRUE;
+    if ( ! dom_tree_to_integer( node, &remOccur ) )
+    {
+        return FALSE;
+    }
+    tsd->num_occur_rem = remOccur;
+    return TRUE;
 }
 
 static
 gboolean
 sx_defer_inst_count_handler( xmlNodePtr node, gpointer gpTSD )
 {
-        gint64 instCount;
-        temporalStateData *tsd = (temporalStateData*)gpTSD;
-        g_return_val_if_fail( node, FALSE );
+    gint64 instCount;
+    temporalStateData *tsd = (temporalStateData*)gpTSD;
+    g_return_val_if_fail( node, FALSE );
 
-        if ( ! dom_tree_to_integer( node, &instCount ) ) {
-                return FALSE;
-        }
-        tsd->num_inst = instCount;
-        return TRUE;
+    if ( ! dom_tree_to_integer( node, &instCount ) )
+    {
+        return FALSE;
+    }
+    tsd->num_inst = instCount;
+    return TRUE;
 }
 
-struct dom_tree_handler sx_defer_dom_handlers[] = {
-       /* tag name, handler, opt, ? */
-        { SX_LAST,           sx_defer_last_handler,       1, 0 },
-        { SX_REM_OCCUR,      sx_defer_rem_occur_handler,  1, 0 },
-        { SX_INSTANCE_COUNT, sx_defer_inst_count_handler, 1, 0 },
-        { NULL, NULL, 0, 0 }
+struct dom_tree_handler sx_defer_dom_handlers[] =
+{
+    /* tag name, handler, opt, ? */
+    { SX_LAST,           sx_defer_last_handler,       1, 0 },
+    { SX_REM_OCCUR,      sx_defer_rem_occur_handler,  1, 0 },
+    { SX_INSTANCE_COUNT, sx_defer_inst_count_handler, 1, 0 },
+    { NULL, NULL, 0, 0 }
 };
 
 static
 gboolean
 sx_defer_inst_handler( xmlNodePtr node, gpointer sx_pdata )
 {
-        struct sx_pdata *pdata = sx_pdata;
-        SchedXaction *sx = pdata->sx;
-        temporalStateData *tsd;
+    struct sx_pdata *pdata = sx_pdata;
+    SchedXaction *sx = pdata->sx;
+    temporalStateData *tsd;
 
-        g_return_val_if_fail( node, FALSE );
+    g_return_val_if_fail( node, FALSE );
 
-        tsd = g_new0( temporalStateData, 1 );
-        g_assert( sx_defer_dom_handlers != NULL );
-        if ( !dom_tree_generic_parse( node,
-                                      sx_defer_dom_handlers,
-                                      tsd ) ) {
-                xmlElemDump(stdout, NULL, node);
-                g_free( tsd );
-                tsd = NULL;
-                return FALSE;
-        }
+    tsd = g_new0( temporalStateData, 1 );
+    g_assert( sx_defer_dom_handlers != NULL );
+    if ( !dom_tree_generic_parse( node,
+                                  sx_defer_dom_handlers,
+                                  tsd ) )
+    {
+        xmlElemDump(stdout, NULL, node);
+        g_free( tsd );
+        tsd = NULL;
+        return FALSE;
+    }
 
-        /* We assume they were serialized in sorted order, here. */
-        sx->deferredList = g_list_append( sx->deferredList, tsd );
-        return TRUE;
+    /* We assume they were serialized in sorted order, here. */
+    sx->deferredList = g_list_append( sx->deferredList, tsd );
+    return TRUE;
 }
 
 static
@@ -558,7 +572,8 @@
     SchedXaction *sx = pdata->sx;
     gint64 numOccur;
 
-    if ( ! dom_tree_to_integer( node, &numOccur ) ) {
+    if ( ! dom_tree_to_integer( node, &numOccur ) )
+    {
         return FALSE;
     }
 
@@ -568,59 +583,61 @@
 }
 
 
-static 
+static
 gboolean
 sx_templ_acct_handler( xmlNodePtr node, gpointer sx_pdata)
 {
-  struct sx_pdata *pdata = sx_pdata;
-  SchedXaction *sx = pdata->sx;
-  GUID *templ_acct_guid = dom_tree_to_guid(node);
-  Account *account;
+    struct sx_pdata *pdata = sx_pdata;
+    SchedXaction *sx = pdata->sx;
+    GUID *templ_acct_guid = dom_tree_to_guid(node);
+    Account *account;
 
-  if (!templ_acct_guid)
-  {
-    return FALSE;
-  }
+    if (!templ_acct_guid)
+    {
+        return FALSE;
+    }
 
-  account = xaccAccountLookup(templ_acct_guid, pdata->book);
-  sx_set_template_account(sx, account);
-  g_free(templ_acct_guid);
+    account = xaccAccountLookup(templ_acct_guid, pdata->book);
+    sx_set_template_account(sx, account);
+    g_free(templ_acct_guid);
 
-  return TRUE;
+    return TRUE;
 }
 
-			
+
 static
 gboolean
 sx_remOccur_handler( xmlNodePtr node, gpointer sx_pdata )
 {
-  struct sx_pdata *pdata = sx_pdata;
-  SchedXaction *sx = pdata->sx;
-  gint64        remOccur;
+    struct sx_pdata *pdata = sx_pdata;
+    SchedXaction *sx = pdata->sx;
+    gint64        remOccur;
 
-  if ( ! dom_tree_to_integer( node, &remOccur ) ) {
-    return FALSE;
-  }
+    if ( ! dom_tree_to_integer( node, &remOccur ) )
+    {
+        return FALSE;
+    }
 
-  xaccSchedXactionSetRemOccur( sx, remOccur );
+    xaccSchedXactionSetRemOccur( sx, remOccur );
 
-  return TRUE;
+    return TRUE;
 }
 
 static
 gboolean
 sx_slots_handler( xmlNodePtr node, gpointer sx_pdata )
 {
-  struct sx_pdata *pdata = sx_pdata;
-  SchedXaction *sx = pdata->sx;
+    struct sx_pdata *pdata = sx_pdata;
+    SchedXaction *sx = pdata->sx;
 
-  return dom_tree_to_kvp_frame_given( node, xaccSchedXactionGetSlots (sx) );
+    return dom_tree_to_kvp_frame_given( node, xaccSchedXactionGetSlots (sx) );
 }
 
-struct dom_tree_handler sx_dom_handlers[] = {
+struct dom_tree_handler sx_dom_handlers[] =
+{
     { SX_ID,                  sx_id_handler,         1, 0 },
     { SX_NAME,                sx_name_handler,       1, 0 },
-    { SX_ENABLED,             sx_enabled_handler,    0, 0 }, 
+    { SX_ENABLED,             sx_enabled_handler,    0, 0 },
     { SX_AUTOCREATE,          sx_autoCreate_handler, 1, 0 },
     { SX_AUTOCREATE_NOTIFY,   sx_notify_handler,     1, 0 },
     { SX_ADVANCE_CREATE_DAYS, sx_advCreate_handler,  1, 0 },
@@ -651,11 +668,13 @@
     gxpf_data    *gdata = (gxpf_data*)global_data;
     struct sx_pdata sx_pdata;
 
-    if ( parent_data ) {
+    if ( parent_data )
+    {
         return TRUE;
     }
 
-    if ( !tag ) {
+    if ( !tag )
+    {
         return TRUE;
     }
 
@@ -670,49 +689,49 @@
     g_assert( sx_dom_handlers != NULL );
 
     successful = dom_tree_generic_parse( tree, sx_dom_handlers, &sx_pdata );
-    if (!successful) 
+    if (!successful)
     {
-            g_critical("failed to parse scheduled xaction");
-            xmlElemDump( stdout, NULL, tree );
-			gnc_sx_begin_edit( sx );
-            xaccSchedXactionDestroy( sx );
-            goto done;
+        g_critical("failed to parse scheduled xaction");
+        xmlElemDump( stdout, NULL, tree );
+        gnc_sx_begin_edit( sx );
+        xaccSchedXactionDestroy( sx );
+        goto done;
     }
 
     if (tree->properties)
     {
-         gchar *sx_name = xaccSchedXactionGetName(sx);
-         xmlAttr *attr;
-         for (attr = tree->properties; attr != NULL; attr = attr->next)
-         {
-              xmlChar *attr_value = attr->children->content;
-              g_debug("sx attribute name[%s] value[%s]", attr->name, attr_value);
-              if (strcmp((const char *)attr->name, "version") != 0)
-              {
-                   g_warning("unknown sx attribute [%s]", attr->name);
-                   continue;
-              }
+        gchar *sx_name = xaccSchedXactionGetName(sx);
+        xmlAttr *attr;
+        for (attr = tree->properties; attr != NULL; attr = attr->next)
+        {
+            xmlChar *attr_value = attr->children->content;
+            g_debug("sx attribute name[%s] value[%s]", attr->name, attr_value);
+            if (strcmp((const char *)attr->name, "version") != 0)
+            {
+                g_warning("unknown sx attribute [%s]", attr->name);
+                continue;
+            }
 
-              // if version == 1.0.0: ensure freqspec, no recurrence
-              // if version == 2.0.0: ensure recurrence, no freqspec.
-              if (strcmp((const char *)attr_value,
-                               schedxaction_version_string) == 0)
-              {
-                   if (!sx_pdata.saw_freqspec)
-                        g_critical("did not see freqspec in version 1 sx [%s]", sx_name);
-                   if (sx_pdata.saw_recurrence)
-                        g_warning("saw recurrence in supposedly version 1 sx [%s]", sx_name);
-              }
+            // if version == 1.0.0: ensure freqspec, no recurrence
+            // if version == 2.0.0: ensure recurrence, no freqspec.
+            if (strcmp((const char *)attr_value,
+                       schedxaction_version_string) == 0)
+            {
+                if (!sx_pdata.saw_freqspec)
+                    g_critical("did not see freqspec in version 1 sx [%s]", sx_name);
+                if (sx_pdata.saw_recurrence)
+                    g_warning("saw recurrence in supposedly version 1 sx [%s]", sx_name);
+            }
 
-              if (strcmp((const char *)attr_value,
-                             schedxaction_version2_string) == 0)
-              {
-                   if (sx_pdata.saw_freqspec)
-                        g_warning("saw freqspec in version 2 sx [%s]", sx_name);
-                   if (!sx_pdata.saw_recurrence)
-                        g_critical("did not find recurrence in version 2 sx [%s]", sx_name);
-              }
-         }
+            if (strcmp((const char *)attr_value,
+                       schedxaction_version2_string) == 0)
+            {
+                if (sx_pdata.saw_freqspec)
+                    g_warning("saw freqspec in version 2 sx [%s]", sx_name);
+                if (!sx_pdata.saw_recurrence)
+                    g_critical("did not find recurrence in version 2 sx [%s]", sx_name);
+            }
+        }
     }
 
     // generic_callback -> book_callback: insert the SX in the book
@@ -721,47 +740,47 @@
     /* FIXME: this should be removed somewhere near 1.8 release time. */
     if ( sx->template_acct == NULL )
     {
-            Account *ra = NULL;
-            const char *id = NULL;
-            Account *acct = NULL;
-            sixtp_gdv2 *sixdata = gdata->parsedata;
-            QofBook *book;
+        Account *ra = NULL;
+        const char *id = NULL;
+        Account *acct = NULL;
+        sixtp_gdv2 *sixdata = gdata->parsedata;
+        QofBook *book;
 
-            book = sixdata->book;
+        book = sixdata->book;
 
-            /* We're dealing with a pre-200107<near-end-of-month> rgmerk
-               change re: storing template accounts. */
-            /* Fix: get account with name of our GUID from the template
-               accounts.  Make that our template_acct pointer. */
-            /* THREAD-UNSAFE */
-            id = guid_to_string( xaccSchedXactionGetGUID( sx ) );
-            ra = gnc_book_get_template_root(book);
-            if ( ra == NULL )
-            {
-                    g_warning( "Error getting template root account from being-parsed Book." );
-                    xmlFreeNode( tree );
-                    return FALSE;
-            }
-            acct = gnc_account_lookup_by_name( ra, id );
-            if ( acct == NULL )
-            {
-                    g_warning("no template account with name [%s]", id);
-                    xmlFreeNode( tree );
-                    return FALSE;
-            }
-            g_debug("template account name [%s] for SX with GUID [%s]",
-                   xaccAccountGetName( acct ), id );
+        /* We're dealing with a pre-200107<near-end-of-month> rgmerk
+           change re: storing template accounts. */
+        /* Fix: get account with name of our GUID from the template
+           accounts.  Make that our template_acct pointer. */
+        /* THREAD-UNSAFE */
+        id = guid_to_string( xaccSchedXactionGetGUID( sx ) );
+        ra = gnc_book_get_template_root(book);
+        if ( ra == NULL )
+        {
+            g_warning( "Error getting template root account from being-parsed Book." );
+            xmlFreeNode( tree );
+            return FALSE;
+        }
+        acct = gnc_account_lookup_by_name( ra, id );
+        if ( acct == NULL )
+        {
+            g_warning("no template account with name [%s]", id);
+            xmlFreeNode( tree );
+            return FALSE;
+        }
+        g_debug("template account name [%s] for SX with GUID [%s]",
+                xaccAccountGetName( acct ), id );
 
-            /* FIXME: free existing template account. 
-             *  HUH????? We only execute this if there isn't
-             * currently an existing template account, don't we?
-             * <rgmerk>
-             */
+        /* FIXME: free existing template account.
+         *  HUH????? We only execute this if there isn't
+         * currently an existing template account, don't we?
+         * <rgmerk>
+         */
 
-            sx->template_acct = acct;
+        sx->template_acct = acct;
     }
 
- done:
+done:
     xmlFreeNode( tree );
 
     return successful;
@@ -777,71 +796,79 @@
 gboolean
 tt_act_handler( xmlNodePtr node, gpointer data )
 {
-        gnc_template_xaction_data *txd = data;
-        Account *acc;
-        gnc_commodity *com;
+    gnc_template_xaction_data *txd = data;
+    Account *acc;
+    gnc_commodity *com;
 
-        acc = dom_tree_to_account(node, txd->book);
+    acc = dom_tree_to_account(node, txd->book);
 
-        if ( acc == NULL ) {
-                return FALSE;
-        } else {
-                xaccAccountBeginEdit (acc);
+    if ( acc == NULL )
+    {
+        return FALSE;
+    }
+    else
+    {
+        xaccAccountBeginEdit (acc);
 
-                /* Check for the lack of a commodity [signifying that the
-                   pre-7/11/2001-CIT-change SX template Account was parsed [but
-                   incorrectly]. */
-                if ( xaccAccountGetCommodity( acc ) == NULL ) {
+        /* Check for the lack of a commodity [signifying that the
+           pre-7/11/2001-CIT-change SX template Account was parsed [but
+           incorrectly]. */
+        if ( xaccAccountGetCommodity( acc ) == NULL )
+        {
 #if 1
-						gnc_commodity_table* table;
+            gnc_commodity_table* table;
 
-						table = gnc_commodity_table_get_table( txd->book );
-						com = gnc_commodity_table_lookup( table,
-												"template", "template" );
+            table = gnc_commodity_table_get_table( txd->book );
+            com = gnc_commodity_table_lookup( table,
+                                              "template", "template" );
 #else
-                        /* FIXME: This should first look in the table of the
-                           book, maybe? The right thing happens [WRT file
-                           load/save] if we just _new all the time, but it
-                           doesn't seem right. This whole block should go
-                           away at some point, but the same concern still
-                           applies for
-                           SchedXaction.c:xaccSchedXactionInit... */
-                        com = gnc_commodity_new( txd->book,
-                                                 "template", "template",
-                                                 "template", "template",
-                                                 1 );
+            /* FIXME: This should first look in the table of the
+               book, maybe? The right thing happens [WRT file
+               load/save] if we just _new all the time, but it
+               doesn't seem right. This whole block should go
+               away at some point, but the same concern still
+               applies for
+               SchedXaction.c:xaccSchedXactionInit... */
+            com = gnc_commodity_new( txd->book,
+                                     "template", "template",
+                                     "template", "template",
+                                     1 );
 #endif
-                        xaccAccountSetCommodity( acc, com );
-                }
-
-                txd->accts = g_list_append( txd->accts, acc );
+            xaccAccountSetCommodity( acc, com );
         }
 
-        return TRUE;
+        txd->accts = g_list_append( txd->accts, acc );
+    }
+
+    return TRUE;
 }
 
 static
 gboolean
 tt_trn_handler( xmlNodePtr node, gpointer data )
 {
-        gnc_template_xaction_data *txd = data;
-        Transaction        *trn;
+    gnc_template_xaction_data *txd = data;
+    Transaction        *trn;
 
-        trn = dom_tree_to_transaction( node, txd->book );
+    trn = dom_tree_to_transaction( node, txd->book );
 
-        if ( trn == NULL ) {
-                return FALSE;
-        } else {
-                txd->transactions = g_list_append( txd->transactions, trn );
-        }
+    if ( trn == NULL )
+    {
+        return FALSE;
+    }
+    else
+    {
+        txd->transactions = g_list_append( txd->transactions, trn );
+    }
 
-        return TRUE;
+    return TRUE;
 }
 
-struct dom_tree_handler tt_dom_handlers[] = {
-        { GNC_ACCOUNT_TAG,     tt_act_handler, 0, 0 },
-        { GNC_TRANSACTION_TAG, tt_trn_handler, 0, 0 },
-        { NULL, NULL, 0, 0 },
+struct dom_tree_handler tt_dom_handlers[] =
+{
+    { GNC_ACCOUNT_TAG,     tt_act_handler, 0, 0 },
+    { GNC_TRANSACTION_TAG, tt_trn_handler, 0, 0 },
+    { NULL, NULL, 0, 0 },
 };
 
 static gboolean
@@ -853,65 +880,69 @@
                                      gpointer *result,
                                      const gchar *tag)
 {
-        gboolean   successful = FALSE;
-        xmlNodePtr tree = data_for_children;
-        gxpf_data  *gdata = global_data;
-        QofBook    *book = gdata->bookdata;
-        GList      *n;
-        gnc_template_xaction_data txd;
+    gboolean   successful = FALSE;
+    xmlNodePtr tree = data_for_children;
+    gxpf_data  *gdata = global_data;
+    QofBook    *book = gdata->bookdata;
+    GList      *n;
+    gnc_template_xaction_data txd;
 
-        txd.book = book;
-        txd.accts = NULL;
-        txd.transactions = NULL;
+    txd.book = book;
+    txd.accts = NULL;
+    txd.transactions = NULL;
 
-        /* the DOM tree will have an account tree [the template
-           accounts] and a list of transactions [which will be members
-           of the template account].
+    /* the DOM tree will have an account tree [the template
+       accounts] and a list of transactions [which will be members
+       of the template account].
 
-           we want to parse through the dom trees for each, placing
-           the null-parent account in the book's template-group slot,
-           the others under it, and the transactions as normal. */
+       we want to parse through the dom trees for each, placing
+       the null-parent account in the book's template-group slot,
+       the others under it, and the transactions as normal. */
 
-        if ( parent_data ) {
-                return TRUE;
-        }
+    if ( parent_data )
+    {
+        return TRUE;
+    }
 
-        if ( !tag ) {
-                return TRUE;
-        }
+    if ( !tag )
+    {
+        return TRUE;
+    }
 
-        g_return_val_if_fail( tree, FALSE );
-        
-        successful = dom_tree_generic_parse( tree, tt_dom_handlers, &txd );
+    g_return_val_if_fail( tree, FALSE );
 
-        if ( successful ) 
-        {
-                gdata->cb( tag, gdata->parsedata, &txd );
-        } 
-        else 
-        {
-                g_warning("failed to parse template transaction");
-                xmlElemDump( stdout, NULL, tree );
-        }
+    successful = dom_tree_generic_parse( tree, tt_dom_handlers, &txd );
 
-        /* cleanup */
-        for ( n = txd.accts; n; n = n->next ) {
-                n->data = NULL;
-        }
-        for ( n = txd.transactions; n; n = n->next ) {
-                n->data = NULL;
-        }
-        g_list_free( txd.accts );
-        g_list_free( txd.transactions );
+    if ( successful )
+    {
+        gdata->cb( tag, gdata->parsedata, &txd );
+    }
+    else
+    {
+        g_warning("failed to parse template transaction");
+        xmlElemDump( stdout, NULL, tree );
+    }
 
-        xmlFreeNode( tree );
+    /* cleanup */
+    for ( n = txd.accts; n; n = n->next )
+    {
+        n->data = NULL;
+    }
+    for ( n = txd.transactions; n; n = n->next )
+    {
+        n->data = NULL;
+    }
+    g_list_free( txd.accts );
+    g_list_free( txd.transactions );
 
-        return successful;
+    xmlFreeNode( tree );
+
+    return successful;
 }
 
 sixtp*
 gnc_template_transaction_sixtp_parser_create( void )
 {
-        return sixtp_dom_parser_new( gnc_template_transaction_end_handler,
-                                     NULL, NULL );
+    return sixtp_dom_parser_new( gnc_template_transaction_end_handler,
+                                 NULL, NULL );
 }

Modified: gnucash/trunk/src/backend/xml/gnc-transaction-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-transaction-xml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-transaction-xml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -58,7 +58,7 @@
 static void
 add_timespec(xmlNodePtr node, const gchar *tag, Timespec tms, gboolean always)
 {
-    if(always || !((tms.tv_sec == 0) && (tms.tv_nsec == 0)))
+    if (always || !((tms.tv_sec == 0) && (tms.tv_nsec == 0)))
     {
         xmlAddChild(node, timespec_to_dom_tree(tag, &tms));
     }
@@ -72,11 +72,11 @@
     ret = xmlNewNode(NULL, BAD_CAST tag);
 
     xmlAddChild(ret, guid_to_dom_tree("split:id", xaccSplitGetGUID(spl)));
-    
+
     {
         const char *memo = xaccSplitGetMemo(spl);
 
-        if(memo && safe_strcmp(memo, "") != 0)
+        if (memo && safe_strcmp(memo, "") != 0)
         {
             xmlNewTextChild(ret, NULL, BAD_CAST "split:memo", (xmlChar*)memo);
         }
@@ -85,7 +85,7 @@
     {
         const char *action = xaccSplitGetAction(spl);
 
-        if(action && safe_strcmp(action, "") != 0)
+        if (action && safe_strcmp(action, "") != 0)
         {
             xmlNewTextChild(ret, NULL, BAD_CAST "split:action", (xmlChar*)action);
         }
@@ -108,29 +108,29 @@
     add_gnc_num(ret, "split:quantity", xaccSplitGetAmount(spl));
 
     {
-       Account * account = xaccSplitGetAccount (spl);
+        Account * account = xaccSplitGetAccount (spl);
 
-       xmlAddChild (ret, guid_to_dom_tree("split:account",
-                                         xaccAccountGetGUID (account)));
+        xmlAddChild (ret, guid_to_dom_tree("split:account",
+                                           xaccAccountGetGUID (account)));
     }
     {
-       GNCLot * lot = xaccSplitGetLot (spl);
+        GNCLot * lot = xaccSplitGetLot (spl);
 
-       if (lot)
-       {
-          xmlAddChild (ret, guid_to_dom_tree("split:lot",
-                                         gnc_lot_get_guid(lot)));
-       }
+        if (lot)
+        {
+            xmlAddChild (ret, guid_to_dom_tree("split:lot",
+                                               gnc_lot_get_guid(lot)));
+        }
     }
     {
-       xmlNodePtr kvpnode = kvp_frame_to_dom_tree("split:slots",
-                                                  xaccSplitGetSlots(spl));
-       if(kvpnode)
-       {
-           xmlAddChild(ret, kvpnode);
-       }
+        xmlNodePtr kvpnode = kvp_frame_to_dom_tree("split:slots",
+                             xaccSplitGetSlots(spl));
+        if (kvpnode)
+        {
+            xmlAddChild(ret, kvpnode);
+        }
     }
-    
+
     return ret;
 }
 
@@ -141,8 +141,8 @@
     xmlNodePtr toaddto;
 
     toaddto = xmlNewChild(node, NULL, BAD_CAST "trn:splits", NULL);
-    
-    for (n=xaccTransGetSplitList(trn); n; n=n->next)
+
+    for (n = xaccTransGetSplitList(trn); n; n = n->next)
     {
         Split *s = n->data;
         xmlAddChild(toaddto, split_to_dom_tree("trn:split", s));
@@ -161,9 +161,9 @@
     xmlAddChild(ret, guid_to_dom_tree("trn:id", xaccTransGetGUID(trn)));
 
     xmlAddChild(ret, commodity_ref_to_dom_tree("trn:currency",
-                                               xaccTransGetCurrency(trn)));
+                xaccTransGetCurrency(trn)));
 
-    if(xaccTransGetNum(trn) && (safe_strcmp(xaccTransGetNum(trn), "") != 0))
+    if (xaccTransGetNum(trn) && (safe_strcmp(xaccTransGetNum(trn), "") != 0))
     {
         xmlNewTextChild(ret, NULL, BAD_CAST "trn:num", (xmlChar*)xaccTransGetNum(trn));
     }
@@ -173,23 +173,23 @@
     add_timespec(ret, "trn:date-entered",
                  xaccTransRetDateEnteredTS(trn), TRUE);
 
-    if(xaccTransGetDescription(trn))
+    if (xaccTransGetDescription(trn))
     {
         xmlNewTextChild(ret, NULL, BAD_CAST "trn:description",
                         (xmlChar*)xaccTransGetDescription(trn));
     }
-    
+
     {
         xmlNodePtr kvpnode = kvp_frame_to_dom_tree("trn:slots",
-                                                   xaccTransGetSlots(trn));
-        if(kvpnode)
+                             xaccTransGetSlots(trn));
+        if (kvpnode)
         {
             xmlAddChild(ret, kvpnode);
         }
     }
 
     add_trans_splits(ret, trn);
-    
+
     return ret;
 }
 
@@ -197,8 +197,8 @@
 
 struct split_pdata
 {
-  Split *split;
-  QofBook *book;
+    Split *split;
+    QofBook *book;
 };
 
 static inline gboolean
@@ -207,7 +207,7 @@
 {
     gchar *tmp = dom_tree_to_text(node);
     g_return_val_if_fail(tmp, FALSE);
-    
+
     func(spl, tmp);
 
     g_free(tmp);
@@ -228,7 +228,7 @@
 
     return FALSE;
 }
-    
+
 static gboolean
 spl_id_handler(xmlNodePtr node, gpointer data)
 {
@@ -311,12 +311,12 @@
 
     account = xaccAccountLookup (id, pdata->book);
     if (!account && gnc_transaction_xml_v2_testing &&
-        !guid_equal (id, guid_null ()))
+            !guid_equal (id, guid_null ()))
     {
-      account = xaccMallocAccount (pdata->book);
-      xaccAccountSetGUID (account, id);
-      xaccAccountSetCommoditySCU (account,
-                                  xaccSplitGetAmount (pdata->split).denom);
+        account = xaccMallocAccount (pdata->book);
+        xaccAccountSetGUID (account, id);
+        xaccAccountSetCommoditySCU (account,
+                                    xaccSplitGetAmount (pdata->split).denom);
     }
 
     xaccAccountInsertSplit (account, pdata->split);
@@ -337,10 +337,10 @@
 
     lot = gnc_lot_lookup (id, pdata->book);
     if (!lot && gnc_transaction_xml_v2_testing &&
-        !guid_equal (id, guid_null ()))
+            !guid_equal (id, guid_null ()))
     {
-      lot = gnc_lot_new (pdata->book);
-      gnc_lot_set_guid (lot, *id);
+        lot = gnc_lot_new (pdata->book);
+        gnc_lot_set_guid (lot, *id);
     }
 
     gnc_lot_add_split (lot, pdata->split);
@@ -357,7 +357,7 @@
     gboolean successful;
 
     successful = dom_tree_to_kvp_frame_given(node,
-                                             xaccSplitGetSlots (pdata->split));
+                 xaccSplitGetSlots (pdata->split));
     g_return_val_if_fail(successful, FALSE);
 
     return TRUE;
@@ -393,7 +393,7 @@
     pdata.book = book;
 
     /* this isn't going to work in a testing setup */
-    if(dom_tree_generic_parse(node, spl_dom_handlers, &pdata))
+    if (dom_tree_generic_parse(node, spl_dom_handlers, &pdata))
     {
         return ret;
     }
@@ -408,8 +408,8 @@
 
 struct trans_pdata
 {
-  Transaction *trans;
-  QofBook *book;
+    Transaction *trans;
+    QofBook *book;
 };
 
 static inline gboolean
@@ -421,7 +421,7 @@
     tmp = dom_tree_to_text(node);
 
     g_return_val_if_fail(tmp, FALSE);
-    
+
     func(trn, tmp);
 
     g_free(tmp);
@@ -438,7 +438,7 @@
     tm = dom_tree_to_timespec(node);
 
     if (!dom_tree_valid_timespec(&tm, node->name)) return FALSE;
-    
+
     func(trn, &tm);
 
     return TRUE;
@@ -456,7 +456,7 @@
     xaccTransSetGUID((Transaction*)trn, tmp);
 
     g_free(tmp);
-    
+
     return TRUE;
 }
 
@@ -533,21 +533,21 @@
     g_return_val_if_fail(node, FALSE);
     g_return_val_if_fail(node->xmlChildrenNode, FALSE);
 
-    for(mark = node->xmlChildrenNode; mark; mark = mark->next)
+    for (mark = node->xmlChildrenNode; mark; mark = mark->next)
     {
         Split *spl;
-        
-        if(safe_strcmp("text", (char*)mark->name) == 0)
-          continue;
 
-        if(safe_strcmp("trn:split", (char*)mark->name))
+        if (safe_strcmp("text", (char*)mark->name) == 0)
+            continue;
+
+        if (safe_strcmp("trn:split", (char*)mark->name))
         {
             return FALSE;
         }
 
         spl = dom_tree_to_split(mark, pdata->book);
 
-        if(spl)
+        if (spl)
         {
             xaccTransAppendSplit(trn, spl);
         }
@@ -583,14 +583,14 @@
     xmlNodePtr tree = (xmlNodePtr)data_for_children;
     gxpf_data *gdata = (gxpf_data*)global_data;
 
-    if(parent_data)
+    if (parent_data)
     {
         return TRUE;
     }
 
     /* OK.  For some messed up reason this is getting called again with a
        NULL tag.  So we ignore those cases */
-    if(!tag)
+    if (!tag)
     {
         return TRUE;
     }
@@ -598,14 +598,14 @@
     g_return_val_if_fail(tree, FALSE);
 
     trn = dom_tree_to_transaction(tree, gdata->bookdata);
-    if(trn != NULL)
+    if (trn != NULL)
     {
         gdata->cb(tag, gdata->parsedata, trn);
         successful = TRUE;
     }
 
     xmlFreeNode(tree);
-    
+
     return trn != NULL;
 }
 
@@ -618,7 +618,7 @@
 
     g_return_val_if_fail(node, NULL);
     g_return_val_if_fail(book, NULL);
-    
+
     trn = xaccMallocTransaction(book);
     g_return_val_if_fail(trn, NULL);
     xaccTransBeginEdit(trn);

Modified: gnucash/trunk/src/backend/xml/gnc-xml.h
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-xml.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gnc-xml.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -33,7 +33,7 @@
 #include "sixtp.h"
 
 xmlNodePtr gnc_account_dom_tree_create(Account *act, gboolean exporting,
-				       gboolean allow_incompat);
+                                       gboolean allow_incompat);
 sixtp* gnc_account_sixtp_parser_create(void);
 
 xmlNodePtr gnc_book_dom_tree_create(QofBook *book);

Modified: gnucash/trunk/src/backend/xml/gncmod-backend-xml.c
===================================================================
--- gnucash/trunk/src/backend/xml/gncmod-backend-xml.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/gncmod-backend-xml.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -28,38 +28,38 @@
 char *
 libgncmod_backend_file_gnc_module_path(void)
 {
-  return g_strdup("gnucash/backend/file");
+    return g_strdup("gnucash/backend/file");
 }
 
 char *
 libgncmod_backend_file_gnc_module_description(void)
 {
-  return g_strdup("The binary and XML (v1 and v2) backends for GnuCash");
+    return g_strdup("The binary and XML (v1 and v2) backends for GnuCash");
 }
 
 int
 libgncmod_backend_file_gnc_module_init(int refcount)
 {
-  engine = gnc_module_load("gnucash/engine", 0);
-  if(!engine) return FALSE;
+    engine = gnc_module_load("gnucash/engine", 0);
+    if (!engine) return FALSE;
 
-  /* Need to initialize g-type engine for gconf */
-  if (refcount == 0)
-    g_type_init();
+    /* Need to initialize g-type engine for gconf */
+    if (refcount == 0)
+        g_type_init();
 
-  return TRUE;
+    return TRUE;
 }
 
 int
 libgncmod_backend_file_gnc_module_end(int refcount)
 {
-  int unload = TRUE;
+    int unload = TRUE;
 
-  if (engine)
-    unload = libgnc_backend_file_utils_gnc_module_unload(engine);
+    if (engine)
+        unload = libgnc_backend_file_utils_gnc_module_unload(engine);
 
-  if (refcount == 0)
-    engine = NULL;
+    if (refcount == 0)
+        engine = NULL;
 
-  return unload;
+    return unload;
 }

Modified: gnucash/trunk/src/backend/xml/io-example-account.c
===================================================================
--- gnucash/trunk/src/backend/xml/io-example-account.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/io-example-account.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -60,33 +60,33 @@
 void
 gnc_destroy_example_account(GncExampleAccount *gea)
 {
-    if(gea->title != NULL)
+    if (gea->title != NULL)
     {
         g_free(gea->title);
         gea->title = NULL;
     }
-    if(gea->filename != NULL)
+    if (gea->filename != NULL)
     {
         g_free(gea->filename);
         gea->filename = NULL;
     }
-    if(gea->root != NULL)
+    if (gea->root != NULL)
     {
         xaccAccountBeginEdit (gea->root);
         xaccAccountDestroy(gea->root);
         gea->root = NULL;
     }
-    if(gea->short_description != NULL)
+    if (gea->short_description != NULL)
     {
         g_free(gea->short_description);
         gea->short_description = NULL;
     }
-    if(gea->long_description != NULL)
+    if (gea->long_description != NULL)
     {
         g_free(gea->long_description);
         gea->long_description = NULL;
     }
-    if(gea->book != NULL)
+    if (gea->book != NULL)
     {
         qof_book_destroy(gea->book);
         gea->book = NULL;
@@ -103,7 +103,7 @@
     gnc_commodity *gcom;
     gnc_commodity *com = getter(act);
 
-    if(!com)
+    if (!com)
     {
         return;
     }
@@ -114,14 +114,14 @@
                                       gnc_commodity_get_namespace(com),
                                       gnc_commodity_get_mnemonic(com));
 
-    if(gcom == com)
+    if (gcom == com)
     {
         return;
     }
-    else if(!gcom)
+    else if (!gcom)
     {
         PWARN("unable to find global commodity for %s adding new",
-                  gnc_commodity_get_unique_name(com));
+              gnc_commodity_get_unique_name(com));
         gnc_commodity_table_insert(tbl, com);
     }
     else
@@ -150,9 +150,10 @@
     }
     else if (!gnc_account_get_parent(act))
     {
-        if (!gea->root) {
+        if (!gea->root)
+        {
             g_warning("The example account file should declared a ROOT "
-		      "account before declaring any other accounts.");
+                      "account before declaring any other accounts.");
             gea->root = gnc_book_get_root_account(gea->book);
         }
         gnc_account_append_child(gea->root, act);
@@ -164,7 +165,7 @@
 {
     GncExampleAccount *gea = (GncExampleAccount*)globaldata;
 
-    if(safe_strcmp(tag, "gnc:account") == 0)
+    if (safe_strcmp(tag, "gnc:account") == 0)
     {
         add_account_local(gea, (Account*)data);
     }
@@ -176,10 +177,10 @@
 {
     int spot;
     int length = strlen(text);
-    
-    for(spot = 1; spot < length; spot++)
+
+    for (spot = 1; spot < length; spot++)
     {
-        if(isspace(text[spot]) && isspace(text[spot - 1]))
+        if (isspace(text[spot]) && isspace(text[spot - 1]))
         {
             memmove(text + spot, text + spot + 1, length - spot + 1);
             length--;
@@ -205,10 +206,10 @@
                               gpointer *result, const gchar *tag)
 {
     GncExampleAccount *gea =
-    (GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
+        (GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
 
     gea->short_description = grab_clean_string((xmlNodePtr)data_for_children);
-    
+
     return TRUE;
 }
 
@@ -225,10 +226,10 @@
                              gpointer *result, const gchar *tag)
 {
     GncExampleAccount *gea =
-    (GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
+        (GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
 
     gea->long_description = grab_clean_string((xmlNodePtr)data_for_children);
-    
+
     return TRUE;
 }
 
@@ -240,17 +241,17 @@
 
 static gboolean
 gnc_excludep_end_handler(gpointer data_for_children,
-                             GSList* data_from_children, GSList* sibling_data,
-                             gpointer parent_data, gpointer global_data,
-                             gpointer *result, const gchar *tag)
+                         GSList* data_from_children, GSList* sibling_data,
+                         gpointer parent_data, gpointer global_data,
+                         gpointer *result, const gchar *tag)
 {
     GncExampleAccount *gea =
-    (GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
+        (GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
     gint64 val = 0;
 
     dom_tree_to_integer ((xmlNodePtr)data_for_children, &val);
     gea->exclude_from_select_all = (val ? TRUE : FALSE);
-    
+
     return TRUE;
 }
 
@@ -262,17 +263,17 @@
 
 static gboolean
 gnc_selected_end_handler(gpointer data_for_children,
-                             GSList* data_from_children, GSList* sibling_data,
-                             gpointer parent_data, gpointer global_data,
-                             gpointer *result, const gchar *tag)
+                         GSList* data_from_children, GSList* sibling_data,
+                         gpointer parent_data, gpointer global_data,
+                         gpointer *result, const gchar *tag)
 {
     GncExampleAccount *gea =
-    (GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
+        (GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
     gint64 val = 0;
 
     dom_tree_to_integer ((xmlNodePtr)data_for_children, &val);
     gea->start_selected = (val ? TRUE : FALSE);
-    
+
     return TRUE;
 }
 
@@ -284,15 +285,15 @@
 
 static gboolean
 gnc_title_end_handler(gpointer data_for_children,
-                             GSList* data_from_children, GSList* sibling_data,
-                             gpointer parent_data, gpointer global_data,
-                             gpointer *result, const gchar *tag)
+                      GSList* data_from_children, GSList* sibling_data,
+                      gpointer parent_data, gpointer global_data,
+                      gpointer *result, const gchar *tag)
 {
     GncExampleAccount *gea =
-    (GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
+        (GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
 
     gea->title = grab_clean_string((xmlNodePtr)data_for_children);
-    
+
     return TRUE;
 }
 
@@ -320,29 +321,29 @@
     top_parser = sixtp_new();
     main_parser = sixtp_new();
 
-    if(!sixtp_add_some_sub_parsers(
-        top_parser, TRUE,
-        GNC_ACCOUNT_STRING, main_parser,
-        NULL, NULL))
+    if (!sixtp_add_some_sub_parsers(
+                top_parser, TRUE,
+                GNC_ACCOUNT_STRING, main_parser,
+                NULL, NULL))
     {
         return FALSE;
     }
 
-    if(!sixtp_add_some_sub_parsers(
-           main_parser, TRUE,
-           GNC_ACCOUNT_TITLE, gnc_titse_sixtp_parser_create(),
-           GNC_ACCOUNT_SHORT, gnc_short_descrip_sixtp_parser_create(),
-           GNC_ACCOUNT_LONG, gnc_long_descrip_sixtp_parser_create(),
-	   GNC_ACCOUNT_EXCLUDEP, gnc_excludep_sixtp_parser_create(),
-	   GNC_ACCOUNT_SELECTED, gnc_selected_sixtp_parser_create(),
-           "gnc:account", gnc_account_sixtp_parser_create(),
-           NULL, NULL))
+    if (!sixtp_add_some_sub_parsers(
+                main_parser, TRUE,
+                GNC_ACCOUNT_TITLE, gnc_titse_sixtp_parser_create(),
+                GNC_ACCOUNT_SHORT, gnc_short_descrip_sixtp_parser_create(),
+                GNC_ACCOUNT_LONG, gnc_long_descrip_sixtp_parser_create(),
+                GNC_ACCOUNT_EXCLUDEP, gnc_excludep_sixtp_parser_create(),
+                GNC_ACCOUNT_SELECTED, gnc_selected_sixtp_parser_create(),
+                "gnc:account", gnc_account_sixtp_parser_create(),
+                NULL, NULL))
     {
         return FALSE;
     }
 
-    if(!gnc_xml_parse_file(top_parser, filename,
-                           generic_callback, gea, gea->book))
+    if (!gnc_xml_parse_file(top_parser, filename,
+                            generic_callback, gea, gea->book))
     {
         sixtp_destroy(top_parser);
         xaccLogEnable ();
@@ -394,21 +395,21 @@
     fprintf(out, "<" GNC_ACCOUNT_STRING ">\n");
 
     write_string_part(out, GNC_ACCOUNT_TITLE, gea->title);
-    
+
     write_string_part(out, GNC_ACCOUNT_SHORT, gea->short_description);
 
     write_string_part(out, GNC_ACCOUNT_LONG, gea->long_description);
-    
+
     write_bool_part(out, GNC_ACCOUNT_EXCLUDEP, gea->exclude_from_select_all);
 
     write_account_tree(out, gea->root, &data);
 
     fprintf(out, "</" GNC_ACCOUNT_STRING ">\n\n");
-    
+
     write_emacs_trailer(out);
 
     fclose(out);
-    
+
     return TRUE;
 
 }
@@ -418,7 +419,7 @@
 static void
 slist_destroy_example_account(gpointer data, gpointer user_data)
 {
-    if(data != NULL)
+    if (data != NULL)
     {
         gnc_destroy_example_account((GncExampleAccount*)data);
     }
@@ -444,28 +445,28 @@
 
     dir = g_dir_open(dirname, 0, NULL);
 
-    if(dir == NULL)
+    if (dir == NULL)
     {
         return NULL;
     }
-    
+
     ret = NULL;
 
-    for(direntry = g_dir_read_name(dir); direntry != NULL;
-        direntry = g_dir_read_name(dir))
+    for (direntry = g_dir_read_name(dir); direntry != NULL;
+            direntry = g_dir_read_name(dir))
     {
         gchar *filename;
         GncExampleAccount *gea;
         if (!g_str_has_suffix(direntry, "xea"))
-          continue;
+            continue;
 
         filename = g_build_filename(dirname, direntry, (gchar*) NULL);
 
-        if(!g_file_test(filename, G_FILE_TEST_IS_DIR))
+        if (!g_file_test(filename, G_FILE_TEST_IS_DIR))
         {
             gea = gnc_read_example_account(filename);
 
-            if(gea == NULL)
+            if (gea == NULL)
             {
                 g_free(filename);
                 gnc_free_example_account_list(ret);

Modified: gnucash/trunk/src/backend/xml/io-gncxml-gen.c
===================================================================
--- gnucash/trunk/src/backend/xml/io-gncxml-gen.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/io-gncxml-gen.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -38,6 +38,6 @@
     gpdata.parsedata = parsedata;
     gpdata.bookdata = bookdata;
 
-    return sixtp_parse_file(top_parser, filename, 
+    return sixtp_parse_file(top_parser, filename,
                             NULL, &gpdata, &parse_result);
 }

Modified: gnucash/trunk/src/backend/xml/io-gncxml-v1.c
===================================================================
--- gnucash/trunk/src/backend/xml/io-gncxml-v1.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/io-gncxml-v1.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -76,39 +76,41 @@
 static sixtp* gnc_pricedb_parser_new(void);
 
 
-typedef enum {
-  GNC_PARSE_ERR_NONE,
-  GNC_PARSE_ERR_BAD_VERSION,
+typedef enum
+{
+    GNC_PARSE_ERR_NONE,
+    GNC_PARSE_ERR_BAD_VERSION,
 } GNCParseErr;
 
-typedef struct {
-  /* have we gotten the file version yet? */
-  gboolean seen_version;
-  gint64 version;
+typedef struct
+{
+    /* have we gotten the file version yet? */
+    gboolean seen_version;
+    gint64 version;
 
-  /* top level <gnc-data> parser - we need this so we can set it up
-     after we see the file version. */
-  sixtp *gnc_parser;
+    /* top level <gnc-data> parser - we need this so we can set it up
+       after we see the file version. */
+    sixtp *gnc_parser;
 
-  /* The book */
-  QofBook *book;
+    /* The book */
+    QofBook *book;
 
-  /* The root account */
-  Account *root_account;
+    /* The root account */
+    Account *root_account;
 
-  /* The pricedb */
-  GNCPriceDB *pricedb;
+    /* The pricedb */
+    GNCPriceDB *pricedb;
 
-  /* The query */
-  //  Query *query;
+    /* The query */
+    //  Query *query;
 
-  GNCParseErr error;
+    GNCParseErr error;
 } GNCParseStatus;
 
 
 /* result for a characters handler is shared across all character
    handlers for a given node.  result for start/end pair is shared as
-   well. 
+   well.
 
    Cleaning up the results returned by children and characters
    handlers is the user's responsibility.
@@ -133,7 +135,7 @@
 
 /* ================================================================= */
 /* <version> (lineage <gnc>)
-   
+
    Fancy and strange - look for an integer version number.  If we get
    one, then modify the parent parser to handle the input.
 
@@ -143,37 +145,38 @@
  */
 
 static gboolean
-gnc_parser_configure_for_input_version(GNCParseStatus *status, gint64 version) 
+gnc_parser_configure_for_input_version(GNCParseStatus *status, gint64 version)
 {
 
-  status->version = version;
-  status->seen_version = TRUE;
+    status->version = version;
+    status->seen_version = TRUE;
 
-  /* Check for a legal version here. */
-  if(version != 1) {
-    status->error = GNC_PARSE_ERR_BAD_VERSION;
-    return(FALSE);
-  }
-  
-  /* Now set up the parser based on the version. */
-  
-  /* add <ledger-data> */
-  {
-    sixtp *ledger_data_pr = ledger_data_parser_new();
-    g_return_val_if_fail(ledger_data_pr, FALSE);
-    sixtp_add_sub_parser(status->gnc_parser, "ledger-data", ledger_data_pr);
-  }
+    /* Check for a legal version here. */
+    if (version != 1)
+    {
+        status->error = GNC_PARSE_ERR_BAD_VERSION;
+        return(FALSE);
+    }
 
+    /* Now set up the parser based on the version. */
+
+    /* add <ledger-data> */
+    {
+        sixtp *ledger_data_pr = ledger_data_parser_new();
+        g_return_val_if_fail(ledger_data_pr, FALSE);
+        sixtp_add_sub_parser(status->gnc_parser, "ledger-data", ledger_data_pr);
+    }
+
 #if 0
-  /* add <query-server> */
-  {
-    sixtp *query_server_pr = query_server_parser_new();
-    g_return_val_if_fail(query_server_pr, FALSE);
-    sixtp_add_sub_parser(status->gnc_parser, "query-server", query_server_pr);
-  }
+    /* add <query-server> */
+    {
+        sixtp *query_server_pr = query_server_parser_new();
+        g_return_val_if_fail(query_server_pr, FALSE);
+        sixtp_add_sub_parser(status->gnc_parser, "query-server", query_server_pr);
+    }
 #endif
 
-  return(TRUE);
+    return(TRUE);
 }
 
 static gboolean
@@ -182,35 +185,35 @@
                         gpointer parent_data, gpointer global_data,
                         gpointer *result, const gchar *tag)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  gint64 version;
-  gboolean ok;
-  gchar *txt;
-  
-  g_return_val_if_fail(pstatus, FALSE);
-  if(pstatus->seen_version) return(FALSE);
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  ok = string_to_gint64(txt, &version);
-  g_free(txt);
-  g_return_val_if_fail(ok, FALSE);
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    gint64 version;
+    gboolean ok;
+    gchar *txt;
 
-  if(!gnc_parser_configure_for_input_version(pstatus, version)) return(FALSE);
+    g_return_val_if_fail(pstatus, FALSE);
+    if (pstatus->seen_version) return(FALSE);
 
-  return(TRUE);
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    ok = string_to_gint64(txt, &version);
+    g_free(txt);
+    g_return_val_if_fail(ok, FALSE);
+
+    if (!gnc_parser_configure_for_input_version(pstatus, version)) return(FALSE);
+
+    return(TRUE);
 }
 
 static sixtp *
-gnc_version_parser_new(void) 
+gnc_version_parser_new(void)
 {
-  return(simple_chars_only_parser_new(gnc_version_end_handler));
+    return(simple_chars_only_parser_new(gnc_version_end_handler));
 }
 
 /****************************************************************************/
 /* <gnc> (lineage #f)
-   
+
    Takes the results from various children and puts them in the
    global_data result structure.
 
@@ -223,7 +226,7 @@
    after-child: if a ledger-data child, parse_data->root_account = *result.
    characters: allow_and_ignore_only_whitespace
 
-   Similarly, only one query is allowed ... 
+   Similarly, only one query is allowed ...
    end: NA
 
    cleanup-result: NA
@@ -236,31 +239,34 @@
 
 static gboolean
 gnc_parser_before_child_handler(gpointer data_for_children,
-                              GSList* data_from_children,
-                              GSList* sibling_data,
-                              gpointer parent_data,
-                              gpointer global_data,
-                              gpointer *result,
-                              
-                              const gchar *tag,
-                              const gchar *child_tag) 
-{  
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  
-  g_return_val_if_fail(pstatus, FALSE);
+                                GSList* data_from_children,
+                                GSList* sibling_data,
+                                gpointer parent_data,
+                                gpointer global_data,
+                                gpointer *result,
 
-  if(strcmp(child_tag, "ledger-data") == 0) {
-    if(pstatus->root_account) {
-      return(FALSE);
+                                const gchar *tag,
+                                const gchar *child_tag)
+{
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+
+    g_return_val_if_fail(pstatus, FALSE);
+
+    if (strcmp(child_tag, "ledger-data") == 0)
+    {
+        if (pstatus->root_account)
+        {
+            return(FALSE);
+        }
     }
-  }
 
 #if 0
-  if(strcmp(child_tag, "query-server") == 0) {
-    if(pstatus->query) return(FALSE);
-  }
+    if (strcmp(child_tag, "query-server") == 0)
+    {
+        if (pstatus->query) return(FALSE);
+    }
 #endif
-  return(TRUE);
+    return(TRUE);
 }
 
 static gboolean
@@ -274,38 +280,38 @@
                                const gchar *child_tag,
                                sixtp_child_result *child_result)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  g_return_val_if_fail(pstatus, FALSE);
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    g_return_val_if_fail(pstatus, FALSE);
 
-  if(strcmp(child_tag, "ledger-data") == 0) 
-  {
-    g_return_val_if_fail(child_result, FALSE);
-    g_return_val_if_fail(child_result->data, FALSE);
-    pstatus->root_account = (Account *) child_result->data;
-    child_result->should_cleanup = FALSE;
-  }
+    if (strcmp(child_tag, "ledger-data") == 0)
+    {
+        g_return_val_if_fail(child_result, FALSE);
+        g_return_val_if_fail(child_result->data, FALSE);
+        pstatus->root_account = (Account *) child_result->data;
+        child_result->should_cleanup = FALSE;
+    }
 
 #if 0
-  if(strcmp(child_tag, "query-server") == 0) 
-  {
-    g_return_val_if_fail(child_result, FALSE);
-    g_return_val_if_fail(child_result->data, FALSE);
-    pstatus->query = (Query *) child_result->data;
-    child_result->should_cleanup = FALSE;
-  }
+    if (strcmp(child_tag, "query-server") == 0)
+    {
+        g_return_val_if_fail(child_result, FALSE);
+        g_return_val_if_fail(child_result->data, FALSE);
+        pstatus->query = (Query *) child_result->data;
+        child_result->should_cleanup = FALSE;
+    }
 #endif
-  return(TRUE);
+    return(TRUE);
 }
 
 static sixtp*
-gnc_parser_new(void) 
+gnc_parser_new(void)
 {
     return sixtp_set_any(
-        sixtp_new(), FALSE,
-        SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
-        SIXTP_BEFORE_CHILD_HANDLER_ID, gnc_parser_before_child_handler,
-        SIXTP_AFTER_CHILD_HANDLER_ID, gnc_parser_after_child_handler,
-        SIXTP_NO_MORE_HANDLERS);
+               sixtp_new(), FALSE,
+               SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
+               SIXTP_BEFORE_CHILD_HANDLER_ID, gnc_parser_before_child_handler,
+               SIXTP_AFTER_CHILD_HANDLER_ID, gnc_parser_after_child_handler,
+               SIXTP_NO_MORE_HANDLERS);
 }
 
 /* ================================================================== */
@@ -314,41 +320,43 @@
 gncxml_setup_for_read (GNCParseStatus *global_parse_status)
 {
 
-  sixtp *top_level_pr;
-  sixtp *gnc_pr;
-  sixtp *gnc_version_pr;
+    sixtp *top_level_pr;
+    sixtp *gnc_pr;
+    sixtp *gnc_version_pr;
 
-  /* top-level: This is just a dummy node.  It doesn't do anything.
-     For now, the result is communicated through the global_data
-     parser. */
-  top_level_pr = sixtp_new();
-  g_return_val_if_fail(top_level_pr, FALSE);
-  sixtp_set_chars(top_level_pr, allow_and_ignore_only_whitespace);
+    /* top-level: This is just a dummy node.  It doesn't do anything.
+       For now, the result is communicated through the global_data
+       parser. */
+    top_level_pr = sixtp_new();
+    g_return_val_if_fail(top_level_pr, FALSE);
+    sixtp_set_chars(top_level_pr, allow_and_ignore_only_whitespace);
 
-  /* <gnc> */
-  gnc_pr = gnc_parser_new();
-  if(!gnc_pr) {
-    sixtp_destroy(top_level_pr);
-    return(NULL);
-  }
-  sixtp_add_sub_parser(top_level_pr, "gnc", gnc_pr);
+    /* <gnc> */
+    gnc_pr = gnc_parser_new();
+    if (!gnc_pr)
+    {
+        sixtp_destroy(top_level_pr);
+        return(NULL);
+    }
+    sixtp_add_sub_parser(top_level_pr, "gnc", gnc_pr);
 
-  /* <version> */
-  gnc_version_pr = gnc_version_parser_new();
-  if(!gnc_version_pr) {
-    sixtp_destroy(top_level_pr);
-    return(NULL);
-  }
-  sixtp_add_sub_parser(gnc_pr, "version", gnc_version_pr);
+    /* <version> */
+    gnc_version_pr = gnc_version_parser_new();
+    if (!gnc_version_pr)
+    {
+        sixtp_destroy(top_level_pr);
+        return(NULL);
+    }
+    sixtp_add_sub_parser(gnc_pr, "version", gnc_version_pr);
 
-  global_parse_status->seen_version = FALSE;
-  global_parse_status->gnc_parser = gnc_pr;
-  global_parse_status->root_account = NULL;
-  global_parse_status->pricedb = NULL;
-  //  global_parse_status->query = NULL;
-  global_parse_status->error = GNC_PARSE_ERR_NONE;
+    global_parse_status->seen_version = FALSE;
+    global_parse_status->gnc_parser = gnc_pr;
+    global_parse_status->root_account = NULL;
+    global_parse_status->pricedb = NULL;
+    //  global_parse_status->query = NULL;
+    global_parse_status->error = GNC_PARSE_ERR_NONE;
 
-  return top_level_pr;
+    return top_level_pr;
 }
 
 /* ================================================================== */
@@ -356,52 +364,54 @@
 gboolean
 qof_session_load_from_xml_file(QofBook *book, const char *filename)
 {
-  gboolean parse_ok;
-  gpointer parse_result = NULL;
-  sixtp *top_level_pr;
-  GNCParseStatus global_parse_status;
-  Account *root;
+    gboolean parse_ok;
+    gpointer parse_result = NULL;
+    sixtp *top_level_pr;
+    GNCParseStatus global_parse_status;
+    Account *root;
 
-  global_parse_status.book = book;
-  g_return_val_if_fail(book, FALSE);
-  g_return_val_if_fail(filename, FALSE);
+    global_parse_status.book = book;
+    g_return_val_if_fail(book, FALSE);
+    g_return_val_if_fail(filename, FALSE);
 
-  xaccDisableDataScrubbing();
-  top_level_pr = gncxml_setup_for_read (&global_parse_status);
-  g_return_val_if_fail(top_level_pr, FALSE);
+    xaccDisableDataScrubbing();
+    top_level_pr = gncxml_setup_for_read (&global_parse_status);
+    g_return_val_if_fail(top_level_pr, FALSE);
 
-  parse_ok = sixtp_parse_file(top_level_pr,
-                              filename,
-                              NULL,
-                              &global_parse_status,
-                              &parse_result);
+    parse_ok = sixtp_parse_file(top_level_pr,
+                                filename,
+                                NULL,
+                                &global_parse_status,
+                                &parse_result);
 
-  sixtp_destroy(top_level_pr);
-  xaccEnableDataScrubbing();
+    sixtp_destroy(top_level_pr);
+    xaccEnableDataScrubbing();
 
-  if(parse_ok) 
-  {
-    if(!global_parse_status.root_account) return FALSE;
+    if (parse_ok)
+    {
+        if (!global_parse_status.root_account) return FALSE;
 
-    root = global_parse_status.root_account;
-    gnc_book_set_root_account(book, root);
+        root = global_parse_status.root_account;
+        gnc_book_set_root_account(book, root);
 
-    /* Fix account and transaction commodities */
-    xaccAccountTreeScrubCommodities (root);
+        /* Fix account and transaction commodities */
+        xaccAccountTreeScrubCommodities (root);
 
-    /* Fix split amount/value */
-    xaccAccountTreeScrubSplits (root);
+        /* Fix split amount/value */
+        xaccAccountTreeScrubSplits (root);
 
-    return(TRUE);
-  } else {
-    return(FALSE);
-  }
+        return(TRUE);
+    }
+    else
+    {
+        return(FALSE);
+    }
 }
 
 /* ================================================================== */
 
 gboolean
-gnc_is_xml_data_file(const gchar *filename) 
+gnc_is_xml_data_file(const gchar *filename)
 {
     return gnc_is_our_xml_file(filename, "gnc", NULL);
 }
@@ -411,7 +421,7 @@
 
 /****************************************************************************/
 /* <kvp-frame>
-   
+
    A collection of node functions intended to parse a sub-node set
    that looks like this:
 
@@ -447,13 +457,13 @@
 
 static void
 kvp_value_result_cleanup(sixtp_child_result *cr)
-{  
-  kvp_value *v = (kvp_value *) cr->data;;
-  if(v) kvp_value_delete(v);
+{
+    kvp_value *v = (kvp_value *) cr->data;;
+    if (v) kvp_value_delete(v);
 }
 
 static sixtp*
-simple_kvp_value_parser_new(sixtp_end_handler end_handler) 
+simple_kvp_value_parser_new(sixtp_end_handler end_handler)
 {
     return sixtp_set_any(sixtp_new(), FALSE,
                          SIXTP_CHARACTERS_HANDLER_ID,
@@ -514,15 +524,16 @@
                              gpointer parent_data,
                              gpointer global_data,
                              gpointer *result,
-                             const gchar *tag) 
+                             const gchar *tag)
 {
     KVP_CVT_VALUE (gint64);
 }
 
 
 static sixtp*
-gint64_kvp_value_parser_new(void) {
-  return(simple_kvp_value_parser_new(gint64_kvp_value_end_handler));
+gint64_kvp_value_parser_new(void)
+{
+    return(simple_kvp_value_parser_new(gint64_kvp_value_end_handler));
 }
 
 static gboolean
@@ -532,14 +543,15 @@
                              gpointer parent_data,
                              gpointer global_data,
                              gpointer *result,
-                             const gchar *tag) 
+                             const gchar *tag)
 {
     KVP_CVT_VALUE (double);
 }
 
 static sixtp*
-double_kvp_value_parser_new(void) {
-  return(simple_kvp_value_parser_new(double_kvp_value_end_handler));
+double_kvp_value_parser_new(void)
+{
+    return(simple_kvp_value_parser_new(double_kvp_value_end_handler));
 }
 
 static gboolean
@@ -549,45 +561,47 @@
                                   gpointer parent_data,
                                   gpointer global_data,
                                   gpointer *result,
-                                  const gchar *tag) 
+                                  const gchar *tag)
 {
     KVP_CVT_VALUE (gnc_numeric);
 }
 
 static sixtp*
-gnc_numeric_kvp_value_parser_new(void) {
-  return(simple_kvp_value_parser_new(gnc_numeric_kvp_value_end_handler));
+gnc_numeric_kvp_value_parser_new(void)
+{
+    return(simple_kvp_value_parser_new(gnc_numeric_kvp_value_end_handler));
 }
 
 static gboolean
 string_kvp_value_end_handler(gpointer data_for_children,
-                        GSList* data_from_children,
-                        GSList* sibling_data,
-                        gpointer parent_data,
-                        gpointer global_data,
-                        gpointer *result,
-                        const gchar *tag) 
+                             GSList* data_from_children,
+                             GSList* sibling_data,
+                             gpointer parent_data,
+                             gpointer global_data,
+                             gpointer *result,
+                             const gchar *tag)
 {
-  gchar *txt = NULL;
-  kvp_value *kvpv;
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  kvpv = kvp_value_new_string(txt);
-  g_free(txt);
-  g_return_val_if_fail(kvpv, FALSE);
-    
-  *result = kvpv;
-  return(TRUE);
+    gchar *txt = NULL;
+    kvp_value *kvpv;
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    kvpv = kvp_value_new_string(txt);
+    g_free(txt);
+    g_return_val_if_fail(kvpv, FALSE);
+
+    *result = kvpv;
+    return(TRUE);
 }
 
 static sixtp*
-string_kvp_value_parser_new(void) {
-  return(simple_kvp_value_parser_new(string_kvp_value_end_handler));
+string_kvp_value_parser_new(void)
+{
+    return(simple_kvp_value_parser_new(string_kvp_value_end_handler));
 }
 
-/* the guid handler is almost the same as above, but has 
+/* the guid handler is almost the same as above, but has
  * inconsistent type handling */
 static gboolean
 guid_kvp_value_end_handler(gpointer data_for_children,
@@ -596,31 +610,32 @@
                            gpointer parent_data,
                            gpointer global_data,
                            gpointer *result,
-                           const gchar *tag) 
+                           const gchar *tag)
 {
-  gchar *txt = NULL;
-  GUID val;
-  kvp_value *kvpv;
-  gboolean ok;
+    gchar *txt = NULL;
+    GUID val;
+    kvp_value *kvpv;
+    gboolean ok;
 
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
 
-  ok = string_to_guid(txt, &val);
-  g_free(txt);
+    ok = string_to_guid(txt, &val);
+    g_free(txt);
 
-  g_return_val_if_fail(ok, FALSE);
+    g_return_val_if_fail(ok, FALSE);
 
-  kvpv = kvp_value_new_guid(&val);
-  g_return_val_if_fail(kvpv, FALSE);
-   
-  *result = kvpv;
-  return(TRUE);
+    kvpv = kvp_value_new_guid(&val);
+    g_return_val_if_fail(kvpv, FALSE);
+
+    *result = kvpv;
+    return(TRUE);
 }
 
 static sixtp*
-guid_kvp_value_parser_new(void) {
-  return(simple_kvp_value_parser_new(guid_kvp_value_end_handler));
+guid_kvp_value_parser_new(void)
+{
+    return(simple_kvp_value_parser_new(guid_kvp_value_end_handler));
 }
 
 /*********************************/
@@ -647,7 +662,7 @@
    fail: NA
    result-fail: kvp_value_delete
    chars-fail: g_free chars
-   
+
  */
 
 static gboolean
@@ -656,30 +671,31 @@
                                  gpointer parent_data, gpointer global_data,
                                  gpointer *result, const gchar *tag)
 {
-  gchar *txt = NULL;
-  void *val;
-  guint64 size;
-  kvp_value *kvpv;
-  gboolean ok;
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  ok = hex_string_to_binary(txt, &val, &size);
-  g_free(txt);
+    gchar *txt = NULL;
+    void *val;
+    guint64 size;
+    kvp_value *kvpv;
+    gboolean ok;
 
-  g_return_val_if_fail(ok, FALSE);
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
 
-  kvpv = kvp_value_new_binary_nc(val, size);
-  g_return_val_if_fail(kvpv, FALSE);
-    
-  *result = kvpv;
-  return(TRUE);
+    ok = hex_string_to_binary(txt, &val, &size);
+    g_free(txt);
+
+    g_return_val_if_fail(ok, FALSE);
+
+    kvpv = kvp_value_new_binary_nc(val, size);
+    g_return_val_if_fail(kvpv, FALSE);
+
+    *result = kvpv;
+    return(TRUE);
 }
 
 static sixtp*
-hex_binary_kvp_value_parser_new(void) {
-  return(simple_kvp_value_parser_new(hex_binary_kvp_value_end_handler));
+hex_binary_kvp_value_parser_new(void)
+{
+    return(simple_kvp_value_parser_new(hex_binary_kvp_value_end_handler));
 }
 
 /* <binary> (lineage <s> <kvp-frame>)
@@ -704,66 +720,68 @@
                              gpointer parent_data, gpointer global_data,
                              gpointer *result, const gchar *tag)
 {
-  void *data;
-  guint64 total_size;
-  guint64 pos;
-  kvp_value *kvpv;
-  GSList *lp;
-  
-  /* at this point, we know that if there are child results, they all
-     have to be binary kvp_values. */
-  
-  /* first see how much data we've got. */
-  total_size = 0;
-  for(lp = data_from_children; lp; lp = lp->next) {
-    sixtp_child_result *cr = (sixtp_child_result *) lp->data;
-    kvp_value *kvp = (kvp_value *) cr->data;
-    void *tmpdata;
-    guint64 tmpsize;
+    void *data;
+    guint64 total_size;
+    guint64 pos;
+    kvp_value *kvpv;
+    GSList *lp;
 
-    tmpdata = kvp_value_get_binary(kvp, &tmpsize);
-    g_return_val_if_fail(tmpdata, FALSE);
-    total_size += tmpsize;
-  }
+    /* at this point, we know that if there are child results, they all
+       have to be binary kvp_values. */
 
-  /* allocate a chunk to hold it all and copy */
-  data = g_new(gchar, total_size);
-  g_return_val_if_fail(data, FALSE);
+    /* first see how much data we've got. */
+    total_size = 0;
+    for (lp = data_from_children; lp; lp = lp->next)
+    {
+        sixtp_child_result *cr = (sixtp_child_result *) lp->data;
+        kvp_value *kvp = (kvp_value *) cr->data;
+        void *tmpdata;
+        guint64 tmpsize;
 
-  pos = 0;
-  for(lp = data_from_children; lp; lp = lp->next) {
-    sixtp_child_result *cr = (sixtp_child_result *) lp->data;
-    kvp_value *kvp = (kvp_value *) cr->data;
-    void *new_data;
-    guint64 new_size;
+        tmpdata = kvp_value_get_binary(kvp, &tmpsize);
+        g_return_val_if_fail(tmpdata, FALSE);
+        total_size += tmpsize;
+    }
 
-    new_data = kvp_value_get_binary(kvp, &new_size);
-    g_return_val_if_fail(new_data, FALSE);
-    memcpy((data + pos), new_data, new_size);
-    pos += new_size;
-  }
+    /* allocate a chunk to hold it all and copy */
+    data = g_new(gchar, total_size);
+    g_return_val_if_fail(data, FALSE);
 
-  kvpv = kvp_value_new_binary_nc(data, total_size);
-  g_return_val_if_fail(kvpv, FALSE);
+    pos = 0;
+    for (lp = data_from_children; lp; lp = lp->next)
+    {
+        sixtp_child_result *cr = (sixtp_child_result *) lp->data;
+        kvp_value *kvp = (kvp_value *) cr->data;
+        void *new_data;
+        guint64 new_size;
 
-  *result = kvpv;
-  return(TRUE);
+        new_data = kvp_value_get_binary(kvp, &new_size);
+        g_return_val_if_fail(new_data, FALSE);
+        memcpy((data + pos), new_data, new_size);
+        pos += new_size;
+    }
+
+    kvpv = kvp_value_new_binary_nc(data, total_size);
+    g_return_val_if_fail(kvpv, FALSE);
+
+    *result = kvpv;
+    return(TRUE);
 }
 
 static sixtp*
-binary_kvp_value_parser_new(void) 
+binary_kvp_value_parser_new(void)
 {
     return sixtp_add_some_sub_parsers(
-        sixtp_set_any(sixtp_new(), FALSE,
-                      SIXTP_CHARACTERS_HANDLER_ID,
-                      allow_and_ignore_only_whitespace,
-                      SIXTP_END_HANDLER_ID, kvp_frame_binary_end_handler,
-                      SIXTP_CLEANUP_RESULT_ID, kvp_value_result_cleanup,
-                      SIXTP_RESULT_FAIL_ID, kvp_value_result_cleanup,
-                      SIXTP_NO_MORE_HANDLERS),
-        TRUE,
-        "hex", hex_binary_kvp_value_parser_new(),
-        0);
+               sixtp_set_any(sixtp_new(), FALSE,
+                             SIXTP_CHARACTERS_HANDLER_ID,
+                             allow_and_ignore_only_whitespace,
+                             SIXTP_END_HANDLER_ID, kvp_frame_binary_end_handler,
+                             SIXTP_CLEANUP_RESULT_ID, kvp_value_result_cleanup,
+                             SIXTP_RESULT_FAIL_ID, kvp_value_result_cleanup,
+                             SIXTP_NO_MORE_HANDLERS),
+               TRUE,
+               "hex", hex_binary_kvp_value_parser_new(),
+               0);
 }
 
 /*********************************/
@@ -783,7 +801,7 @@
    fail: NA
    result-fail: kvp_value_delete
    chars-fail: NA
-   
+
  */
 
 
@@ -793,26 +811,28 @@
                             gpointer parent_data, gpointer global_data,
                             gpointer *result, const gchar *tag)
 {
-  GSList *lp;
-  GList *result_glist;
-  kvp_value *kvp_result;
+    GSList *lp;
+    GList *result_glist;
+    kvp_value *kvp_result;
 
-  result_glist = NULL;
-  for(lp = data_from_children; lp; lp = lp->next) {
-    sixtp_child_result *cr = (sixtp_child_result *) lp->data;
-    kvp_value *kvp = (kvp_value *) cr->data;
+    result_glist = NULL;
+    for (lp = data_from_children; lp; lp = lp->next)
+    {
+        sixtp_child_result *cr = (sixtp_child_result *) lp->data;
+        kvp_value *kvp = (kvp_value *) cr->data;
 
-    /* children are in reverse chron order, so this fixes it. */
-    result_glist = g_list_prepend(result_glist, kvp);
-    cr->should_cleanup = FALSE;
-  }
+        /* children are in reverse chron order, so this fixes it. */
+        result_glist = g_list_prepend(result_glist, kvp);
+        cr->should_cleanup = FALSE;
+    }
 
-  kvp_result = kvp_value_new_glist_nc(result_glist);
-  if(!kvp_result) {
-    kvp_glist_delete(result_glist);
-  }
-  *result = kvp_result;
-  return(TRUE);
+    kvp_result = kvp_value_new_glist_nc(result_glist);
+    if (!kvp_result)
+    {
+        kvp_glist_delete(result_glist);
+    }
+    *result = kvp_result;
+    return(TRUE);
 }
 
 /* ---------------------------------------------- */
@@ -826,42 +846,45 @@
 static gboolean
 add_all_kvp_value_parsers_as_sub_nodes(sixtp *p,
                                        sixtp *kvp_frame_parser,
-                                       sixtp *glist_parser) {
-  sixtp *child_pr;
+                                       sixtp *glist_parser)
+{
+    sixtp *child_pr;
 
-  g_return_val_if_fail(p, FALSE);
-  g_return_val_if_fail(kvp_frame_parser, FALSE);
+    g_return_val_if_fail(p, FALSE);
+    g_return_val_if_fail(kvp_frame_parser, FALSE);
 
-  KVP_TOKEN(gint64, "gint64");
-  KVP_TOKEN(double, "double");
-  KVP_TOKEN(gnc_numeric, "numeric");
-  KVP_TOKEN(string, "string");
-  KVP_TOKEN(guid,   "guid");
-  KVP_TOKEN(binary, "binary");
+    KVP_TOKEN(gint64, "gint64");
+    KVP_TOKEN(double, "double");
+    KVP_TOKEN(gnc_numeric, "numeric");
+    KVP_TOKEN(string, "string");
+    KVP_TOKEN(guid,   "guid");
+    KVP_TOKEN(binary, "binary");
 
-  sixtp_add_sub_parser(p, "glist", glist_parser);
-  sixtp_add_sub_parser(p, "frame", kvp_frame_parser);
+    sixtp_add_sub_parser(p, "glist", glist_parser);
+    sixtp_add_sub_parser(p, "frame", kvp_frame_parser);
 
-  return(TRUE);
+    return(TRUE);
 }
 
 static sixtp*
-glist_kvp_value_parser_new(sixtp *kvp_frame_parser) {
+glist_kvp_value_parser_new(sixtp *kvp_frame_parser)
+{
     sixtp *top_level = sixtp_set_any(
-        sixtp_new(), FALSE,
-        SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
-        SIXTP_END_HANDLER_ID, glist_kvp_value_end_handler,
-        SIXTP_CLEANUP_RESULT_ID, kvp_value_result_cleanup,
-        SIXTP_RESULT_FAIL_ID, kvp_value_result_cleanup,
-        SIXTP_NO_MORE_HANDLERS);
-    if(!top_level)
+                           sixtp_new(), FALSE,
+                           SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
+                           SIXTP_END_HANDLER_ID, glist_kvp_value_end_handler,
+                           SIXTP_CLEANUP_RESULT_ID, kvp_value_result_cleanup,
+                           SIXTP_RESULT_FAIL_ID, kvp_value_result_cleanup,
+                           SIXTP_NO_MORE_HANDLERS);
+    if (!top_level)
     {
         return NULL;
     }
-  
-    if(!add_all_kvp_value_parsers_as_sub_nodes(top_level,
-                                               kvp_frame_parser,
-                                               top_level)) {
+
+    if (!add_all_kvp_value_parsers_as_sub_nodes(top_level,
+            kvp_frame_parser,
+            top_level))
+    {
         sixtp_destroy(top_level);
         return(NULL);
     }
@@ -870,8 +893,8 @@
 }
 
 /*********************************/
-/* kvp-frame slot handlers 
-   
+/* kvp-frame slot handlers
+
    handlers for the <s><k>some key</k><[value]>data</[value]> sub-structure.
 */
 
@@ -906,82 +929,99 @@
                            gpointer parent_data, gpointer global_data,
                            gpointer *result, const gchar *tag)
 {
-  kvp_frame *f = (kvp_frame *) parent_data;
-  GSList *lp;
-  guint64 key_node_count;
-  gchar *key = NULL;
-  sixtp_child_result *value_cr = NULL;
-  kvp_value *value = NULL;
-  gboolean delete_value = FALSE;
+    kvp_frame *f = (kvp_frame *) parent_data;
+    GSList *lp;
+    guint64 key_node_count;
+    gchar *key = NULL;
+    sixtp_child_result *value_cr = NULL;
+    kvp_value *value = NULL;
+    gboolean delete_value = FALSE;
 
-  g_return_val_if_fail(f, FALSE);
+    g_return_val_if_fail(f, FALSE);
 
-  if(g_slist_length(data_from_children) != 2) return(FALSE);
+    if (g_slist_length(data_from_children) != 2) return(FALSE);
 
-  /* check to see that we got exactly one <key> node */
-  lp = data_from_children;
-  key_node_count = 0;
-  for(lp = data_from_children; lp; lp = lp->next) {
-    sixtp_child_result *cr = (sixtp_child_result *) lp->data;
+    /* check to see that we got exactly one <key> node */
+    lp = data_from_children;
+    key_node_count = 0;
+    for (lp = data_from_children; lp; lp = lp->next)
+    {
+        sixtp_child_result *cr = (sixtp_child_result *) lp->data;
 
-    if(is_child_result_from_node_named(cr, "k")) {
-      key = (char *) cr->data;
-      key_node_count++;
-    } else {
-      if(is_child_result_from_node_named(cr, "frame")) {
-        kvp_frame *frame = cr->data;
-        value = kvp_value_new_frame (frame);
-        delete_value = TRUE;
-      } else {
-        value = cr->data;
-        delete_value = FALSE;
-      }
+        if (is_child_result_from_node_named(cr, "k"))
+        {
+            key = (char *) cr->data;
+            key_node_count++;
+        }
+        else
+        {
+            if (is_child_result_from_node_named(cr, "frame"))
+            {
+                kvp_frame *frame = cr->data;
+                value = kvp_value_new_frame (frame);
+                delete_value = TRUE;
+            }
+            else
+            {
+                value = cr->data;
+                delete_value = FALSE;
+            }
 
-      value_cr = cr;
+            value_cr = cr;
+        }
     }
-  }
 
-  if(key_node_count != 1) return(FALSE);
+    if (key_node_count != 1) return(FALSE);
 
-  value_cr->should_cleanup = TRUE;
-  kvp_frame_set_slot(f, key, value);
-  if (delete_value)
-    kvp_value_delete (value);
-  return(TRUE);
+    value_cr->should_cleanup = TRUE;
+    kvp_frame_set_slot(f, key, value);
+    if (delete_value)
+        kvp_value_delete (value);
+    return(TRUE);
 }
 
 static sixtp*
-kvp_frame_slot_parser_new(sixtp *kvp_frame_parser) {
-  sixtp *top_level;
-  sixtp *child_pr;
-  sixtp *glist_pr;
+kvp_frame_slot_parser_new(sixtp *kvp_frame_parser)
+{
+    sixtp *top_level;
+    sixtp *child_pr;
+    sixtp *glist_pr;
 
-  g_return_val_if_fail(kvp_frame_parser, NULL);
+    g_return_val_if_fail(kvp_frame_parser, NULL);
 
-  if(!(top_level = sixtp_set_any(
-           sixtp_new(), FALSE,
-           SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
-           SIXTP_END_HANDLER_ID, kvp_frame_slot_end_handler,
-           SIXTP_NO_MORE_HANDLERS)))
-  {
-      return NULL;
-  }
+    if (!(top_level = sixtp_set_any(
+                          sixtp_new(), FALSE,
+                          SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
+                          SIXTP_END_HANDLER_ID, kvp_frame_slot_end_handler,
+                          SIXTP_NO_MORE_HANDLERS)))
+    {
+        return NULL;
+    }
 
-  child_pr = simple_chars_only_parser_new(NULL);
-  if(!child_pr) { sixtp_destroy(top_level); return(NULL); }
-  sixtp_add_sub_parser(top_level, "k", child_pr);
+    child_pr = simple_chars_only_parser_new(NULL);
+    if (!child_pr)
+    {
+        sixtp_destroy(top_level);
+        return(NULL);
+    }
+    sixtp_add_sub_parser(top_level, "k", child_pr);
 
-  glist_pr = glist_kvp_value_parser_new(kvp_frame_parser);
-  if(!glist_pr) { sixtp_destroy(top_level); return(NULL); }
+    glist_pr = glist_kvp_value_parser_new(kvp_frame_parser);
+    if (!glist_pr)
+    {
+        sixtp_destroy(top_level);
+        return(NULL);
+    }
 
-  if(!add_all_kvp_value_parsers_as_sub_nodes(top_level,
-                                             kvp_frame_parser,
-                                             glist_pr)) {
-    sixtp_destroy(top_level);
-    return(NULL);
-  }
+    if (!add_all_kvp_value_parsers_as_sub_nodes(top_level,
+            kvp_frame_parser,
+            glist_pr))
+    {
+        sixtp_destroy(top_level);
+        return(NULL);
+    }
 
-  return(top_level);
+    return(top_level);
 }
 
 
@@ -1007,10 +1047,10 @@
                         gpointer global_data, gpointer *data_for_children,
                         gpointer *result, const gchar *tag, gchar **attrs)
 {
-  kvp_frame *f = kvp_frame_new();
-  g_return_val_if_fail(f, FALSE);
-  *data_for_children = f;
-  return(TRUE);
+    kvp_frame *f = kvp_frame_new();
+    g_return_val_if_fail(f, FALSE);
+    *data_for_children = f;
+    return(TRUE);
 }
 
 static gboolean
@@ -1019,59 +1059,59 @@
                       gpointer parent_data, gpointer global_data,
                       gpointer *result, const gchar *tag)
 {
-  kvp_frame *f = (kvp_frame *) data_for_children;
-  g_return_val_if_fail(f, FALSE);
-  *result = f;
-  return(TRUE);
+    kvp_frame *f = (kvp_frame *) data_for_children;
+    g_return_val_if_fail(f, FALSE);
+    *result = f;
+    return(TRUE);
 }
 
 static void
 kvp_frame_fail_handler(gpointer data_for_children,
-                         GSList* data_from_children,
-                         GSList* sibling_data,
-                         gpointer parent_data,
-                         gpointer global_data,
-                         gpointer *result,
-                         const gchar *tag)
+                       GSList* data_from_children,
+                       GSList* sibling_data,
+                       gpointer parent_data,
+                       gpointer global_data,
+                       gpointer *result,
+                       const gchar *tag)
 {
-  kvp_frame *f = (kvp_frame *) data_for_children;
-  if(f) kvp_frame_delete(f);
+    kvp_frame *f = (kvp_frame *) data_for_children;
+    if (f) kvp_frame_delete(f);
 }
 
 static void
 kvp_frame_result_cleanup(sixtp_child_result *cr)
 {
-  kvp_frame *f = (kvp_frame *) cr->data;;
-  if(f) kvp_frame_delete(f);
+    kvp_frame *f = (kvp_frame *) cr->data;;
+    if (f) kvp_frame_delete(f);
 }
 
 static sixtp*
-kvp_frame_parser_new(void) 
+kvp_frame_parser_new(void)
 {
-  sixtp *top_level;
+    sixtp *top_level;
 
-  if(!(top_level = sixtp_set_any(
-           sixtp_new(), FALSE,
-           SIXTP_START_HANDLER_ID, kvp_frame_start_handler,
-           SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
-           SIXTP_END_HANDLER_ID, kvp_frame_end_handler,
-           SIXTP_CLEANUP_RESULT_ID, kvp_frame_result_cleanup,
-           SIXTP_RESULT_FAIL_ID, kvp_frame_result_cleanup,
-           SIXTP_FAIL_HANDLER_ID, kvp_frame_fail_handler,
-           SIXTP_NO_MORE_HANDLERS)))
-  {
-      return NULL;
-  }
+    if (!(top_level = sixtp_set_any(
+                          sixtp_new(), FALSE,
+                          SIXTP_START_HANDLER_ID, kvp_frame_start_handler,
+                          SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
+                          SIXTP_END_HANDLER_ID, kvp_frame_end_handler,
+                          SIXTP_CLEANUP_RESULT_ID, kvp_frame_result_cleanup,
+                          SIXTP_RESULT_FAIL_ID, kvp_frame_result_cleanup,
+                          SIXTP_FAIL_HANDLER_ID, kvp_frame_fail_handler,
+                          SIXTP_NO_MORE_HANDLERS)))
+    {
+        return NULL;
+    }
 
-  if(!(sixtp_add_some_sub_parsers(
-           top_level, TRUE,
-           "s", kvp_frame_slot_parser_new(top_level),
-           0)))
-  {
-      return NULL;
-  }
+    if (!(sixtp_add_some_sub_parsers(
+                top_level, TRUE,
+                "s", kvp_frame_slot_parser_new(top_level),
+                0)))
+    {
+        return NULL;
+    }
 
-  return(top_level);
+    return(top_level);
 }
 
 /****************************************************************************/
@@ -1102,17 +1142,17 @@
                           gpointer global_data, gpointer *data_for_children,
                           gpointer *result, const gchar *tag, gchar **attrs)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  Account *ra;
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    Account *ra;
 
-  /* disable logging during load; otherwise its just a mess */
-  xaccLogDisable();
-  ra = xaccMallocAccount(pstatus->book);
+    /* disable logging during load; otherwise its just a mess */
+    xaccLogDisable();
+    ra = xaccMallocAccount(pstatus->book);
 
-  g_return_val_if_fail(ra, FALSE);
+    g_return_val_if_fail(ra, FALSE);
 
-  *data_for_children = ra;
-  return(ra != NULL);
+    *data_for_children = ra;
+    return(ra != NULL);
 }
 
 static gboolean
@@ -1126,25 +1166,27 @@
                                 const gchar *child_tag,
                                 sixtp_child_result *child_result)
 {
-  if(!child_result) return(TRUE);
+    if (!child_result) return(TRUE);
 
-  /* if we see the pricedb, deal with it */
-  if(child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE);
-  if(strcmp(child_result->tag, "pricedb") == 0) {
-    GNCPriceDB *pdb = (GNCPriceDB *) child_result->data;
-    GNCParseStatus *status = (GNCParseStatus *) global_data;
+    /* if we see the pricedb, deal with it */
+    if (child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE);
+    if (strcmp(child_result->tag, "pricedb") == 0)
+    {
+        GNCPriceDB *pdb = (GNCPriceDB *) child_result->data;
+        GNCParseStatus *status = (GNCParseStatus *) global_data;
 
-    g_return_val_if_fail(pdb, FALSE);
-    g_return_val_if_fail(status, FALSE);
+        g_return_val_if_fail(pdb, FALSE);
+        g_return_val_if_fail(status, FALSE);
 
-    if(status->pricedb) {
-      PERR("hit pricedb twice in data file.");
-      return FALSE;
+        if (status->pricedb)
+        {
+            PERR("hit pricedb twice in data file.");
+            return FALSE;
+        }
+        status->pricedb = pdb;
+        child_result->should_cleanup = FALSE;
     }
-    status->pricedb = pdb;
-    child_result->should_cleanup = FALSE;
-  }
-  return(TRUE);
+    return(TRUE);
 }
 
 static gboolean
@@ -1153,23 +1195,23 @@
                         gpointer parent_data, gpointer global_data,
                         gpointer *result, const gchar *tag)
 {
-  
-  Account *ra = (Account *) data_for_children;
-  GList *descendants;
 
-  g_return_val_if_fail(ra, FALSE);
+    Account *ra = (Account *) data_for_children;
+    GList *descendants;
 
-  /* commit all accounts, this completes the BeginEdit started when the
-   * account_end_handler finished reading the account.
-   */
-  descendants = gnc_account_get_descendants(ra);
-  g_list_foreach(descendants, (GFunc)xaccAccountCommitEdit, NULL);
-  g_list_free(descendants);
+    g_return_val_if_fail(ra, FALSE);
 
-  xaccLogEnable();
+    /* commit all accounts, this completes the BeginEdit started when the
+     * account_end_handler finished reading the account.
+     */
+    descendants = gnc_account_get_descendants(ra);
+    g_list_foreach(descendants, (GFunc)xaccAccountCommitEdit, NULL);
+    g_list_free(descendants);
 
-  *result = ra;
-  return(TRUE);
+    xaccLogEnable();
+
+    *result = ra;
+    return(TRUE);
 }
 
 static void
@@ -1181,64 +1223,64 @@
                          gpointer *result,
                          const gchar *tag)
 {
-  Account *account = (Account *) data_for_children;
-  if (account)
-  {
-    xaccAccountBeginEdit(account);
-    xaccAccountDestroy(account);
-  }
+    Account *account = (Account *) data_for_children;
+    if (account)
+    {
+        xaccAccountBeginEdit(account);
+        xaccAccountDestroy(account);
+    }
 }
 
 static void
 ledger_data_result_cleanup(sixtp_child_result *cr)
 {
-  Account *account = (Account *) cr->data;
-  if (account)
-  {
-    xaccAccountBeginEdit(account);
-    xaccAccountDestroy(account);
-  }
+    Account *account = (Account *) cr->data;
+    if (account)
+    {
+        xaccAccountBeginEdit(account);
+        xaccAccountDestroy(account);
+    }
 }
 
 
 static sixtp*
-ledger_data_parser_new(void) 
+ledger_data_parser_new(void)
 {
-  sixtp *top_level;
-  
-  /* <ledger-data> */
-  if(!(top_level = sixtp_set_any(
-           sixtp_new(), FALSE,
-           SIXTP_START_HANDLER_ID, ledger_data_start_handler,
-           SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
-           SIXTP_AFTER_CHILD_HANDLER_ID, ledger_data_after_child_handler,
-           SIXTP_END_HANDLER_ID, ledger_data_end_handler,
-           SIXTP_CLEANUP_RESULT_ID, ledger_data_result_cleanup,
-           SIXTP_FAIL_HANDLER_ID, ledger_data_fail_handler,
-           SIXTP_RESULT_FAIL_ID, ledger_data_result_cleanup,
-           SIXTP_NO_MORE_HANDLERS)))
-  {
-      return NULL;
-  }
+    sixtp *top_level;
 
-  if(!sixtp_add_some_sub_parsers(
-         top_level, TRUE,
-         "commodity", commodity_restore_parser_new(),
-         "pricedb", gnc_pricedb_parser_new(),
-         "account", gnc_account_parser_new(),
-         "transaction", gnc_transaction_parser_new(),
-         0))
-  {
-      return NULL;
-  }
+    /* <ledger-data> */
+    if (!(top_level = sixtp_set_any(
+                          sixtp_new(), FALSE,
+                          SIXTP_START_HANDLER_ID, ledger_data_start_handler,
+                          SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
+                          SIXTP_AFTER_CHILD_HANDLER_ID, ledger_data_after_child_handler,
+                          SIXTP_END_HANDLER_ID, ledger_data_end_handler,
+                          SIXTP_CLEANUP_RESULT_ID, ledger_data_result_cleanup,
+                          SIXTP_FAIL_HANDLER_ID, ledger_data_fail_handler,
+                          SIXTP_RESULT_FAIL_ID, ledger_data_result_cleanup,
+                          SIXTP_NO_MORE_HANDLERS)))
+    {
+        return NULL;
+    }
 
-  return(top_level);
+    if (!sixtp_add_some_sub_parsers(
+                top_level, TRUE,
+                "commodity", commodity_restore_parser_new(),
+                "pricedb", gnc_pricedb_parser_new(),
+                "account", gnc_account_parser_new(),
+                "transaction", gnc_transaction_parser_new(),
+                0))
+    {
+        return NULL;
+    }
+
+    return(top_level);
 }
 
 /***********************************************************************/
 /****************************************************************************/
 /* <account> (parent <ledger-data>)
- 
+
    This block does nothing but pass the ledger-data account group down
    to its children.  It generates no data of its own, so it doesn't
    need any cleanup.
@@ -1248,7 +1290,7 @@
    to-children-via-*result: Account*
 
    returns: NA
-   
+
    start: pass input to children.
 
    characters: NA
@@ -1276,19 +1318,19 @@
                       const gchar *tag,
                       gchar **attrs)
 {
-  /* pass the parent data down to the children */
-  *data_for_children = parent_data;
-  return(TRUE);
+    /* pass the parent data down to the children */
+    *data_for_children = parent_data;
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <restore> (lineage <account> <ledger-data>)
-   
+
    restores a given account.  We allocate the new account in the
    start block, the children modify it, and in the end block, we see
    if the resultant account is OK, and if so, we add it to the
    ledger-data's account group.
- 
+
    input: Account*
    to-children-via-*result: new Account*
    returns: NA
@@ -1311,16 +1353,16 @@
                               const gchar *tag,
                               gchar **attrs)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  Account *acc = xaccMallocAccount(pstatus->book);
-  
-  g_return_val_if_fail(acc, FALSE);
-  xaccAccountBeginEdit(acc);
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    Account *acc = xaccMallocAccount(pstatus->book);
 
-  *data_for_children = acc;
-  *result = acc;
+    g_return_val_if_fail(acc, FALSE);
+    xaccAccountBeginEdit(acc);
 
-  return(TRUE);
+    *data_for_children = acc;
+    *result = acc;
+
+    return(TRUE);
 }
 
 static gboolean
@@ -1329,27 +1371,27 @@
                             gpointer parent_data, gpointer global_data,
                             gpointer *result, const gchar *tag)
 {
-  Account *parent = (Account *) parent_data;
-  Account *acc = (Account *) *result;
+    Account *parent = (Account *) parent_data;
+    Account *acc = (Account *) * result;
 
-  g_return_val_if_fail((parent && acc), FALSE);
+    g_return_val_if_fail((parent && acc), FALSE);
 
-  /* CHECKME: do we need to xaccAccountRecomputeBalance(acc) here? */
-  xaccAccountCommitEdit(acc);
+    /* CHECKME: do we need to xaccAccountRecomputeBalance(acc) here? */
+    xaccAccountCommitEdit(acc);
 
-  /* If the account doesn't have a parent yet, just cram it into the
-     top level */
-  if (!gnc_account_get_parent(acc))
-    gnc_account_append_child(parent, acc);
+    /* If the account doesn't have a parent yet, just cram it into the
+       top level */
+    if (!gnc_account_get_parent(acc))
+        gnc_account_append_child(parent, acc);
 
-  *result = NULL;
+    *result = NULL;
 
-  /* Now return the account to the "edit" state.  At the end of reading
-   * all the transactions, we will Commit.  This replaces #splits
-   *  rebalances with #accounts rebalances at the end.  A BIG win!
-   */
-  xaccAccountBeginEdit(acc);
-  return(TRUE);
+    /* Now return the account to the "edit" state.  At the end of reading
+     * all the transactions, we will Commit.  This replaces #splits
+     *  rebalances with #accounts rebalances at the end.  A BIG win!
+     */
+    xaccAccountBeginEdit(acc);
+    return(TRUE);
 }
 
 static gboolean
@@ -1363,36 +1405,39 @@
                                     const gchar *child_tag,
                                     sixtp_child_result *child_result)
 {
-  Account *a = (Account *) data_for_children;
-  /* GNCParseStatus *pstatus = (GNCParseStatus *) global_data; */
+    Account *a = (Account *) data_for_children;
+    /* GNCParseStatus *pstatus = (GNCParseStatus *) global_data; */
 
-  g_return_val_if_fail(a, FALSE);
+    g_return_val_if_fail(a, FALSE);
 
-  if(!child_result) return(TRUE);
-  if(child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE);
-  if(strcmp(child_result->tag, "slots") == 0) {
-    kvp_frame *f = (kvp_frame *) child_result->data;
-    g_return_val_if_fail(f, FALSE);
-    if(a->inst.kvp_data) kvp_frame_delete(a->inst.kvp_data);
-    a->inst.kvp_data = f;
-    child_result->should_cleanup = FALSE;
-  }
-  else if(strcmp(child_result->tag, "currency") == 0) {
-    gnc_commodity *com = (gnc_commodity *) child_result->data;
-    g_return_val_if_fail(com, FALSE);
-    if(DxaccAccountGetCurrency(a)) return FALSE;
-    DxaccAccountSetCurrency(a, com);
-    /* let the normal child_result handler clean up com */
-  }
-  else if(strcmp(child_result->tag, "security") == 0) {
-    gnc_commodity *com = (gnc_commodity *) child_result->data;
-    g_return_val_if_fail(com, FALSE);
-    if(DxaccAccountGetSecurity(a)) return FALSE;
-    DxaccAccountSetSecurity(a, com);
-    /* let the normal child_result handler clean up com */
-  }
+    if (!child_result) return(TRUE);
+    if (child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE);
+    if (strcmp(child_result->tag, "slots") == 0)
+    {
+        kvp_frame *f = (kvp_frame *) child_result->data;
+        g_return_val_if_fail(f, FALSE);
+        if (a->inst.kvp_data) kvp_frame_delete(a->inst.kvp_data);
+        a->inst.kvp_data = f;
+        child_result->should_cleanup = FALSE;
+    }
+    else if (strcmp(child_result->tag, "currency") == 0)
+    {
+        gnc_commodity *com = (gnc_commodity *) child_result->data;
+        g_return_val_if_fail(com, FALSE);
+        if (DxaccAccountGetCurrency(a)) return FALSE;
+        DxaccAccountSetCurrency(a, com);
+        /* let the normal child_result handler clean up com */
+    }
+    else if (strcmp(child_result->tag, "security") == 0)
+    {
+        gnc_commodity *com = (gnc_commodity *) child_result->data;
+        g_return_val_if_fail(com, FALSE);
+        if (DxaccAccountGetSecurity(a)) return FALSE;
+        DxaccAccountSetSecurity(a, com);
+        /* let the normal child_result handler clean up com */
+    }
 
-  return(TRUE);
+    return(TRUE);
 }
 
 static void
@@ -1404,17 +1449,17 @@
                              gpointer *result,
                              const gchar *tag)
 {
-  Account *acc = (Account *) *result;
-  if(acc)
-  {
-    xaccAccountBeginEdit (acc);
-    xaccAccountDestroy(acc);
-  }
+    Account *acc = (Account *) * result;
+    if (acc)
+    {
+        xaccAccountBeginEdit (acc);
+        xaccAccountDestroy(acc);
+    }
 }
 
 /****************************************************************************/
 /* <name> (lineage <restore> <account>)
-   
+
    restores a given account's name.
    input: Account*
    returns: NA
@@ -1436,22 +1481,22 @@
                              gpointer parent_data, gpointer global_data,
                              gpointer *result, const gchar *tag)
 {
-  Account *acc = (Account *) parent_data;
-  gchar *name = NULL;
+    Account *acc = (Account *) parent_data;
+    gchar *name = NULL;
 
-  g_return_val_if_fail(acc, FALSE);
+    g_return_val_if_fail(acc, FALSE);
 
-  name = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(name, FALSE);
-  
-  xaccAccountSetName(acc, name);
-  g_free(name);
-  return(TRUE);
+    name = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(name, FALSE);
+
+    xaccAccountSetName(acc, name);
+    g_free(name);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <guid> (lineage <restore> <account>)
-   
+
    restores a given account's guid.
    input: Account*
    returns: NA
@@ -1474,34 +1519,34 @@
                              gpointer parent_data, gpointer global_data,
                              gpointer *result, const gchar *tag)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  Account *acc = (Account *) parent_data;
-  gchar *txt = NULL;
-  GUID gid;
-  gboolean ok;
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    Account *acc = (Account *) parent_data;
+    gchar *txt = NULL;
+    GUID gid;
+    gboolean ok;
 
-  g_return_val_if_fail(acc, FALSE);
+    g_return_val_if_fail(acc, FALSE);
 
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  ok = string_to_guid(txt, &gid);
-  g_free(txt);
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
 
-  g_return_val_if_fail(ok, FALSE);
+    ok = string_to_guid(txt, &gid);
+    g_free(txt);
 
-  if(xaccAccountLookup(&gid, pstatus->book)) 
-  {
-    return(FALSE);
-  }
+    g_return_val_if_fail(ok, FALSE);
 
-  xaccAccountSetGUID(acc, &gid);
-  return(TRUE);
+    if (xaccAccountLookup(&gid, pstatus->book))
+    {
+        return(FALSE);
+    }
+
+    xaccAccountSetGUID(acc, &gid);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <type> (lineage <restore> <account>)
-   
+
    restores a given account's type.
    input: Account*
    returns: NA
@@ -1524,28 +1569,28 @@
                              gpointer parent_data, gpointer global_data,
                              gpointer *result, const gchar *tag)
 {
-  Account *acc = (Account *) parent_data;
-  gchar *txt = NULL;
-  int type;
-  gboolean ok;
+    Account *acc = (Account *) parent_data;
+    gchar *txt = NULL;
+    int type;
+    gboolean ok;
 
-  g_return_val_if_fail(acc, FALSE);
+    g_return_val_if_fail(acc, FALSE);
 
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  ok = xaccAccountStringToType(txt, &type);
-  g_free(txt);
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
 
-  g_return_val_if_fail(ok, FALSE);
-  
-  xaccAccountSetType(acc, type);
-  return(TRUE);
+    ok = xaccAccountStringToType(txt, &type);
+    g_free(txt);
+
+    g_return_val_if_fail(ok, FALSE);
+
+    xaccAccountSetType(acc, type);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <code> (lineage <restore> <account>)
-   
+
    restores a given account's code.
    input: Account*
    returns: NA
@@ -1568,22 +1613,22 @@
                              gpointer parent_data, gpointer global_data,
                              gpointer *result, const gchar *tag)
 {
-  Account *acc = (Account *) parent_data;
-  gchar *txt = NULL;
-  
-  g_return_val_if_fail(acc, FALSE);
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  xaccAccountSetCode(acc, txt);
-  g_free(txt);
-  return(TRUE);
+    Account *acc = (Account *) parent_data;
+    gchar *txt = NULL;
+
+    g_return_val_if_fail(acc, FALSE);
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    xaccAccountSetCode(acc, txt);
+    g_free(txt);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <description> (lineage <restore> <account>)
-   
+
    restores a given account's description.
    input: Account*
    returns: NA
@@ -1607,22 +1652,22 @@
                                     gpointer parent_data, gpointer global_data,
                                     gpointer *result, const gchar *tag)
 {
-  Account *acc = (Account *) parent_data;
-  gchar *txt = NULL;
-  
-  g_return_val_if_fail(acc, FALSE);
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  xaccAccountSetDescription(acc, txt);
-  g_free(txt);
-  return(TRUE);
+    Account *acc = (Account *) parent_data;
+    gchar *txt = NULL;
+
+    g_return_val_if_fail(acc, FALSE);
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    xaccAccountSetDescription(acc, txt);
+    g_free(txt);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <notes> (lineage <restore> <account>)
-   
+
    restores a given account's notes.
    input: Account*
    returns: NA
@@ -1645,22 +1690,22 @@
                               gpointer parent_data, gpointer global_data,
                               gpointer *result, const gchar *tag)
 {
-  Account *acc = (Account *) parent_data;
-  gchar *txt = NULL;
-  
-  g_return_val_if_fail(acc, FALSE);
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  xaccAccountSetNotes(acc, txt);
-  g_free(txt);
-  return(TRUE);
+    Account *acc = (Account *) parent_data;
+    gchar *txt = NULL;
+
+    g_return_val_if_fail(acc, FALSE);
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    xaccAccountSetNotes(acc, txt);
+    g_free(txt);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <parent> (lineage <restore> <account>)
-   
+
    restores a given account's parent.
    input: Account*
    returns: NA
@@ -1686,32 +1731,32 @@
                                gpointer parent_data, gpointer global_data,
                                gpointer *result, const gchar *tag)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  Account *acc = (Account *) parent_data;
-  Account *parent;
-  sixtp_child_result *child_result;
-  GUID gid;
-  
-  g_return_val_if_fail(acc, FALSE);
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    Account *acc = (Account *) parent_data;
+    Account *parent;
+    sixtp_child_result *child_result;
+    GUID gid;
 
-  if(g_slist_length(data_from_children) != 1)
-    return(FALSE);
+    g_return_val_if_fail(acc, FALSE);
 
-  child_result = (sixtp_child_result *) data_from_children->data;
-  
-  if(!is_child_result_from_node_named(child_result, "guid"))
-    return(FALSE);
+    if (g_slist_length(data_from_children) != 1)
+        return(FALSE);
 
-  /* otherwise this must be a good result - use it */
-  gid = *((GUID *) child_result->data);
+    child_result = (sixtp_child_result *) data_from_children->data;
 
-  parent = xaccAccountLookup(&gid, pstatus->book);
-  
-  g_return_val_if_fail(parent, FALSE);
+    if (!is_child_result_from_node_named(child_result, "guid"))
+        return(FALSE);
 
-  gnc_account_append_child(parent, acc);
+    /* otherwise this must be a good result - use it */
+    gid = *((GUID *) child_result->data);
 
-  return(TRUE);
+    parent = xaccAccountLookup(&gid, pstatus->book);
+
+    g_return_val_if_fail(parent, FALSE);
+
+    gnc_account_append_child(parent, acc);
+
+    return(TRUE);
 }
 
 static sixtp *
@@ -1728,62 +1773,62 @@
 static sixtp *
 gnc_account_parser_new(void)
 {
-  sixtp *restore_pr;
-  sixtp *ret;
-    
-  /* <account> */
-  if(!(ret = sixtp_set_any(
-           sixtp_new(), FALSE,
-           SIXTP_START_HANDLER_ID, account_start_handler,
-           SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
-           SIXTP_NO_MORE_HANDLERS)))
-  {
-      return NULL;
-  }
-  
-  /* <account> <restore> */
-  if(!(restore_pr =
-       sixtp_set_any(sixtp_new(), FALSE,
-                     SIXTP_START_HANDLER_ID, account_restore_start_handler,
-                     SIXTP_END_HANDLER_ID, account_restore_end_handler,
-                     SIXTP_FAIL_HANDLER_ID, account_restore_fail_handler,
-                     SIXTP_AFTER_CHILD_HANDLER_ID,
-                     account_restore_after_child_handler,
-                     SIXTP_NO_MORE_HANDLERS)))
-  {
-      sixtp_destroy(ret);
-      return NULL;
-  }
-  
-  /* <restore> (<name> | <guid> | <type> | <code> | <description> | <notes>)*/
-  if(!sixtp_add_some_sub_parsers(
-         restore_pr, TRUE,
-         "name", restore_char_generator(acc_restore_name_end_handler),
-         "guid", restore_char_generator(acc_restore_guid_end_handler),
-         "type", restore_char_generator(acc_restore_type_end_handler),
-         "code", restore_char_generator(acc_restore_code_end_handler),
-         "description",
-         restore_char_generator(acc_restore_description_end_handler),
-         "notes", restore_char_generator(acc_restore_notes_end_handler),
-         /* <account> <restore> <currency> */
-         "currency", generic_gnc_commodity_lookup_parser_new(),
-         /* <account> <restore> <security> */
-         "security", generic_gnc_commodity_lookup_parser_new(),
-         /* <account> <restore> <parent> */
-         "parent", sixtp_add_some_sub_parsers(
-             parent_lookup_parser_new(), TRUE,
-             "guid", generic_guid_parser_new(),
-             0),
-         "slots", kvp_frame_parser_new(),
-         0))
-  {
-      sixtp_destroy(ret);
-      return NULL;
-  }
-  
-  sixtp_add_sub_parser(ret, "restore", restore_pr);
+    sixtp *restore_pr;
+    sixtp *ret;
 
-  return ret;
+    /* <account> */
+    if (!(ret = sixtp_set_any(
+                    sixtp_new(), FALSE,
+                    SIXTP_START_HANDLER_ID, account_start_handler,
+                    SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
+                    SIXTP_NO_MORE_HANDLERS)))
+    {
+        return NULL;
+    }
+
+    /* <account> <restore> */
+    if (!(restore_pr =
+                sixtp_set_any(sixtp_new(), FALSE,
+                              SIXTP_START_HANDLER_ID, account_restore_start_handler,
+                              SIXTP_END_HANDLER_ID, account_restore_end_handler,
+                              SIXTP_FAIL_HANDLER_ID, account_restore_fail_handler,
+                              SIXTP_AFTER_CHILD_HANDLER_ID,
+                              account_restore_after_child_handler,
+                              SIXTP_NO_MORE_HANDLERS)))
+    {
+        sixtp_destroy(ret);
+        return NULL;
+    }
+
+    /* <restore> (<name> | <guid> | <type> | <code> | <description> | <notes>)*/
+    if (!sixtp_add_some_sub_parsers(
+                restore_pr, TRUE,
+                "name", restore_char_generator(acc_restore_name_end_handler),
+                "guid", restore_char_generator(acc_restore_guid_end_handler),
+                "type", restore_char_generator(acc_restore_type_end_handler),
+                "code", restore_char_generator(acc_restore_code_end_handler),
+                "description",
+                restore_char_generator(acc_restore_description_end_handler),
+                "notes", restore_char_generator(acc_restore_notes_end_handler),
+                /* <account> <restore> <currency> */
+                "currency", generic_gnc_commodity_lookup_parser_new(),
+                /* <account> <restore> <security> */
+                "security", generic_gnc_commodity_lookup_parser_new(),
+                /* <account> <restore> <parent> */
+                "parent", sixtp_add_some_sub_parsers(
+                    parent_lookup_parser_new(), TRUE,
+                    "guid", generic_guid_parser_new(),
+                    0),
+                "slots", kvp_frame_parser_new(),
+                0))
+    {
+        sixtp_destroy(ret);
+        return NULL;
+    }
+
+    sixtp_add_sub_parser(ret, "restore", restore_pr);
+
+    return ret;
 }
 /***********************************************************************/
 /****************************************************************************/
@@ -1795,7 +1840,7 @@
    We also check to see that we get a <fraction>.  If not, it's an
    error.
 
-   Example:   
+   Example:
      <commodity>
        <restore>
          <space>NASDAQ</space>
@@ -1833,13 +1878,14 @@
 
  */
 
-typedef struct {
-  gchar *space;
-  gchar *id;
-  gchar *name;
-  gchar *xcode;
-  gboolean seen_fraction;
-  int fraction;
+typedef struct
+{
+    gchar *space;
+    gchar *id;
+    gchar *name;
+    gchar *xcode;
+    gboolean seen_fraction;
+    int fraction;
 } CommodityParseInfo;
 
 static gboolean
@@ -1848,13 +1894,13 @@
                                 gpointer *data_for_children, gpointer *result,
                                 const gchar *tag, gchar **attrs)
 {
-  CommodityParseInfo *cpi =
-    (CommodityParseInfo *) g_new0(CommodityParseInfo, 1);
+    CommodityParseInfo *cpi =
+        (CommodityParseInfo *) g_new0(CommodityParseInfo, 1);
 
-  g_return_val_if_fail(cpi, FALSE);
+    g_return_val_if_fail(cpi, FALSE);
 
-  *data_for_children = cpi;
-  return(TRUE);
+    *data_for_children = cpi;
+    return(TRUE);
 }
 
 /* ----------------------------------------------------*/
@@ -1864,7 +1910,7 @@
     cpi->NAME = (gchar *) child_result->data;		\
     child_result->should_cleanup = FALSE;		\
   }							\
-  else 
+  else
 /* ----------------------------------------------------*/
 
 static gboolean
@@ -1878,30 +1924,33 @@
                                       const gchar *child_tag,
                                       sixtp_child_result *child_result)
 {
-  CommodityParseInfo *cpi = (CommodityParseInfo *) data_for_children;
+    CommodityParseInfo *cpi = (CommodityParseInfo *) data_for_children;
 
-  g_return_val_if_fail(cpi, FALSE);
-  g_return_val_if_fail(child_result, FALSE);
+    g_return_val_if_fail(cpi, FALSE);
+    g_return_val_if_fail(child_result, FALSE);
 
-  COMMOD_TOKEN(space)
-  COMMOD_TOKEN(id)
-  COMMOD_TOKEN(name)
-  COMMOD_TOKEN(xcode)
-  if(strcmp(child_result->tag, "fraction") == 0) {
-    gint64 frac;
-    gboolean conv_ok;
+    COMMOD_TOKEN(space)
+    COMMOD_TOKEN(id)
+    COMMOD_TOKEN(name)
+    COMMOD_TOKEN(xcode)
+    if (strcmp(child_result->tag, "fraction") == 0)
+    {
+        gint64 frac;
+        gboolean conv_ok;
 
-    if(cpi->seen_fraction) return(FALSE);
-    conv_ok = string_to_gint64((gchar *) child_result->data, &frac);
-    cpi->fraction = frac;
-    cpi->seen_fraction = TRUE;
-    child_result->should_cleanup = TRUE;
-  } else {
-    /* redundant because the parser won't allow any other children */
-    return(FALSE);
-  }
+        if (cpi->seen_fraction) return(FALSE);
+        conv_ok = string_to_gint64((gchar *) child_result->data, &frac);
+        cpi->fraction = frac;
+        cpi->seen_fraction = TRUE;
+        child_result->should_cleanup = TRUE;
+    }
+    else
+    {
+        /* redundant because the parser won't allow any other children */
+        return(FALSE);
+    }
 
-  return(TRUE);
+    return(TRUE);
 }
 
 static gboolean
@@ -1910,93 +1959,94 @@
                               gpointer parent_data, gpointer global_data,
                               gpointer *result, const gchar *tag)
 {
-  CommodityParseInfo *cpi = (CommodityParseInfo *) data_for_children;
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  gboolean ok = FALSE;
-  gnc_commodity *comm = NULL;
+    CommodityParseInfo *cpi = (CommodityParseInfo *) data_for_children;
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    gboolean ok = FALSE;
+    gnc_commodity *comm = NULL;
 
-  g_return_val_if_fail(cpi, FALSE);
+    g_return_val_if_fail(cpi, FALSE);
 
-  if(cpi->seen_fraction) {
-    gnc_commodity *comm;
+    if (cpi->seen_fraction)
+    {
+        gnc_commodity *comm;
 
-    if(!cpi->space) cpi->space = g_strdup("");
-    if(!cpi->id) cpi->id = g_strdup("");
-    if(!cpi->name) cpi->name = g_strdup("");
-    if(!cpi->xcode) cpi->xcode = g_strdup("");
+        if (!cpi->space) cpi->space = g_strdup("");
+        if (!cpi->id) cpi->id = g_strdup("");
+        if (!cpi->name) cpi->name = g_strdup("");
+        if (!cpi->xcode) cpi->xcode = g_strdup("");
 
-    comm = gnc_commodity_new(pstatus->book,
-			     cpi->name,
-                             cpi->space,
-                             cpi->id,
-                             cpi->xcode,
-                             cpi->fraction);
-    if(comm)
-    {
-      gnc_commodity_table *ctab;
+        comm = gnc_commodity_new(pstatus->book,
+                                 cpi->name,
+                                 cpi->space,
+                                 cpi->id,
+                                 cpi->xcode,
+                                 cpi->fraction);
+        if (comm)
+        {
+            gnc_commodity_table *ctab;
 
-      ctab = gnc_book_get_commodity_table (pstatus->book);
+            ctab = gnc_book_get_commodity_table (pstatus->book);
 
-      if(ctab)
-      {
-        gnc_commodity_table_insert(ctab, comm);
-        ok = TRUE;
-      }
+            if (ctab)
+            {
+                gnc_commodity_table_insert(ctab, comm);
+                ok = TRUE;
+            }
+        }
     }
-  }
 
-  g_free(cpi->space);
-  g_free(cpi->id);
-  g_free(cpi->name);
-  g_free(cpi->xcode);
-  g_free(cpi);
+    g_free(cpi->space);
+    g_free(cpi->id);
+    g_free(cpi->name);
+    g_free(cpi->xcode);
+    g_free(cpi);
 
-  if(!ok) gnc_commodity_destroy(comm);
+    if (!ok) gnc_commodity_destroy(comm);
 
-  return(ok);
+    return(ok);
 }
 
 
 static sixtp *
-commodity_restore_parser_new(void) 
+commodity_restore_parser_new(void)
 {
-  sixtp *top_level;
-  sixtp *restore_pr;
+    sixtp *top_level;
+    sixtp *restore_pr;
 
-  top_level = sixtp_new();
-  g_return_val_if_fail(top_level, NULL);
+    top_level = sixtp_new();
+    g_return_val_if_fail(top_level, NULL);
 
-  if(!(restore_pr = sixtp_set_any(
-           sixtp_new(), FALSE,
-           SIXTP_START_HANDLER_ID, commodity_restore_start_handler,
-           SIXTP_END_HANDLER_ID, commodity_restore_end_handler,
-           SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children,
-           SIXTP_AFTER_CHILD_HANDLER_ID, commodity_restore_after_child_handler,
-           SIXTP_NO_MORE_HANDLERS)))
-  {
-      sixtp_destroy(top_level);
-      return(NULL);
-  }
-  sixtp_add_sub_parser(top_level, "restore", restore_pr);
-  
-  if(!sixtp_add_some_sub_parsers(
-         restore_pr, TRUE,
-         "space", simple_chars_only_parser_new(NULL),
-         "id", simple_chars_only_parser_new(NULL),
-         "name", simple_chars_only_parser_new(NULL),
-         "xcode", simple_chars_only_parser_new(NULL),
-         "fraction", simple_chars_only_parser_new(NULL),
-         0))
-  {
-      return NULL;
-  }
+    if (!(restore_pr = sixtp_set_any(
+                           sixtp_new(), FALSE,
+                           SIXTP_START_HANDLER_ID, commodity_restore_start_handler,
+                           SIXTP_END_HANDLER_ID, commodity_restore_end_handler,
+                           SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children,
+                           SIXTP_AFTER_CHILD_HANDLER_ID, commodity_restore_after_child_handler,
+                           SIXTP_NO_MORE_HANDLERS)))
+    {
+        sixtp_destroy(top_level);
+        return(NULL);
+    }
+    sixtp_add_sub_parser(top_level, "restore", restore_pr);
 
-  return(top_level);
+    if (!sixtp_add_some_sub_parsers(
+                restore_pr, TRUE,
+                "space", simple_chars_only_parser_new(NULL),
+                "id", simple_chars_only_parser_new(NULL),
+                "name", simple_chars_only_parser_new(NULL),
+                "xcode", simple_chars_only_parser_new(NULL),
+                "fraction", simple_chars_only_parser_new(NULL),
+                0))
+    {
+        return NULL;
+    }
+
+    return(top_level);
 }
 
 /****************************************************************************/
 /* generic gnc_commodity lookup handler.
-   
+
    A collection of node functions intended to parse a sub-node set
    that looks like this:
 
@@ -2031,9 +2081,10 @@
 
  */
 
-typedef struct {
-  gchar *namespace;
-  gchar *id;
+typedef struct
+{
+    gchar *namespace;
+    gchar *id;
 } CommodityLookupParseInfo;
 
 static gboolean
@@ -2042,110 +2093,116 @@
     gpointer *data_for_children, gpointer *result, const gchar *tag,
     gchar **attrs)
 {
-  CommodityLookupParseInfo *cpi = g_new0(CommodityLookupParseInfo, 1);
-  g_return_val_if_fail(cpi, FALSE);
-  *data_for_children = cpi;
-  return(TRUE);
+    CommodityLookupParseInfo *cpi = g_new0(CommodityLookupParseInfo, 1);
+    g_return_val_if_fail(cpi, FALSE);
+    *data_for_children = cpi;
+    return(TRUE);
 }
 
 static gboolean
 generic_gnc_commodity_lookup_after_child_handler(gpointer data_for_children,
-                           GSList* data_from_children,
-                           GSList* sibling_data,
-                           gpointer parent_data,
-                           gpointer global_data,
-                           gpointer *result,
-                           const gchar *tag,
-                           const gchar *child_tag,
-                           sixtp_child_result *child_result)
+        GSList* data_from_children,
+        GSList* sibling_data,
+        gpointer parent_data,
+        gpointer global_data,
+        gpointer *result,
+        const gchar *tag,
+        const gchar *child_tag,
+        sixtp_child_result *child_result)
 {
-  CommodityLookupParseInfo *cpi =
-  (CommodityLookupParseInfo *) data_for_children;
+    CommodityLookupParseInfo *cpi =
+        (CommodityLookupParseInfo *) data_for_children;
 
-  g_return_val_if_fail(cpi, FALSE);
-  g_return_val_if_fail(child_result, FALSE);
-  if(child_result->type != SIXTP_CHILD_RESULT_NODE) return(FALSE);
+    g_return_val_if_fail(cpi, FALSE);
+    g_return_val_if_fail(child_result, FALSE);
+    if (child_result->type != SIXTP_CHILD_RESULT_NODE) return(FALSE);
 
-  if(strcmp(child_result->tag, "space") == 0) {
-    if(cpi->namespace) return(FALSE);
-    cpi->namespace = (gchar *) child_result->data;
-    child_result->should_cleanup = FALSE;
-  }
-  else if(strcmp(child_result->tag, "id") == 0) {
-    if(cpi->id) return(FALSE);
-    cpi->id = (gchar *) child_result->data;
-    child_result->should_cleanup = FALSE;
-  } else {
-    /* redundant because the parser won't allow any other children */
-    return(FALSE);
-  }
+    if (strcmp(child_result->tag, "space") == 0)
+    {
+        if (cpi->namespace) return(FALSE);
+        cpi->namespace = (gchar *) child_result->data;
+        child_result->should_cleanup = FALSE;
+    }
+    else if (strcmp(child_result->tag, "id") == 0)
+    {
+        if (cpi->id) return(FALSE);
+        cpi->id = (gchar *) child_result->data;
+        child_result->should_cleanup = FALSE;
+    }
+    else
+    {
+        /* redundant because the parser won't allow any other children */
+        return(FALSE);
+    }
 
-  return(TRUE);
+    return(TRUE);
 }
 
 static gboolean
 generic_gnc_commodity_lookup_end_handler(gpointer data_for_children,
-                                         GSList  *data_from_children, GSList *sibling_data,
-                                         gpointer parent_data, gpointer global_data,
-                                         gpointer *result, const gchar *tag)
+        GSList  *data_from_children, GSList *sibling_data,
+        gpointer parent_data, gpointer global_data,
+        gpointer *result, const gchar *tag)
 {
-  CommodityLookupParseInfo *cpi =
-  (CommodityLookupParseInfo *) data_for_children;
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  gboolean ok = FALSE;
+    CommodityLookupParseInfo *cpi =
+        (CommodityLookupParseInfo *) data_for_children;
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    gboolean ok = FALSE;
 
-  g_return_val_if_fail(cpi, FALSE);
+    g_return_val_if_fail(cpi, FALSE);
 
-  if(cpi->namespace && cpi->id) {
-    gnc_commodity_table *table;
-    gnc_commodity *com;
+    if (cpi->namespace && cpi->id)
+    {
+        gnc_commodity_table *table;
+        gnc_commodity *com;
 
-    table = gnc_book_get_commodity_table (pstatus->book);
+        table = gnc_book_get_commodity_table (pstatus->book);
 
-    com = gnc_commodity_table_lookup(table, cpi->namespace, cpi->id);
+        com = gnc_commodity_table_lookup(table, cpi->namespace, cpi->id);
 
-    if(com) {
-      *result = com;
-      ok = TRUE;
+        if (com)
+        {
+            *result = com;
+            ok = TRUE;
+        }
     }
-  }
 
-  g_free(cpi->namespace);
-  g_free(cpi->id);
-  g_free(cpi);
+    g_free(cpi->namespace);
+    g_free(cpi->id);
+    g_free(cpi);
 
-  return(ok);
+    return(ok);
 }
 
 
 static sixtp *
-generic_gnc_commodity_lookup_parser_new(void) 
+generic_gnc_commodity_lookup_parser_new(void)
 {
-  sixtp *top_level;
+    sixtp *top_level;
 
-  if(!(top_level = sixtp_set_any(
-           sixtp_new(), FALSE,
-           SIXTP_START_HANDLER_ID, generic_gnc_commodity_lookup_start_handler,
-           SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
-           SIXTP_END_HANDLER_ID, generic_gnc_commodity_lookup_end_handler,
-           SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children,
-           SIXTP_AFTER_CHILD_HANDLER_ID,
-           generic_gnc_commodity_lookup_after_child_handler,
-           SIXTP_NO_MORE_HANDLERS)))
-  {
-      return NULL;
-  }
+    if (!(top_level = sixtp_set_any(
+                          sixtp_new(), FALSE,
+                          SIXTP_START_HANDLER_ID, generic_gnc_commodity_lookup_start_handler,
+                          SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
+                          SIXTP_END_HANDLER_ID, generic_gnc_commodity_lookup_end_handler,
+                          SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children,
+                          SIXTP_AFTER_CHILD_HANDLER_ID,
+                          generic_gnc_commodity_lookup_after_child_handler,
+                          SIXTP_NO_MORE_HANDLERS)))
+    {
+        return NULL;
+    }
 
-  if(!sixtp_add_some_sub_parsers(
-         top_level, TRUE,
-         "space", simple_chars_only_parser_new(NULL),
-         "id", simple_chars_only_parser_new(NULL),
-         0))
-  {
-      return NULL;
-  }
+    if (!sixtp_add_some_sub_parsers(
+                top_level, TRUE,
+                "space", simple_chars_only_parser_new(NULL),
+                "id", simple_chars_only_parser_new(NULL),
+                0))
+    {
+        return NULL;
+    }
 
-  return(top_level);
+    return(top_level);
 }
 
 #if 0
@@ -2179,7 +2236,7 @@
                            const gchar *tag,
                            gchar **attrs)
 {
-  return(TRUE);
+    return(TRUE);
 }
 
 static gboolean
@@ -2188,25 +2245,25 @@
                          gpointer parent_data, gpointer global_data,
                          gpointer *result, const gchar *tag)
 {
-  Query *q;
-  sixtp_child_result *cr;
+    Query *q;
+    sixtp_child_result *cr;
 
-  g_return_val_if_fail(data_from_children, FALSE);
+    g_return_val_if_fail(data_from_children, FALSE);
 
-  cr = (sixtp_child_result *) data_from_children->data;
-  g_return_val_if_fail(cr, FALSE);
+    cr = (sixtp_child_result *) data_from_children->data;
+    g_return_val_if_fail(cr, FALSE);
 
-  q = (Query *) (cr->data);
-  g_return_val_if_fail(q, FALSE);
+    q = (Query *) (cr->data);
+    g_return_val_if_fail(q, FALSE);
 
-  *result = q;
-  return(TRUE);
+    *result = q;
+    return(TRUE);
 }
 
 
 /* ================================================================= */
 /* <query> (parent <query-server>)
- 
+
    This block does nothing.
    It generates no data of its own, so it doesn't need any cleanup.
 
@@ -2229,7 +2286,7 @@
                     gpointer global_data, gpointer *data_for_children,
                     gpointer *result, const gchar *tag, gchar **attrs)
 {
-  return(TRUE);
+    return(TRUE);
 }
 
 static gboolean
@@ -2238,28 +2295,28 @@
                   gpointer parent_data, gpointer global_data,
                   gpointer *result, const gchar *tag)
 {
-  Query *q;
-  sixtp_child_result *cr;
+    Query *q;
+    sixtp_child_result *cr;
 
-  g_return_val_if_fail(data_from_children, FALSE);
+    g_return_val_if_fail(data_from_children, FALSE);
 
-  cr = (sixtp_child_result *) data_from_children->data;
-  g_return_val_if_fail(cr, FALSE);
+    cr = (sixtp_child_result *) data_from_children->data;
+    g_return_val_if_fail(cr, FALSE);
 
-  q = (Query *) (cr->data);
-  g_return_val_if_fail(q, FALSE);
+    q = (Query *) (cr->data);
+    g_return_val_if_fail(q, FALSE);
 
-  *result = q;
-  return(TRUE);
+    *result = q;
+    return(TRUE);
 }
 
 /* ================================================================= */
 /* <restore> (lineage <query> <query-server>)
-   
+
    restores a given query.  We allocate the new query in the
    start block, the children modify it, and in the end block, we see
    if the resultant query is OK, and if so, we're done.
- 
+
    input: Query*
    to-children-via-*result: new Query*
    returns: NA
@@ -2279,12 +2336,12 @@
                             gpointer global_data, gpointer *data_for_children,
                             gpointer *result, const gchar *tag, gchar **attrs)
 {
-  Query *q;
-  q = xaccMallocQuery();
-  g_return_val_if_fail(q, FALSE);
-  *data_for_children = q;
-  *result = q;
-  return(q != NULL);
+    Query *q;
+    q = xaccMallocQuery();
+    g_return_val_if_fail(q, FALSE);
+    *data_for_children = q;
+    *result = q;
+    return(q != NULL);
 }
 
 static gboolean
@@ -2293,67 +2350,68 @@
                           gpointer parent_data, gpointer global_data,
                           gpointer *result, const gchar *tag)
 {
-  sixtp_child_result *cr;
-  Query *qand, *qret;
-  Query *q = (Query *) data_for_children;
-  g_return_val_if_fail(q, FALSE);
+    sixtp_child_result *cr;
+    Query *qand, *qret;
+    Query *q = (Query *) data_for_children;
+    g_return_val_if_fail(q, FALSE);
 
-  g_return_val_if_fail(data_from_children, FALSE);
-  cr = (sixtp_child_result *) data_from_children->data;
-  g_return_val_if_fail(cr, FALSE);
+    g_return_val_if_fail(data_from_children, FALSE);
+    cr = (sixtp_child_result *) data_from_children->data;
+    g_return_val_if_fail(cr, FALSE);
 
-  qand = (Query *) (cr->data);
-  g_return_val_if_fail(qand, FALSE);
+    qand = (Query *) (cr->data);
+    g_return_val_if_fail(qand, FALSE);
 
-  /* append the and terms by or'ing them in ... */
-  qret = xaccQueryMerge (q, qand, QUERY_OR);
-  if (!qret) {
+    /* append the and terms by or'ing them in ... */
+    qret = xaccQueryMerge (q, qand, QUERY_OR);
+    if (!qret)
+    {
+        xaccFreeQuery(qand);
+        *result = q;
+        g_return_val_if_fail(qret, FALSE);
+    }
+
+    xaccFreeQuery(q);
     xaccFreeQuery(qand);
-    *result = q;
-    g_return_val_if_fail(qret, FALSE);
-  }
 
-  xaccFreeQuery(q);
-  xaccFreeQuery(qand);
-
-  *result = qret;
-  return(TRUE);
+    *result = qret;
+    return(TRUE);
 }
 
 static gboolean
 query_restore_after_child_handler(gpointer data_for_children,
+                                  GSList* data_from_children,
+                                  GSList* sibling_data,
+                                  gpointer parent_data,
+                                  gpointer global_data,
+                                  gpointer *result,
+                                  const gchar *tag,
+                                  const gchar *child_tag,
+                                  sixtp_child_result *child_result)
+{
+    return(TRUE);
+}
+
+static void
+query_restore_fail_handler(gpointer data_for_children,
                            GSList* data_from_children,
                            GSList* sibling_data,
                            gpointer parent_data,
                            gpointer global_data,
                            gpointer *result,
-                           const gchar *tag,
-                           const gchar *child_tag,
-                           sixtp_child_result *child_result)
-{  
-  return(TRUE);
+                           const gchar *tag)
+{
+    Query *q = (Query *) data_for_children;
+    if (q) xaccFreeQuery(q);
 }
 
-static void
-query_restore_fail_handler(gpointer data_for_children,
-                         GSList* data_from_children,
-                         GSList* sibling_data,
-                         gpointer parent_data,
-                         gpointer global_data,
-                         gpointer *result,
-                         const gchar *tag)
-{  
-  Query *q = (Query *) data_for_children;
-  if (q) xaccFreeQuery(q);
-}
-
 /* ================================================================= */
 /* <and-terms> (lineage <restore> <query> <query-server>)
-   
+
    restores a given query.  We allocate the new query in the
    start block, the children modify it, and in the end block, we see
    if the resultant query is OK, and if so, we're done.
- 
+
    input: Query*
    to-children-via-*result: new Query*
    returns: NA
@@ -2373,14 +2431,14 @@
                         gpointer global_data, gpointer *data_for_children,
                         gpointer *result, const gchar *tag, gchar **attrs)
 {
-  Query *q;
+    Query *q;
 
-  /* note this malloc freed in the node higher up (query_restore_end_handler) */
-  q = xaccMallocQuery();
-  g_return_val_if_fail(q, FALSE);
-  *data_for_children = q;
-  *result = q;
-  return(q != NULL);
+    /* note this malloc freed in the node higher up (query_restore_end_handler) */
+    q = xaccMallocQuery();
+    g_return_val_if_fail(q, FALSE);
+    *data_for_children = q;
+    *result = q;
+    return(q != NULL);
 }
 
 static gboolean
@@ -2389,23 +2447,23 @@
                       gpointer parent_data, gpointer global_data,
                       gpointer *result, const gchar *tag)
 {
-  Query *q = (Query *) data_for_children;
-  g_return_val_if_fail(q, FALSE);
-  *result = q;
-  return(TRUE);
+    Query *q = (Query *) data_for_children;
+    g_return_val_if_fail(q, FALSE);
+    *result = q;
+    return(TRUE);
 }
 
 static void
 query_and_fail_handler(gpointer data_for_children,
-                         GSList* data_from_children,
-                         GSList* sibling_data,
-                         gpointer parent_data,
-                         gpointer global_data,
-                         gpointer *result,
-                         const gchar *tag)
-{  
-  Query *q = (Query *) data_for_children;
-  if (q) xaccFreeQuery(q);
+                       GSList* data_from_children,
+                       GSList* sibling_data,
+                       gpointer parent_data,
+                       gpointer global_data,
+                       gpointer *result,
+                       const gchar *tag)
+{
+    Query *q = (Query *) data_for_children;
+    if (q) xaccFreeQuery(q);
 }
 
 /* ================================================================= */
@@ -2445,21 +2503,21 @@
                                  gpointer parent_data, gpointer global_data,
                                  gpointer *result, const gchar *tag)
 {
-  Query *q = (Query *) parent_data;
-  PredicateData *dp = (PredicateData *) data_for_children;
+    Query *q = (Query *) parent_data;
+    PredicateData *dp = (PredicateData *) data_for_children;
 
-  g_return_val_if_fail(q, FALSE);
-  g_return_val_if_fail(dp, FALSE);
+    g_return_val_if_fail(q, FALSE);
+    g_return_val_if_fail(dp, FALSE);
 
-  xaccQueryAddPredicate (q, dp, QUERY_AND);
+    xaccQueryAddPredicate (q, dp, QUERY_AND);
 
-  return(TRUE);
+    return(TRUE);
 }
 
 /* ================================================================= */
 /* <datepred> (lineage <and-terms> <restore> <query> <query-server>)
-   Restores a given date predicate.  
- 
+   Restores a given date predicate.
+
    from parent: Query*
    for children: NA
    result: NA
@@ -2481,24 +2539,24 @@
                                 gpointer *result, const gchar *tag,
                                 gchar **attrs)
 {
-  DatePredicateData *dp = g_new0 (DatePredicateData, 1);
-  g_return_val_if_fail(dp, FALSE);
-  dp->type = PD_DATE;
-  dp->term_type = PR_DATE;
-  *data_for_children = dp;
-  return(TRUE);
+    DatePredicateData *dp = g_new0 (DatePredicateData, 1);
+    g_return_val_if_fail(dp, FALSE);
+    dp->type = PD_DATE;
+    dp->term_type = PR_DATE;
+    *data_for_children = dp;
+    return(TRUE);
 }
 
 static void
 qrestore_datepred_fail_handler(gpointer data_for_children,
-                         GSList* data_from_children,
-                         GSList* sibling_data,
-                         gpointer parent_data,
-                         gpointer global_data,
-                         gpointer *result,
-                         const gchar *tag)
+                               GSList* data_from_children,
+                               GSList* sibling_data,
+                               gpointer parent_data,
+                               gpointer global_data,
+                               gpointer *result,
+                               const gchar *tag)
 {
-  // g_free (data_for_children);
+    // g_free (data_for_children);
 }
 
 /* ================================================================= */
@@ -2514,9 +2572,9 @@
                                gpointer parent_data, gpointer global_data,
                                gpointer *result, const gchar *tag)
 {
-  DatePredicateData *dp = (DatePredicateData *) parent_data;
-  CVT_INT(dp->use_start);
-  return(TRUE);
+    DatePredicateData *dp = (DatePredicateData *) parent_data;
+    CVT_INT(dp->use_start);
+    return(TRUE);
 }
 
 static gboolean
@@ -2525,9 +2583,9 @@
                              gpointer parent_data, gpointer global_data,
                              gpointer *result, const gchar *tag)
 {
-  DatePredicateData *dp = (DatePredicateData *) parent_data;
-  CVT_INT(dp->use_end);
-  return(TRUE);
+    DatePredicateData *dp = (DatePredicateData *) parent_data;
+    CVT_INT(dp->use_end);
+    return(TRUE);
 }
 
 static gboolean
@@ -2536,9 +2594,9 @@
                                 gpointer parent_data, gpointer global_data,
                                 gpointer *result, const gchar *tag)
 {
-  DatePredicateData *dp = (DatePredicateData *) parent_data;
-  CVT_DATE (dp->start);
-  return(TRUE);
+    DatePredicateData *dp = (DatePredicateData *) parent_data;
+    CVT_DATE (dp->start);
+    return(TRUE);
 }
 
 static gboolean
@@ -2547,9 +2605,9 @@
                               gpointer parent_data, gpointer global_data,
                               gpointer *result, const gchar *tag)
 {
-  DatePredicateData *dp = (DatePredicateData *) parent_data;
-  CVT_DATE (dp->end);
-  return(TRUE);
+    DatePredicateData *dp = (DatePredicateData *) parent_data;
+    CVT_DATE (dp->end);
+    return(TRUE);
 }
 
 static gboolean
@@ -2558,9 +2616,9 @@
                                gpointer parent_data, gpointer global_data,
                                gpointer *result, const gchar *tag)
 {
-  PredicateData *dp = (PredicateData *) parent_data;
-  CVT_INT(dp->base.sense);
-  return(TRUE);
+    PredicateData *dp = (PredicateData *) parent_data;
+    CVT_INT(dp->base.sense);
+    return(TRUE);
 }
 
 static sixtp*
@@ -2577,103 +2635,103 @@
 qrestore_datepred_parser_new(void)
 {
     return sixtp_add_some_sub_parsers(
-        sixtp_new(), TRUE,
-        "sense", pred_parser_new(generic_pred_sense_end_handler),
-        "use-start", pred_parser_new(datepred_use_start_end_handler),
-        "use-end", pred_parser_new(datepred_use_end_end_handler),
-        "start-date",
-        generic_timespec_parser_new(datepred_start_date_end_handler),
-        "end-date", 
-        generic_timespec_parser_new(datepred_end_date_end_handler),
-        0);
+               sixtp_new(), TRUE,
+               "sense", pred_parser_new(generic_pred_sense_end_handler),
+               "use-start", pred_parser_new(datepred_use_start_end_handler),
+               "use-end", pred_parser_new(datepred_use_end_end_handler),
+               "start-date",
+               generic_timespec_parser_new(datepred_start_date_end_handler),
+               "end-date",
+               generic_timespec_parser_new(datepred_end_date_end_handler),
+               0);
 }
 
 static sixtp*
-query_server_parser_new (void) 
+query_server_parser_new (void)
 {
-  sixtp *top_level;
-  sixtp *query_pr;
-  sixtp *restore_pr;
-  sixtp *and_pr;
-  sixtp *date_pred_pr;
-  
-  /* <query_server> */
-  if(!(top_level =
-       sixtp_set_any(sixtp_new(), FALSE,
-                     SIXTP_START_HANDLER_ID, query_server_start_handler,
-                     SIXTP_CHARACTERS_HANDLER_ID,
-                     allow_and_ignore_only_whitespace,
-                     SIXTP_END_HANDLER_ID, query_server_end_handler,
-                     SIXTP_NO_MORE_HANDLERS)))
-  {
-      return NULL;
-  }
+    sixtp *top_level;
+    sixtp *query_pr;
+    sixtp *restore_pr;
+    sixtp *and_pr;
+    sixtp *date_pred_pr;
 
-  /* <query_server> <query> */
-  if(!(query_pr =
-       sixtp_set_any(sixtp_new(), FALSE,
-                     SIXTP_START_HANDLER_ID, query_start_handler,
-                     SIXTP_CHARACTERS_HANDLER_ID,
-                     allow_and_ignore_only_whitespace,
-                     SIXTP_END_HANDLER_ID, query_end_handler,
-                     SIXTP_NO_MORE_HANDLERS)))
-  {
-    sixtp_destroy(top_level);
-    return (NULL);
-  }
-  sixtp_add_sub_parser(top_level, "query", query_pr);
-  
-  /* <query> <restore> */
-  if(!(restore_pr = sixtp_set_any(
-           sixtp_new(), FALSE,
-           SIXTP_START_HANDLER_ID, query_restore_start_handler,
-           SIXTP_END_HANDLER_ID, query_restore_end_handler,
-           SIXTP_FAIL_HANDLER_ID, query_restore_fail_handler,
-           SIXTP_AFTER_CHILD_HANDLER_ID, query_restore_after_child_handler,
-           SIXTP_NO_MORE_HANDLERS)))
-  {
-      sixtp_destroy(top_level);
-      return(NULL);
-  }
-  sixtp_add_sub_parser(query_pr, "restore", restore_pr);
-  
-  /* <query> <restore> <and-terms> */
-  if(!(and_pr =
-       sixtp_set_any(sixtp_new(), FALSE,
-                     SIXTP_START_HANDLER_ID, query_and_start_handler,
-                     SIXTP_CHARACTERS_HANDLER_ID,
-                     allow_and_ignore_only_whitespace,
-                     SIXTP_END_HANDLER_ID, query_and_end_handler,
-                     SIXTP_FAIL_HANDLER_ID, query_and_fail_handler,
-                     SIXTP_NO_MORE_HANDLERS)))
-  {
-    sixtp_destroy(top_level);
-    return (NULL);
-  }
-  sixtp_add_sub_parser(restore_pr, "and-terms", and_pr);
+    /* <query_server> */
+    if (!(top_level =
+                sixtp_set_any(sixtp_new(), FALSE,
+                              SIXTP_START_HANDLER_ID, query_server_start_handler,
+                              SIXTP_CHARACTERS_HANDLER_ID,
+                              allow_and_ignore_only_whitespace,
+                              SIXTP_END_HANDLER_ID, query_server_end_handler,
+                              SIXTP_NO_MORE_HANDLERS)))
+    {
+        return NULL;
+    }
 
-  if(!(date_pred_pr =
-       sixtp_set_any(qrestore_datepred_parser_new(), FALSE,
-                     SIXTP_START_HANDLER_ID, qrestore_datepred_start_handler,
-                     SIXTP_CHARACTERS_HANDLER_ID,
-                     allow_and_ignore_only_whitespace,
-                     SIXTP_END_HANDLER_ID, qrestore_genericpred_end_handler,
-                     SIXTP_FAIL_HANDLER_ID, qrestore_datepred_fail_handler,
-                     SIXTP_NO_MORE_HANDLERS)))
-  {
-      sixtp_destroy(top_level);
-      return NULL;
-  }
-  sixtp_add_sub_parser(and_pr, "date-pred", date_pred_pr);
+    /* <query_server> <query> */
+    if (!(query_pr =
+                sixtp_set_any(sixtp_new(), FALSE,
+                              SIXTP_START_HANDLER_ID, query_start_handler,
+                              SIXTP_CHARACTERS_HANDLER_ID,
+                              allow_and_ignore_only_whitespace,
+                              SIXTP_END_HANDLER_ID, query_end_handler,
+                              SIXTP_NO_MORE_HANDLERS)))
+    {
+        sixtp_destroy(top_level);
+        return (NULL);
+    }
+    sixtp_add_sub_parser(top_level, "query", query_pr);
 
-  return(top_level);
+    /* <query> <restore> */
+    if (!(restore_pr = sixtp_set_any(
+                           sixtp_new(), FALSE,
+                           SIXTP_START_HANDLER_ID, query_restore_start_handler,
+                           SIXTP_END_HANDLER_ID, query_restore_end_handler,
+                           SIXTP_FAIL_HANDLER_ID, query_restore_fail_handler,
+                           SIXTP_AFTER_CHILD_HANDLER_ID, query_restore_after_child_handler,
+                           SIXTP_NO_MORE_HANDLERS)))
+    {
+        sixtp_destroy(top_level);
+        return(NULL);
+    }
+    sixtp_add_sub_parser(query_pr, "restore", restore_pr);
+
+    /* <query> <restore> <and-terms> */
+    if (!(and_pr =
+                sixtp_set_any(sixtp_new(), FALSE,
+                              SIXTP_START_HANDLER_ID, query_and_start_handler,
+                              SIXTP_CHARACTERS_HANDLER_ID,
+                              allow_and_ignore_only_whitespace,
+                              SIXTP_END_HANDLER_ID, query_and_end_handler,
+                              SIXTP_FAIL_HANDLER_ID, query_and_fail_handler,
+                              SIXTP_NO_MORE_HANDLERS)))
+    {
+        sixtp_destroy(top_level);
+        return (NULL);
+    }
+    sixtp_add_sub_parser(restore_pr, "and-terms", and_pr);
+
+    if (!(date_pred_pr =
+                sixtp_set_any(qrestore_datepred_parser_new(), FALSE,
+                              SIXTP_START_HANDLER_ID, qrestore_datepred_start_handler,
+                              SIXTP_CHARACTERS_HANDLER_ID,
+                              allow_and_ignore_only_whitespace,
+                              SIXTP_END_HANDLER_ID, qrestore_genericpred_end_handler,
+                              SIXTP_FAIL_HANDLER_ID, qrestore_datepred_fail_handler,
+                              SIXTP_NO_MORE_HANDLERS)))
+    {
+        sixtp_destroy(top_level);
+        return NULL;
+    }
+    sixtp_add_sub_parser(and_pr, "date-pred", date_pred_pr);
+
+    return(top_level);
 }
 #endif /* 0 */
 
 /***********************************************************************/
 /****************************************************************************/
 /* <transaction> (parent <ledger-data>)
- 
+
    This block does nothing but pass the ledger-data account group down
    to its children.  It generates no data of its own, so it doesn't
    need any cleanup.
@@ -2683,7 +2741,7 @@
    to-children-via-*result: Account*
 
    returns: NA
-   
+
    start: pass input to children.
 
    characters: ignore whitespace only
@@ -2707,25 +2765,25 @@
                           gpointer global_data, gpointer *data_for_children,
                           gpointer *result, const gchar *tag, gchar **attrs)
 {
-  /* pass the parent data down to the children */
-  *data_for_children = parent_data;
-  return(TRUE);
+    /* pass the parent data down to the children */
+    *data_for_children = parent_data;
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <restore> (lineage <transaction> <ledger-data>)
-   
+
    restores a given transaction.  We allocate the new transaction in
    the start block, the children modify it, and in the end block, we
    see if the resultant account is OK, and if so, we add it to the
    ledger-data's account group.
- 
+
    from parent: Account*
 
    for children: new Transaction*
 
    result: NA
-   
+
    -----------
 
    start: create new Transaction*, and store in data_for_children.
@@ -2751,15 +2809,15 @@
                           gpointer global_data, gpointer *data_for_children,
                           gpointer *result, const gchar *tag, gchar **attrs)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  Transaction *trans = xaccMallocTransaction(pstatus->book);
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    Transaction *trans = xaccMallocTransaction(pstatus->book);
 
-  g_return_val_if_fail(trans, FALSE);
+    g_return_val_if_fail(trans, FALSE);
 
-  xaccTransBeginEdit(trans);
-  *data_for_children = trans;
+    xaccTransBeginEdit(trans);
+    *data_for_children = trans;
 
-  return(TRUE);
+    return(TRUE);
 }
 
 static gboolean
@@ -2768,51 +2826,54 @@
                         gpointer parent_data, gpointer global_data,
                         gpointer *result, const gchar *tag)
 {
-  Account *parent = (Account *) parent_data;
-  Transaction *trans = (Transaction *) data_for_children;
+    Account *parent = (Account *) parent_data;
+    Transaction *trans = (Transaction *) data_for_children;
 
-  g_return_val_if_fail(trans, FALSE);
-  if (!parent) {
-    xaccTransDestroy(trans);
-    xaccTransCommitEdit(trans);
-    return(FALSE);
-  }
+    g_return_val_if_fail(trans, FALSE);
+    if (!parent)
+    {
+        xaccTransDestroy(trans);
+        xaccTransCommitEdit(trans);
+        return(FALSE);
+    }
 
-  if(!xaccTransGetGUID(trans)) {
-    /* must at least have a GUID for a restore */
-    xaccTransDestroy(trans);
+    if (!xaccTransGetGUID(trans))
+    {
+        /* must at least have a GUID for a restore */
+        xaccTransDestroy(trans);
+        xaccTransCommitEdit(trans);
+        return(FALSE);
+    }
+
+    /* FIXME: what if the trans has no splits? */
     xaccTransCommitEdit(trans);
-    return(FALSE);
-  }
-    
-  /* FIXME: what if the trans has no splits? */
-  xaccTransCommitEdit(trans);
 
-  return(TRUE);
+    return(TRUE);
 }
 
 static gboolean
 txn_restore_after_child_handler(gpointer data_for_children,
-                           GSList* data_from_children,
-                           GSList* sibling_data,
-                           gpointer parent_data,
-                           gpointer global_data,
-                           gpointer *result,
-                           const gchar *tag,
-                           const gchar *child_tag,
-                           sixtp_child_result *child_result)
+                                GSList* data_from_children,
+                                GSList* sibling_data,
+                                gpointer parent_data,
+                                gpointer global_data,
+                                gpointer *result,
+                                const gchar *tag,
+                                const gchar *child_tag,
+                                sixtp_child_result *child_result)
 {
-  Transaction *trans = (Transaction *) data_for_children;
-  g_return_val_if_fail(trans, FALSE);
-  if(!child_result) return(TRUE);
-  if(child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE);
-  if(strcmp(child_result->tag, "slots") == 0) {
-    kvp_frame *f = (kvp_frame *) child_result->data;
-    g_return_val_if_fail(f, FALSE);
-    qof_instance_set_slots(QOF_INSTANCE(trans),f);
-    child_result->should_cleanup = FALSE;
-  }
-  return(TRUE);
+    Transaction *trans = (Transaction *) data_for_children;
+    g_return_val_if_fail(trans, FALSE);
+    if (!child_result) return(TRUE);
+    if (child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE);
+    if (strcmp(child_result->tag, "slots") == 0)
+    {
+        kvp_frame *f = (kvp_frame *) child_result->data;
+        g_return_val_if_fail(f, FALSE);
+        qof_instance_set_slots(QOF_INSTANCE(trans), f);
+        child_result->should_cleanup = FALSE;
+    }
+    return(TRUE);
 }
 
 static void
@@ -2824,16 +2885,17 @@
                          gpointer *result,
                          const gchar *tag)
 {
-  Transaction *trans = (Transaction *) data_for_children;
-  if(trans) {
-    xaccTransDestroy(trans);
-    xaccTransCommitEdit(trans);
-  }
+    Transaction *trans = (Transaction *) data_for_children;
+    if (trans)
+    {
+        xaccTransDestroy(trans);
+        xaccTransCommitEdit(trans);
+    }
 }
 
 /****************************************************************************/
 /* <guid> (lineage <restore> <transaction>)
-   
+
    restores a given account's guid.
 
    from parent: Transaction*
@@ -2858,34 +2920,34 @@
                              gpointer parent_data, gpointer global_data,
                              gpointer *result, const gchar *tag)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  Transaction *t = (Transaction *) parent_data;
-  gchar *txt = NULL;
-  GUID gid;
-  gboolean ok;
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    Transaction *t = (Transaction *) parent_data;
+    gchar *txt = NULL;
+    GUID gid;
+    gboolean ok;
 
-  g_return_val_if_fail(t, FALSE);
+    g_return_val_if_fail(t, FALSE);
 
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  ok = string_to_guid(txt, &gid);
-  g_free(txt);
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
 
-  g_return_val_if_fail(ok, FALSE);
+    ok = string_to_guid(txt, &gid);
+    g_free(txt);
 
-  if(xaccTransLookup(&gid, pstatus->book)) 
-  {
-    return(FALSE);
-  }
+    g_return_val_if_fail(ok, FALSE);
 
-  xaccTransSetGUID(t, &gid);
-  return(TRUE);
+    if (xaccTransLookup(&gid, pstatus->book))
+    {
+        return(FALSE);
+    }
+
+    xaccTransSetGUID(t, &gid);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <num> (lineage <restore> <transaction>)
-   
+
    restores a given transaction's num.
 
    from parent: Transaction*
@@ -2910,22 +2972,22 @@
                             gpointer parent_data, gpointer global_data,
                             gpointer *result, const gchar *tag)
 {
-  Transaction *t = (Transaction *) parent_data;
-  gchar *txt = NULL;
-  
-  g_return_val_if_fail(t, FALSE);
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  xaccTransSetNum(t, txt);
-  g_free(txt);
-  return(TRUE);
+    Transaction *t = (Transaction *) parent_data;
+    gchar *txt = NULL;
+
+    g_return_val_if_fail(t, FALSE);
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    xaccTransSetNum(t, txt);
+    g_free(txt);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <description> (lineage <restore> <transaction>)
-   
+
    restores a given transaction's description.
 
    from parent: Transaction*
@@ -2950,22 +3012,22 @@
                                     gpointer parent_data, gpointer global_data,
                                     gpointer *result, const gchar *tag)
 {
-  Transaction *t = (Transaction *) parent_data;
-  gchar *txt = NULL;
-  
-  g_return_val_if_fail(t, FALSE);
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  xaccTransSetDescription(t, txt);
-  g_free(txt);
-  return(TRUE);
+    Transaction *t = (Transaction *) parent_data;
+    gchar *txt = NULL;
+
+    g_return_val_if_fail(t, FALSE);
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    xaccTransSetDescription(t, txt);
+    g_free(txt);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <date-posted> (lineage <restore> <transaction>)
-   
+
    restores a given transaction's posted date.
 
    Just uses a generic_timespec parser, but with our own end handler.
@@ -2980,23 +3042,24 @@
                                  gpointer parent_data, gpointer global_data,
                                  gpointer *result, const gchar *tag)
 {
-  Transaction *t = (Transaction *) parent_data;
-  TimespecParseInfo *info = (TimespecParseInfo *) data_for_children;
-  
-  g_return_val_if_fail(info, FALSE);
-  if(!t || !timespec_parse_ok(info)) {
+    Transaction *t = (Transaction *) parent_data;
+    TimespecParseInfo *info = (TimespecParseInfo *) data_for_children;
+
+    g_return_val_if_fail(info, FALSE);
+    if (!t || !timespec_parse_ok(info))
+    {
+        g_free(info);
+        return(FALSE);
+    }
+
+    xaccTransSetDatePostedTS(t, &(info->ts));
     g_free(info);
-    return(FALSE);
-  }
-
-  xaccTransSetDatePostedTS(t, &(info->ts));
-  g_free(info);
-  return(TRUE);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <date-entered> (lineage <restore> <transaction>)
-   
+
    restores a given transaction's entered date.
 
    Just uses a generic_timespec parser, but with our own end handler.
@@ -3011,18 +3074,19 @@
                                   gpointer parent_data, gpointer global_data,
                                   gpointer *result, const gchar *tag)
 {
-  Transaction *t = (Transaction *) parent_data;
-  TimespecParseInfo *info = (TimespecParseInfo *) data_for_children;
-  
-  g_return_val_if_fail(info, FALSE);
-  if(!t || !timespec_parse_ok(info)) {
+    Transaction *t = (Transaction *) parent_data;
+    TimespecParseInfo *info = (TimespecParseInfo *) data_for_children;
+
+    g_return_val_if_fail(info, FALSE);
+    if (!t || !timespec_parse_ok(info))
+    {
+        g_free(info);
+        return(FALSE);
+    }
+
+    xaccTransSetDateEnteredTS(t, &(info->ts));
     g_free(info);
-    return(FALSE);
-  }
-
-  xaccTransSetDateEnteredTS(t, &(info->ts));
-  g_free(info);
-  return(TRUE);
+    return(TRUE);
 }
 
 
@@ -3030,12 +3094,12 @@
 /****************************************************************************/
 
 /* <split> (lineage <restore> <transaction> <ledger-data>)
-   
+
    Restores a given split.  We allocate the new split in the start
    block, the children modify it, and in the end block, we see if the
    resultant split is OK, and if so, we add it to the input Transaction*
    account group.
- 
+
    from parent: Transaction*
    for children: new Split*
    result: NA
@@ -3057,11 +3121,11 @@
                                 gpointer *data_for_children, gpointer *result,
                                 const gchar *tag, gchar **attrs)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  Split *s = xaccMallocSplit(pstatus->book);
-  g_return_val_if_fail(s, FALSE);
-  *data_for_children = s;
-  return(TRUE);
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    Split *s = xaccMallocSplit(pstatus->book);
+    g_return_val_if_fail(s, FALSE);
+    *data_for_children = s;
+    return(TRUE);
 }
 
 static gboolean
@@ -3070,80 +3134,85 @@
                               gpointer parent_data, gpointer global_data,
                               gpointer *result, const gchar *tag)
 {
-  Transaction *t = (Transaction *) parent_data;
-  Split *s = (Split *) data_for_children;
+    Transaction *t = (Transaction *) parent_data;
+    Split *s = (Split *) data_for_children;
 
-  g_return_val_if_fail(s, FALSE);
-  if(!t) {
-    xaccSplitDestroy(s);
-    return(FALSE);
-  }
+    g_return_val_if_fail(s, FALSE);
+    if (!t)
+    {
+        xaccSplitDestroy(s);
+        return(FALSE);
+    }
 
-  if(!xaccSplitGetGUID(s)) {
-    /* must at least have a GUID for a restore */
-    xaccSplitDestroy(s);
-    return(FALSE);
-  }
-    
-  xaccTransAppendSplit(t, s);
-  return(TRUE);
+    if (!xaccSplitGetGUID(s))
+    {
+        /* must at least have a GUID for a restore */
+        xaccSplitDestroy(s);
+        return(FALSE);
+    }
+
+    xaccTransAppendSplit(t, s);
+    return(TRUE);
 }
 
 static gboolean
 txn_restore_split_after_child_handler(gpointer data_for_children,
-                           GSList* data_from_children,
-                           GSList* sibling_data,
-                           gpointer parent_data,
-                           gpointer global_data,
-                           gpointer *result,
-                           const gchar *tag,
-                           const gchar *child_tag,
-                           sixtp_child_result *child_result)
+                                      GSList* data_from_children,
+                                      GSList* sibling_data,
+                                      gpointer parent_data,
+                                      gpointer global_data,
+                                      gpointer *result,
+                                      const gchar *tag,
+                                      const gchar *child_tag,
+                                      sixtp_child_result *child_result)
 {
-  Split *s = (Split *) data_for_children;
-  g_return_val_if_fail(s, FALSE);
-  if(!child_result) return(TRUE);
-  if(child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE);
+    Split *s = (Split *) data_for_children;
+    g_return_val_if_fail(s, FALSE);
+    if (!child_result) return(TRUE);
+    if (child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE);
 
-  if(strcmp(child_result->tag, "slots") == 0) {
-    kvp_frame *f = (kvp_frame *) child_result->data;
-    g_return_val_if_fail(f, FALSE);
-    if(s->inst.kvp_data) kvp_frame_delete(s->inst.kvp_data);
-    s->inst.kvp_data = f;
-    child_result->should_cleanup = FALSE;
-  }
-  else if(strcmp(child_result->tag, "quantity") == 0) {
-    gnc_numeric *n = (gnc_numeric *) child_result->data;
-    g_return_val_if_fail(n, FALSE);
-    xaccSplitSetAmount(s, *n);
-    /* let the normal child_result handler clean up n */
-  }
-  else if(strcmp(child_result->tag, "value") == 0) {
-    gnc_numeric *n = (gnc_numeric *) child_result->data;
-    g_return_val_if_fail(n, FALSE);
-    xaccSplitSetValue(s, *n);
-    /* let the normal child_result handler clean up n */
-  }
+    if (strcmp(child_result->tag, "slots") == 0)
+    {
+        kvp_frame *f = (kvp_frame *) child_result->data;
+        g_return_val_if_fail(f, FALSE);
+        if (s->inst.kvp_data) kvp_frame_delete(s->inst.kvp_data);
+        s->inst.kvp_data = f;
+        child_result->should_cleanup = FALSE;
+    }
+    else if (strcmp(child_result->tag, "quantity") == 0)
+    {
+        gnc_numeric *n = (gnc_numeric *) child_result->data;
+        g_return_val_if_fail(n, FALSE);
+        xaccSplitSetAmount(s, *n);
+        /* let the normal child_result handler clean up n */
+    }
+    else if (strcmp(child_result->tag, "value") == 0)
+    {
+        gnc_numeric *n = (gnc_numeric *) child_result->data;
+        g_return_val_if_fail(n, FALSE);
+        xaccSplitSetValue(s, *n);
+        /* let the normal child_result handler clean up n */
+    }
 
-  return(TRUE);
+    return(TRUE);
 }
 
 static void
 txn_restore_split_fail_handler(gpointer data_for_children,
-                         GSList* data_from_children,
-                         GSList* sibling_data,
-                         gpointer parent_data,
-                         gpointer global_data,
-                         gpointer *result,
-                         const gchar *tag)
+                               GSList* data_from_children,
+                               GSList* sibling_data,
+                               gpointer parent_data,
+                               gpointer global_data,
+                               gpointer *result,
+                               const gchar *tag)
 {
-  Split *s = (Split *) data_for_children;
-  if(s) xaccSplitDestroy(s);
+    Split *s = (Split *) data_for_children;
+    if (s) xaccSplitDestroy(s);
 }
 
 /****************************************************************************/
 /* <guid> (lineage <split> <restore> <transaction>)
-   
+
    restores a given split's guid.
 
    from parent: Split*
@@ -3168,34 +3237,34 @@
                                    gpointer parent_data, gpointer global_data,
                                    gpointer *result, const gchar *tag)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  Split *s = (Split *) parent_data;
-  gchar *txt = NULL;
-  GUID gid;
-  gboolean ok;
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    Split *s = (Split *) parent_data;
+    gchar *txt = NULL;
+    GUID gid;
+    gboolean ok;
 
-  g_return_val_if_fail(s, FALSE);
+    g_return_val_if_fail(s, FALSE);
 
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  ok = string_to_guid(txt, &gid);
-  g_free(txt);
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
 
-  g_return_val_if_fail(ok, FALSE);
+    ok = string_to_guid(txt, &gid);
+    g_free(txt);
 
-  if(xaccSplitLookup(&gid, pstatus->book)) 
-  {
-    return(FALSE);
-  }
+    g_return_val_if_fail(ok, FALSE);
 
-  xaccSplitSetGUID(s, &gid);
-  return(TRUE);
+    if (xaccSplitLookup(&gid, pstatus->book))
+    {
+        return(FALSE);
+    }
+
+    xaccSplitSetGUID(s, &gid);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <memo> (lineage <split> <restore> <transaction>)
-   
+
    restores a given split's memo.
 
    from parent: Split*
@@ -3220,22 +3289,22 @@
                                    gpointer parent_data, gpointer global_data,
                                    gpointer *result, const gchar *tag)
 {
-  Split *s = (Split *) parent_data;
-  gchar *txt = NULL;
-  
-  g_return_val_if_fail(s, FALSE);
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  xaccSplitSetMemo(s, txt);
-  g_free(txt);
-  return(TRUE);
+    Split *s = (Split *) parent_data;
+    gchar *txt = NULL;
+
+    g_return_val_if_fail(s, FALSE);
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    xaccSplitSetMemo(s, txt);
+    g_free(txt);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <action> (lineage <split> <restore> <transaction>)
-   
+
    restores a given split's action.
 
    from parent: Split*
@@ -3260,22 +3329,22 @@
                                      gpointer parent_data, gpointer global_data,
                                      gpointer *result, const gchar *tag)
 {
-  Split *s = (Split *) parent_data;
-  gchar *txt = NULL;
-  
-  g_return_val_if_fail(s, FALSE);
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  xaccSplitSetAction(s, txt);
-  g_free(txt);
-  return(TRUE);
+    Split *s = (Split *) parent_data;
+    gchar *txt = NULL;
+
+    g_return_val_if_fail(s, FALSE);
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    xaccSplitSetAction(s, txt);
+    g_free(txt);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <reconcile-state> (lineage <split> <restore> <transaction>)
-   
+
    restores a given split's reconcile-state.
 
    from parent: Split*
@@ -3296,31 +3365,32 @@
 
 static gboolean
 txn_restore_split_reconcile_state_end_handler(gpointer data_for_children,
-                                              GSList  *data_from_children, GSList *sibling_data,
-                                              gpointer parent_data, gpointer global_data,
-                                              gpointer *result, const gchar *tag)
+        GSList  *data_from_children, GSList *sibling_data,
+        gpointer parent_data, gpointer global_data,
+        gpointer *result, const gchar *tag)
 {
-  Split *s = (Split *) parent_data;
-  gchar *txt = NULL;
-  
-  g_return_val_if_fail(s, FALSE);
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  if(strlen(txt) != 1) {
+    Split *s = (Split *) parent_data;
+    gchar *txt = NULL;
+
+    g_return_val_if_fail(s, FALSE);
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    if (strlen(txt) != 1)
+    {
+        g_free(txt);
+        return(FALSE);
+    }
+
+    xaccSplitSetReconcile(s, txt[0]);
     g_free(txt);
-    return(FALSE);
-  }
-
-  xaccSplitSetReconcile(s, txt[0]);
-  g_free(txt);
-  return(TRUE);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <reconcile-date> (lineage <split> <restore> <transaction>)
-   
+
    restores a given split's reconcile-date.
 
    Just uses a generic_timespec parser, but with our own end handler.
@@ -3331,27 +3401,28 @@
 
 static gboolean
 txn_restore_split_reconcile_date_end_handler(gpointer data_for_children,
-                                             GSList  *data_from_children, GSList *sibling_data,
-                                             gpointer parent_data, gpointer global_data,
-                                             gpointer *result, const gchar *tag)
+        GSList  *data_from_children, GSList *sibling_data,
+        gpointer parent_data, gpointer global_data,
+        gpointer *result, const gchar *tag)
 {
-  Split *s = (Split *) parent_data;
-  TimespecParseInfo *info = (TimespecParseInfo *) data_for_children;
-  
-  g_return_val_if_fail(info, FALSE);
-  if(!s || !timespec_parse_ok(info)) {
+    Split *s = (Split *) parent_data;
+    TimespecParseInfo *info = (TimespecParseInfo *) data_for_children;
+
+    g_return_val_if_fail(info, FALSE);
+    if (!s || !timespec_parse_ok(info))
+    {
+        g_free(info);
+        return(FALSE);
+    }
+
+    xaccSplitSetDateReconciledTS(s, &(info->ts));
     g_free(info);
-    return(FALSE);
-  }
-
-  xaccSplitSetDateReconciledTS(s, &(info->ts));
-  g_free(info);
-  return(TRUE);
+    return(TRUE);
 }
 
 /****************************************************************************/
 /* <account> (lineage <split> <restore> <transaction>)
-   
+
    restores a given split's account.
 
    from parent: Split*
@@ -3376,28 +3447,28 @@
                                       gpointer parent_data, gpointer global_data,
                                       gpointer *result, const gchar *tag)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  Split *s = (Split *) parent_data;
-  Account *acct;
-  gchar *txt = NULL;
-  GUID gid;
-  gboolean ok;
-  
-  g_return_val_if_fail(s, FALSE);
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  ok = string_to_guid(txt, &gid);
-  g_free(txt);
-  
-  g_return_val_if_fail(ok, FALSE);
-  
-  acct = xaccAccountLookup(&gid, pstatus->book);
-  g_return_val_if_fail(acct, FALSE);
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    Split *s = (Split *) parent_data;
+    Account *acct;
+    gchar *txt = NULL;
+    GUID gid;
+    gboolean ok;
 
-  xaccAccountInsertSplit(acct, s);
-  return(TRUE);
+    g_return_val_if_fail(s, FALSE);
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    ok = string_to_guid(txt, &gid);
+    g_free(txt);
+
+    g_return_val_if_fail(ok, FALSE);
+
+    acct = xaccAccountLookup(&gid, pstatus->book);
+    g_return_val_if_fail(acct, FALSE);
+
+    xaccAccountInsertSplit(acct, s);
+    return(TRUE);
 }
 
 
@@ -3407,102 +3478,102 @@
 /****************************************************************************/
 
 static sixtp *
-gnc_txn_restore_split_parser_new(void) 
+gnc_txn_restore_split_parser_new(void)
 {
-  sixtp *top_level;
-  
-  if(!(top_level =
-       sixtp_set_any(sixtp_new(), FALSE,
-                     SIXTP_START_HANDLER_ID, txn_restore_split_start_handler,
-                     SIXTP_CHARACTERS_HANDLER_ID,
-                     allow_and_ignore_only_whitespace,
-                     SIXTP_END_HANDLER_ID, txn_restore_split_end_handler,
-                     SIXTP_FAIL_HANDLER_ID, txn_restore_split_fail_handler,
-                     SIXTP_AFTER_CHILD_HANDLER_ID,
-                     txn_restore_split_after_child_handler,
-                     SIXTP_NO_MORE_HANDLERS)))
-  {
-      return NULL;
-  }
+    sixtp *top_level;
 
-  if(!sixtp_add_some_sub_parsers(
-         top_level, TRUE,
-         "guid", restore_char_generator(txn_restore_split_guid_end_handler),
-         "memo", restore_char_generator(txn_restore_split_memo_end_handler),
-         "action",
-         restore_char_generator(txn_restore_split_action_end_handler),
-         "account",
-         restore_char_generator(txn_restore_split_account_end_handler),
-         "reconcile-state",
-         restore_char_generator(txn_restore_split_reconcile_state_end_handler),
-         "reconcile-date", 
-         generic_timespec_parser_new(
-             txn_restore_split_reconcile_date_end_handler),
-         "quantity", generic_gnc_numeric_parser_new(),
-         "value", generic_gnc_numeric_parser_new(),
-         "slots", kvp_frame_parser_new(),
-         0))
-  {
-      return NULL;
-  }
+    if (!(top_level =
+                sixtp_set_any(sixtp_new(), FALSE,
+                              SIXTP_START_HANDLER_ID, txn_restore_split_start_handler,
+                              SIXTP_CHARACTERS_HANDLER_ID,
+                              allow_and_ignore_only_whitespace,
+                              SIXTP_END_HANDLER_ID, txn_restore_split_end_handler,
+                              SIXTP_FAIL_HANDLER_ID, txn_restore_split_fail_handler,
+                              SIXTP_AFTER_CHILD_HANDLER_ID,
+                              txn_restore_split_after_child_handler,
+                              SIXTP_NO_MORE_HANDLERS)))
+    {
+        return NULL;
+    }
 
-  return(top_level);
+    if (!sixtp_add_some_sub_parsers(
+                top_level, TRUE,
+                "guid", restore_char_generator(txn_restore_split_guid_end_handler),
+                "memo", restore_char_generator(txn_restore_split_memo_end_handler),
+                "action",
+                restore_char_generator(txn_restore_split_action_end_handler),
+                "account",
+                restore_char_generator(txn_restore_split_account_end_handler),
+                "reconcile-state",
+                restore_char_generator(txn_restore_split_reconcile_state_end_handler),
+                "reconcile-date",
+                generic_timespec_parser_new(
+                    txn_restore_split_reconcile_date_end_handler),
+                "quantity", generic_gnc_numeric_parser_new(),
+                "value", generic_gnc_numeric_parser_new(),
+                "slots", kvp_frame_parser_new(),
+                0))
+    {
+        return NULL;
+    }
+
+    return(top_level);
 }
 
 /***************************************************************************/
 
 static sixtp *
-gnc_transaction_parser_new(void) 
+gnc_transaction_parser_new(void)
 {
-  sixtp *top_level;
-  sixtp *restore_pr;
+    sixtp *top_level;
+    sixtp *restore_pr;
 
-  if(!(top_level =
-       sixtp_set_any(sixtp_new(), FALSE,
-                     SIXTP_START_HANDLER_ID, transaction_start_handler,
-                     SIXTP_CHARACTERS_HANDLER_ID,
-                     allow_and_ignore_only_whitespace,
-                     SIXTP_AFTER_CHILD_HANDLER_ID,
-                     txn_restore_after_child_handler,
-                     SIXTP_NO_MORE_HANDLERS)))
-  {
-      return NULL;
-  }
+    if (!(top_level =
+                sixtp_set_any(sixtp_new(), FALSE,
+                              SIXTP_START_HANDLER_ID, transaction_start_handler,
+                              SIXTP_CHARACTERS_HANDLER_ID,
+                              allow_and_ignore_only_whitespace,
+                              SIXTP_AFTER_CHILD_HANDLER_ID,
+                              txn_restore_after_child_handler,
+                              SIXTP_NO_MORE_HANDLERS)))
+    {
+        return NULL;
+    }
 
-  /* <restore> */
-  if(!(restore_pr =
-       sixtp_set_any(sixtp_new(), FALSE,
-                     SIXTP_START_HANDLER_ID, txn_restore_start_handler,
-                     SIXTP_END_HANDLER_ID, txn_restore_end_handler,
-                     SIXTP_FAIL_HANDLER_ID, txn_restore_fail_handler,
-                     SIXTP_AFTER_CHILD_HANDLER_ID,
-                     txn_restore_after_child_handler,
-                     SIXTP_NO_MORE_HANDLERS)))
-  {
-      sixtp_destroy(top_level);
-      return(NULL);
-  }
-  sixtp_add_sub_parser(top_level, "restore", restore_pr);
+    /* <restore> */
+    if (!(restore_pr =
+                sixtp_set_any(sixtp_new(), FALSE,
+                              SIXTP_START_HANDLER_ID, txn_restore_start_handler,
+                              SIXTP_END_HANDLER_ID, txn_restore_end_handler,
+                              SIXTP_FAIL_HANDLER_ID, txn_restore_fail_handler,
+                              SIXTP_AFTER_CHILD_HANDLER_ID,
+                              txn_restore_after_child_handler,
+                              SIXTP_NO_MORE_HANDLERS)))
+    {
+        sixtp_destroy(top_level);
+        return(NULL);
+    }
+    sixtp_add_sub_parser(top_level, "restore", restore_pr);
 
-  if(!(sixtp_add_some_sub_parsers(
-           restore_pr, TRUE,
-           "guid", restore_char_generator(txn_restore_guid_end_handler),
-           "num", restore_char_generator(txn_restore_num_end_handler),
-           "description",
-           restore_char_generator(txn_restore_description_end_handler),
-           "date-posted",
-           generic_timespec_parser_new(txn_rest_date_posted_end_handler),
-           "date-entered",
-           generic_timespec_parser_new(txn_rest_date_entered_end_handler),
-           "slots", kvp_frame_parser_new(),
-           "split", gnc_txn_restore_split_parser_new(),
-           0)))
-  {
-      sixtp_destroy(top_level);
-      return NULL;
-  }
+    if (!(sixtp_add_some_sub_parsers(
+                restore_pr, TRUE,
+                "guid", restore_char_generator(txn_restore_guid_end_handler),
+                "num", restore_char_generator(txn_restore_num_end_handler),
+                "description",
+                restore_char_generator(txn_restore_description_end_handler),
+                "date-posted",
+                generic_timespec_parser_new(txn_rest_date_posted_end_handler),
+                "date-entered",
+                generic_timespec_parser_new(txn_rest_date_entered_end_handler),
+                "slots", kvp_frame_parser_new(),
+                "split", gnc_txn_restore_split_parser_new(),
+                0)))
+    {
+        sixtp_destroy(top_level);
+        return NULL;
+    }
 
-  return(top_level);
+    return(top_level);
 }
 
 /****************************************************************************/
@@ -3549,52 +3620,65 @@
   Returns a GNCPrice * in result.
 
   Right now, a price is legitimate even if all of it's fields are not
-  set.  We may need to change that later, but at the moment.  
+  set.  We may need to change that later, but at the moment.
 
 */
 
 static gboolean
 price_parse_xml_sub_node(GNCPrice *p, xmlNodePtr sub_node, QofBook *book)
 {
-  if(!p || !sub_node) return FALSE;
+    if (!p || !sub_node) return FALSE;
 
-  gnc_price_begin_edit (p);
+    gnc_price_begin_edit (p);
 
-  if(safe_strcmp("price:id", (char*)sub_node->name) == 0) {
-    GUID *c = dom_tree_to_guid(sub_node);
-    if(!c) return FALSE; 
-    gnc_price_set_guid(p, c);
-    g_free(c);
-  } else if(safe_strcmp("price:commodity", (char*)sub_node->name) == 0) {
-    gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, book);
-    if(!c) return FALSE;
-    gnc_price_set_commodity(p, c);
-  } else if(safe_strcmp("price:currency", (char*)sub_node->name) == 0) {
-    gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, book);
-    if(!c) return FALSE;
-    gnc_price_set_currency(p, c);
-  } else if(safe_strcmp("price:time", (char*)sub_node->name) == 0) {
-    Timespec t = dom_tree_to_timespec(sub_node);
-    if (!dom_tree_valid_timespec(&t, sub_node->name)) return FALSE;
-    gnc_price_set_time(p, t);
-  } else if(safe_strcmp("price:source", (char*)sub_node->name) == 0) {
-    char *text = dom_tree_to_text(sub_node);
-    if(!text) return FALSE;
-    gnc_price_set_source(p, text);
-    g_free(text);
-  } else if(safe_strcmp("price:type", (char*)sub_node->name) == 0) {
-    char *text = dom_tree_to_text(sub_node);
-    if(!text) return FALSE;
-    gnc_price_set_typestr(p, text);
-    g_free(text);
-  } else if(safe_strcmp("price:value", (char*)sub_node->name) == 0) {
-    gnc_numeric *value = dom_tree_to_gnc_numeric(sub_node);
-    if(!value) return FALSE;
-    gnc_price_set_value(p, *value);
-    g_free(value);
-  }
-  gnc_price_commit_edit (p);
-  return TRUE;
+    if (safe_strcmp("price:id", (char*)sub_node->name) == 0)
+    {
+        GUID *c = dom_tree_to_guid(sub_node);
+        if (!c) return FALSE;
+        gnc_price_set_guid(p, c);
+        g_free(c);
+    }
+    else if (safe_strcmp("price:commodity", (char*)sub_node->name) == 0)
+    {
+        gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, book);
+        if (!c) return FALSE;
+        gnc_price_set_commodity(p, c);
+    }
+    else if (safe_strcmp("price:currency", (char*)sub_node->name) == 0)
+    {
+        gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, book);
+        if (!c) return FALSE;
+        gnc_price_set_currency(p, c);
+    }
+    else if (safe_strcmp("price:time", (char*)sub_node->name) == 0)
+    {
+        Timespec t = dom_tree_to_timespec(sub_node);
+        if (!dom_tree_valid_timespec(&t, sub_node->name)) return FALSE;
+        gnc_price_set_time(p, t);
+    }
+    else if (safe_strcmp("price:source", (char*)sub_node->name) == 0)
+    {
+        char *text = dom_tree_to_text(sub_node);
+        if (!text) return FALSE;
+        gnc_price_set_source(p, text);
+        g_free(text);
+    }
+    else if (safe_strcmp("price:type", (char*)sub_node->name) == 0)
+    {
+        char *text = dom_tree_to_text(sub_node);
+        if (!text) return FALSE;
+        gnc_price_set_typestr(p, text);
+        g_free(text);
+    }
+    else if (safe_strcmp("price:value", (char*)sub_node->name) == 0)
+    {
+        gnc_numeric *value = dom_tree_to_gnc_numeric(sub_node);
+        if (!value) return FALSE;
+        gnc_price_set_value(p, *value);
+        g_free(value);
+    }
+    gnc_price_commit_edit (p);
+    return TRUE;
 }
 
 static gboolean
@@ -3606,81 +3690,101 @@
                             gpointer *result,
                             const gchar *tag)
 {
-  gboolean ok = TRUE;
-  xmlNodePtr price_xml = (xmlNodePtr) data_for_children;
-  xmlNodePtr child;
-  GNCPrice *p = NULL;
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    gboolean ok = TRUE;
+    xmlNodePtr price_xml = (xmlNodePtr) data_for_children;
+    xmlNodePtr child;
+    GNCPrice *p = NULL;
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
 
-  /* we haven't been handed the *top* level node yet... */
-  if(parent_data) return TRUE;
+    /* we haven't been handed the *top* level node yet... */
+    if (parent_data) return TRUE;
 
-  *result = NULL;
+    *result = NULL;
 
-  if(!price_xml) return FALSE;
-  if(price_xml->next) { ok = FALSE; goto cleanup_and_exit; }
-  if(price_xml->prev) { ok = FALSE; goto cleanup_and_exit; }
-  if(!price_xml->xmlChildrenNode) { ok = FALSE; goto cleanup_and_exit; }
-  
-  p = gnc_price_create(pstatus->book);
-  if(!p) { ok = FALSE; goto cleanup_and_exit; }
-  
-  for(child = price_xml->xmlChildrenNode; child; child = child->next) 
-  {
-    switch(child->type) {
-      case XML_COMMENT_NODE:
-      case XML_TEXT_NODE:
-        break;
-      case XML_ELEMENT_NODE:
-        if(!price_parse_xml_sub_node(p, child, pstatus->book)) 
-        {
-          ok = FALSE;
-          goto cleanup_and_exit;
-        }
-        break;
-      default:
-        PERR("Unknown node type (%d) while parsing gnc-price xml.", child->type);
-        child = NULL;
+    if (!price_xml) return FALSE;
+    if (price_xml->next)
+    {
         ok = FALSE;
         goto cleanup_and_exit;
-        break;
     }
-  }
-  
- cleanup_and_exit:
-  if(ok) {
-    *result = p;
-  } else {
-    *result = NULL;
-    gnc_price_unref(p);
-  }
-  xmlFreeNode(price_xml);
-  return ok;
+    if (price_xml->prev)
+    {
+        ok = FALSE;
+        goto cleanup_and_exit;
+    }
+    if (!price_xml->xmlChildrenNode)
+    {
+        ok = FALSE;
+        goto cleanup_and_exit;
+    }
+
+    p = gnc_price_create(pstatus->book);
+    if (!p)
+    {
+        ok = FALSE;
+        goto cleanup_and_exit;
+    }
+
+    for (child = price_xml->xmlChildrenNode; child; child = child->next)
+    {
+        switch (child->type)
+        {
+        case XML_COMMENT_NODE:
+        case XML_TEXT_NODE:
+            break;
+        case XML_ELEMENT_NODE:
+            if (!price_parse_xml_sub_node(p, child, pstatus->book))
+            {
+                ok = FALSE;
+                goto cleanup_and_exit;
+            }
+            break;
+        default:
+            PERR("Unknown node type (%d) while parsing gnc-price xml.", child->type);
+            child = NULL;
+            ok = FALSE;
+            goto cleanup_and_exit;
+            break;
+        }
+    }
+
+cleanup_and_exit:
+    if (ok)
+    {
+        *result = p;
+    }
+    else
+    {
+        *result = NULL;
+        gnc_price_unref(p);
+    }
+    xmlFreeNode(price_xml);
+    return ok;
 }
 
 static void
 cleanup_gnc_price(sixtp_child_result *result)
 {
-  if(result->data) gnc_price_unref((GNCPrice *) result->data);
+    if (result->data) gnc_price_unref((GNCPrice *) result->data);
 }
 
 static sixtp *
 gnc_price_parser_new (void)
 {
-  return sixtp_dom_parser_new(price_parse_xml_end_handler,
-                              cleanup_gnc_price,
-                              cleanup_gnc_price);
+    return sixtp_dom_parser_new(price_parse_xml_end_handler,
+                                cleanup_gnc_price,
+                                cleanup_gnc_price);
 }
 
 
 /****************************************************************************/
 /* <pricedb> (lineage <ledger-data>)
-   
+
    restores a pricedb.  We allocate the new db in the start block, the
    children add to it, and it gets returned in result.  Note that the
    cleanup handler will destroy the pricedb, so the parent needs to
    stop that if desired.
- 
+
    result: GNCPriceDB*
 
    start: create new GNCPriceDB*, and leave in *data_for_children.
@@ -3698,11 +3802,11 @@
                       const gchar *tag,
                       gchar **attrs)
 {
-  GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  GNCPriceDB *db = gnc_book_get_pricedb(pstatus->book);
-  g_return_val_if_fail(db, FALSE);
-  *result = db;
-  return(TRUE);
+    GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
+    GNCPriceDB *db = gnc_book_get_pricedb(pstatus->book);
+    g_return_val_if_fail(db, FALSE);
+    *result = db;
+    return(TRUE);
 }
 
 static gboolean
@@ -3716,64 +3820,69 @@
                             const gchar *child_tag,
                             sixtp_child_result *child_result)
 {
-  GNCPriceDB *db = (GNCPriceDB *) *result;
+    GNCPriceDB *db = (GNCPriceDB *) * result;
 
-  g_return_val_if_fail(db, FALSE);
+    g_return_val_if_fail(db, FALSE);
 
-  /* right now children have to produce results :> */
-  if(!child_result) return(FALSE);
-  if(child_result->type != SIXTP_CHILD_RESULT_NODE) return(FALSE);
+    /* right now children have to produce results :> */
+    if (!child_result) return(FALSE);
+    if (child_result->type != SIXTP_CHILD_RESULT_NODE) return(FALSE);
 
-  if(strcmp(child_result->tag, "price") == 0) {
-    GNCPrice *p = (GNCPrice *) child_result->data;
+    if (strcmp(child_result->tag, "price") == 0)
+    {
+        GNCPrice *p = (GNCPrice *) child_result->data;
 
-    g_return_val_if_fail(p, FALSE);
-    gnc_pricedb_add_price(db, p);
-    return TRUE;
-  } else {
+        g_return_val_if_fail(p, FALSE);
+        gnc_pricedb_add_price(db, p);
+        return TRUE;
+    }
+    else
+    {
+        return FALSE;
+    }
     return FALSE;
-  }
-  return FALSE;
 }
 
 static void
 pricedb_cleanup_result_handler(sixtp_child_result *result)
 {
-  if(result->data) {
-    GNCPriceDB *db = (GNCPriceDB *) result->data;
-    if(db) gnc_pricedb_destroy(db);
-    result->data = NULL;
-  }
+    if (result->data)
+    {
+        GNCPriceDB *db = (GNCPriceDB *) result->data;
+        if (db) gnc_pricedb_destroy(db);
+        result->data = NULL;
+    }
 }
 
 static sixtp*
-gnc_pricedb_parser_new(void) 
+gnc_pricedb_parser_new(void)
 {
-  sixtp *top_level;
-  sixtp *price_parser;
+    sixtp *top_level;
+    sixtp *price_parser;
 
-  top_level = 
-    sixtp_set_any(sixtp_new(), TRUE,
-                  SIXTP_START_HANDLER_ID, pricedb_start_handler,
-                  SIXTP_AFTER_CHILD_HANDLER_ID, pricedb_after_child_handler,
-                  SIXTP_CHARACTERS_HANDLER_ID,
-                  allow_and_ignore_only_whitespace,
-                  SIXTP_RESULT_FAIL_ID, pricedb_cleanup_result_handler,
-                  SIXTP_CLEANUP_RESULT_ID, pricedb_cleanup_result_handler,
-                  SIXTP_NO_MORE_HANDLERS);
+    top_level =
+        sixtp_set_any(sixtp_new(), TRUE,
+                      SIXTP_START_HANDLER_ID, pricedb_start_handler,
+                      SIXTP_AFTER_CHILD_HANDLER_ID, pricedb_after_child_handler,
+                      SIXTP_CHARACTERS_HANDLER_ID,
+                      allow_and_ignore_only_whitespace,
+                      SIXTP_RESULT_FAIL_ID, pricedb_cleanup_result_handler,
+                      SIXTP_CLEANUP_RESULT_ID, pricedb_cleanup_result_handler,
+                      SIXTP_NO_MORE_HANDLERS);
 
-  if(!top_level) return NULL;
+    if (!top_level) return NULL;
 
-  price_parser = gnc_price_parser_new();
+    price_parser = gnc_price_parser_new();
 
-  if(!price_parser) {
-    sixtp_destroy(top_level);
-    return NULL;
-  }
+    if (!price_parser)
+    {
+        sixtp_destroy(top_level);
+        return NULL;
+    }
 
-  sixtp_add_sub_parser(top_level, "price", price_parser);
+    sixtp_add_sub_parser(top_level, "price", price_parser);
 
-  return top_level;
+    return top_level;
 }
 
 /* ======================= END OF FILE ============================== */

Modified: gnucash/trunk/src/backend/xml/io-gncxml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/io-gncxml-v2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/io-gncxml-v2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -61,22 +61,24 @@
 static GHashTable *threads = NULL;
 G_LOCK_DEFINE_STATIC(threads);
 
-typedef struct {
-  gint fd;
-  gchar *filename;
-  gchar *perms;
-  gboolean compress;
+typedef struct
+{
+    gint fd;
+    gchar *filename;
+    gchar *perms;
+    gboolean compress;
 } gz_thread_params_t;
 
 /* Callback structure */
-struct file_backend {
-  gboolean        ok;
-  gpointer        data;
-  sixtp_gdv2    * gd;
-  const char    * tag;
-  sixtp         * parser;
-  FILE          * out;
-  QofBook       * book;
+struct file_backend
+{
+    gboolean        ok;
+    gpointer        data;
+    sixtp_gdv2    * gd;
+    const char    * tag;
+    sixtp         * parser;
+    FILE          * out;
+    QofBook       * book;
 };
 
 #define GNC_V2_STRING "gnc-v2"
@@ -85,7 +87,7 @@
 void
 run_callback(sixtp_gdv2 *data, const char *type)
 {
-    if(data->countCallback)
+    if (data->countCallback)
     {
         data->countCallback(data, type);
     }
@@ -104,15 +106,15 @@
     int old_scu;
 
     if (scu_getter)
-      old_scu = scu_getter(act);
+        old_scu = scu_getter(act);
     else
-      old_scu = 0;
+        old_scu = 0;
 
-    if(!com)
+    if (!com)
     {
         return;
     }
-    
+
     gcom = gnc_commodity_table_lookup(tbl, gnc_commodity_get_namespace(com),
                                       gnc_commodity_get_mnemonic(com));
 
@@ -120,17 +122,17 @@
     {
         return;
     }
-    else if(!gcom)
+    else if (!gcom)
     {
         PWARN("unable to find global commodity for %s adding new",
-                  gnc_commodity_get_unique_name(com));
+              gnc_commodity_get_unique_name(com));
         gnc_commodity_table_insert(tbl, com);
     }
     else
     {
         setter(act, gcom);
         if (old_scu != 0 && scu_setter)
-          scu_setter(act, old_scu);
+            scu_setter(act, old_scu);
         gnc_commodity_destroy(com);
     }
 }
@@ -144,22 +146,22 @@
     gnc_commodity *gcom;
     gnc_commodity *com = getter(trans);
 
-    if(!com)
+    if (!com)
     {
         return;
     }
-    
+
     gcom = gnc_commodity_table_lookup(tbl, gnc_commodity_get_namespace(com),
                                       gnc_commodity_get_mnemonic(com));
 
-    if(gcom == com)
+    if (gcom == com)
     {
         return;
     }
-    else if(!gcom)
+    else if (!gcom)
     {
         PWARN("unable to find global commodity for %s adding new",
-                  gnc_commodity_get_unique_name(com));
+              gnc_commodity_get_unique_name(com));
         gnc_commodity_table_insert(tbl, com);
     }
     else
@@ -181,9 +183,9 @@
     table = gnc_book_get_commodity_table (data->book);
 
     clear_up_account_commodity(table, act,
-                                       DxaccAccountGetCurrency,
-                                       DxaccAccountSetCurrency,
-                                       NULL, NULL);
+                               DxaccAccountGetCurrency,
+                               DxaccAccountSetCurrency,
+                               NULL, NULL);
 
     clear_up_account_commodity(table, act,
                                xaccAccountGetCommodity,
@@ -198,15 +200,19 @@
      * account is of type ROOT.  If not, find or create a ROOT
      * account and make that the parent. */
     type = xaccAccountGetType(act);
-    if (type == ACCT_TYPE_ROOT) {
-      gnc_book_set_root_account(data->book, act);
-    } else {
-      parent = gnc_account_get_parent(act);
-      if (parent == NULL) {
-	root = gnc_book_get_root_account(data->book);
-	gnc_account_append_child(root, act);
-      }
+    if (type == ACCT_TYPE_ROOT)
+    {
+        gnc_book_set_root_account(data->book, act);
     }
+    else
+    {
+        parent = gnc_account_get_parent(act);
+        if (parent == NULL)
+        {
+            root = gnc_book_get_root_account(data->book);
+            gnc_account_append_child(root, act);
+        }
+    }
 
     data->counter.accounts_loaded++;
     run_callback(data, "account");
@@ -242,7 +248,7 @@
 add_transaction_local(sixtp_gdv2 *data, Transaction *trn)
 {
     gnc_commodity_table *table;
-    
+
     table = gnc_book_get_commodity_table (data->book);
 
     xaccTransBeginEdit (trn);
@@ -261,12 +267,12 @@
 static gboolean
 add_schedXaction_local(sixtp_gdv2 *data, SchedXaction *sx)
 {
-     SchedXactions *sxes;
-     sxes = gnc_book_get_schedxactions(data->book);
-     gnc_sxes_add_sx(sxes, sx);
-     data->counter.schedXactions_loaded++;
-     run_callback(data, "schedXactions");
-     return TRUE;
+    SchedXactions *sxes;
+    sxes = gnc_book_get_schedxactions(data->book);
+    gnc_sxes_add_sx(sxes, sx);
+    data->counter.schedXactions_loaded++;
+    run_callback(data, "schedXactions");
+    return TRUE;
 }
 
 static gboolean
@@ -283,15 +289,18 @@
     /* expect a struct of: */
     /* . template accounts. */
     /* . transactions in those accounts. */
-    for ( n = txd->accts; n; n = n->next ) {
-        if ( gnc_account_get_parent( (Account*)n->data ) == NULL ) {
+    for ( n = txd->accts; n; n = n->next )
+    {
+        if ( gnc_account_get_parent( (Account*)n->data ) == NULL )
+        {
             /* replace the gnc_book_init-created root account */
             gnc_book_set_template_root(book, (Account *)n->data);
         }
 
     }
 
-    for ( n = txd->transactions; n; n = n->next ) {
+    for ( n = txd->transactions; n; n = n->next )
+    {
         /* insert transactions into accounts */
         add_transaction_local( data, (Transaction*)n->data );
     }
@@ -309,19 +318,19 @@
 static void
 do_counter_cb (const char *type, gpointer data_p, gpointer be_data_p)
 {
-  GncXmlDataType_t *data = data_p;
-  struct file_backend *be_data = be_data_p;
+    GncXmlDataType_t *data = data_p;
+    struct file_backend *be_data = be_data_p;
 
-  g_return_if_fail (type && data && be_data);
-  g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
+    g_return_if_fail (type && data && be_data);
+    g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
 
-  if (be_data->ok == TRUE)
-    return;
+    if (be_data->ok == TRUE)
+        return;
 
-  if (!safe_strcmp (be_data->tag, data->type_name))
-    be_data->ok = TRUE;
+    if (!safe_strcmp (be_data->tag, data->type_name))
+        be_data->ok = TRUE;
 
-  /* XXX: should we do anything with this counter? */
+    /* XXX: should we do anything with this counter? */
 }
 
 static gboolean
@@ -337,7 +346,7 @@
     gxpf_data *gdata = (gxpf_data*)global_data;
     sixtp_gdv2 *sixdata = (sixtp_gdv2*)gdata->parsedata;
     gboolean ret = TRUE;
-    
+
     if (parent_data)
         return TRUE;
 
@@ -345,7 +354,7 @@
        NULL tag.  So we ignore those cases */
     if (!tag)
         return TRUE;
-    
+
     g_return_val_if_fail(tree, FALSE);
 
     /* Note: BADXML.
@@ -357,7 +366,7 @@
     if (!string_to_gint64(strval, &val))
     {
         PERR ("string_to_gint64 failed with input: %s",
-                  strval ? strval : "(null)");
+              strval ? strval : "(null)");
         ret = FALSE;
     }
     else if (safe_strcmp(type, "transaction") == 0)
@@ -386,24 +395,24 @@
     }
     else
     {
-      struct file_backend be_data;
+        struct file_backend be_data;
 
-      be_data.ok = FALSE;
-      be_data.tag = type;
+        be_data.ok = FALSE;
+        be_data.tag = type;
 
-      qof_object_foreach_backend (GNC_FILE_BACKEND, do_counter_cb, &be_data);
+        qof_object_foreach_backend (GNC_FILE_BACKEND, do_counter_cb, &be_data);
 
-      if (be_data.ok == FALSE)
-      {
-        PERR("Unknown type: %s", type ? type : "(null)");
-	/* Do *NOT* flag this as an error. Gnucash 1.8 writes invalid
-	 * xml by writing the 'cd:type' attribute without providing
-	 * the namespace in the gnc:count-data tag.  The parser is
-	 * entirely within its rights to refuse to read this bad
-	 * attribute. Gnucash will function correctly without the data
-	 * in this tag, so just let the error pass. */
-        ret = TRUE;
-      }
+        if (be_data.ok == FALSE)
+        {
+            PERR("Unknown type: %s", type ? type : "(null)");
+            /* Do *NOT* flag this as an error. Gnucash 1.8 writes invalid
+             * xml by writing the 'cd:type' attribute without providing
+             * the namespace in the gnc:count-data tag.  The parser is
+             * entirely within its rights to refuse to read this bad
+             * attribute. Gnucash will function correctly without the data
+             * in this tag, so just let the error pass. */
+            ret = TRUE;
+        }
     }
 
     g_free (strval);
@@ -415,7 +424,7 @@
 static sixtp*
 gnc_counter_sixtp_parser_create(void)
 {
-     return sixtp_dom_parser_new(gnc_counter_end_handler, NULL, NULL);
+    return sixtp_dom_parser_new(gnc_counter_end_handler, NULL, NULL);
 }
 
 static void
@@ -443,22 +452,23 @@
 
     g_assert(gd != NULL);
     if (!gd->gui_display_fn)
-      return;
+        return;
 
     counter = &gd->counter;
     loaded = counter->transactions_loaded + counter->accounts_loaded +
-      counter->books_loaded + counter->commodities_loaded +
-      counter->schedXactions_loaded + counter->budgets_loaded;
+             counter->books_loaded + counter->commodities_loaded +
+             counter->schedXactions_loaded + counter->budgets_loaded;
     total = counter->transactions_total + counter->accounts_total +
-      counter->books_total + counter->commodities_total +
-      counter->schedXactions_total + counter->budgets_total;
+            counter->books_total + counter->commodities_total +
+            counter->schedXactions_total + counter->budgets_total;
     if (total == 0)
-      total = 1;
+        total = 1;
 
-    percentage = (loaded * 100)/total;
-    if (percentage > 100) {
-      /* FIXME: Perhaps the below should be replaced by:
-	 print_counter_data(counter); */
+    percentage = (loaded * 100) / total;
+    if (percentage > 100)
+    {
+        /* FIXME: Perhaps the below should be replaced by:
+        print_counter_data(counter); */
 //      printf("Transactions: Total: %d, Loaded: %d\n",
 //             counter->transactions_total, counter->transactions_loaded);
 //      printf("Accounts: Total: %d, Loaded: %d\n",
@@ -490,21 +500,22 @@
 static void
 add_item_cb (const char *type, gpointer data_p, gpointer be_data_p)
 {
-  GncXmlDataType_t *data = data_p;
-  struct file_backend *be_data = be_data_p;
+    GncXmlDataType_t *data = data_p;
+    struct file_backend *be_data = be_data_p;
 
-  g_return_if_fail (type && data && be_data);
-  g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
+    g_return_if_fail (type && data && be_data);
+    g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
 
-  if (be_data->ok)
-    return;
+    if (be_data->ok)
+        return;
 
-  if (!safe_strcmp (be_data->tag, data->type_name)) {
-    if (data->add_item)
-      (data->add_item)(be_data->gd, be_data->data);
+    if (!safe_strcmp (be_data->tag, data->type_name))
+    {
+        if (data->add_item)
+            (data->add_item)(be_data->gd, be_data->data);
 
-    be_data->ok = TRUE;
-  }
+        be_data->ok = TRUE;
+    }
 }
 
 static gboolean
@@ -512,49 +523,49 @@
 {
     sixtp_gdv2 *gd = (sixtp_gdv2*)globaldata;
 
-    if(safe_strcmp(tag, ACCOUNT_TAG) == 0)
+    if (safe_strcmp(tag, ACCOUNT_TAG) == 0)
     {
         add_account_local(gd, (Account*)data);
     }
-    else if(safe_strcmp(tag, PRICEDB_TAG) == 0)
+    else if (safe_strcmp(tag, PRICEDB_TAG) == 0)
     {
         add_pricedb_local(gd, (GNCPriceDB*)data);
     }
-    else if(safe_strcmp(tag, COMMODITY_TAG) == 0)
+    else if (safe_strcmp(tag, COMMODITY_TAG) == 0)
     {
         add_commodity_local(gd, (gnc_commodity*)data);
     }
-    else if(safe_strcmp(tag, TRANSACTION_TAG) == 0)
+    else if (safe_strcmp(tag, TRANSACTION_TAG) == 0)
     {
         add_transaction_local(gd, (Transaction*)data);
     }
-    else if(safe_strcmp(tag, SCHEDXACTION_TAG) == 0)
+    else if (safe_strcmp(tag, SCHEDXACTION_TAG) == 0)
     {
         add_schedXaction_local(gd, (SchedXaction*)data);
     }
-    else if(safe_strcmp(tag, TEMPLATE_TRANSACTION_TAG) == 0)
+    else if (safe_strcmp(tag, TEMPLATE_TRANSACTION_TAG) == 0)
     {
         add_template_transaction_local( gd, (gnc_template_xaction_data*)data );
     }
-    else if(safe_strcmp(tag, BUDGET_TAG) == 0)
+    else if (safe_strcmp(tag, BUDGET_TAG) == 0)
     {
         // Nothing needed here.
     }
     else
     {
-      struct file_backend be_data;
+        struct file_backend be_data;
 
-      be_data.ok = FALSE;
-      be_data.tag = tag;
-      be_data.gd = gd;
-      be_data.data = data;
+        be_data.ok = FALSE;
+        be_data.tag = tag;
+        be_data.gd = gd;
+        be_data.data = data;
 
-      qof_object_foreach_backend (GNC_FILE_BACKEND, add_item_cb, &be_data);
+        qof_object_foreach_backend (GNC_FILE_BACKEND, add_item_cb, &be_data);
 
-      if (be_data.ok == FALSE)
-      {
-        PWARN ("unexpected tag %s", tag);
-      }
+        if (be_data.ok == FALSE)
+        {
+            PWARN ("unexpected tag %s", tag);
+        }
     }
     return TRUE;
 }
@@ -564,7 +575,7 @@
 {
     sixtp_gdv2 *gd = (sixtp_gdv2*)globaldata;
 
-    if(safe_strcmp(tag, BOOK_TAG) == 0)
+    if (safe_strcmp(tag, BOOK_TAG) == 0)
     {
         add_book_local(gd, (QofBook*)data);
         book_callback(tag, globaldata, data);
@@ -580,34 +591,34 @@
 static void
 add_parser_cb (const char *type, gpointer data_p, gpointer be_data_p)
 {
-  GncXmlDataType_t *data = data_p;
-  struct file_backend *be_data = be_data_p;
+    GncXmlDataType_t *data = data_p;
+    struct file_backend *be_data = be_data_p;
 
-  g_return_if_fail (type && data && be_data);
-  g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
+    g_return_if_fail (type && data && be_data);
+    g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
 
-  if (be_data->ok == FALSE)
-    return;
+    if (be_data->ok == FALSE)
+        return;
 
-  if (data->create_parser)
-    if(!sixtp_add_some_sub_parsers(
-           be_data->parser, TRUE,
-           data->type_name, (data->create_parser)(),
-           NULL, NULL))
-      be_data->ok = FALSE;
+    if (data->create_parser)
+        if (!sixtp_add_some_sub_parsers(
+                    be_data->parser, TRUE,
+                    data->type_name, (data->create_parser)(),
+                    NULL, NULL))
+            be_data->ok = FALSE;
 }
 
 static void
 scrub_cb (const char *type, gpointer data_p, gpointer be_data_p)
 {
-  GncXmlDataType_t *data = data_p;
-  struct file_backend *be_data = be_data_p;
+    GncXmlDataType_t *data = data_p;
+    struct file_backend *be_data = be_data_p;
 
-  g_return_if_fail (type && data && be_data);
-  g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
+    g_return_if_fail (type && data && be_data);
+    g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
 
-  if (data->scrub)
-    (data->scrub)(be_data->book);
+    if (data->scrub)
+        (data->scrub)(be_data->book);
 }
 
 static sixtp_gdv2 *
@@ -662,46 +673,46 @@
     main_parser = sixtp_new();
     book_parser = sixtp_new();
 
-    if(!sixtp_add_some_sub_parsers(
-        top_parser, TRUE,
-        GNC_V2_STRING, main_parser,
-        NULL, NULL))
+    if (!sixtp_add_some_sub_parsers(
+                top_parser, TRUE,
+                GNC_V2_STRING, main_parser,
+                NULL, NULL))
     {
         goto bail;
     }
 
-    if(!sixtp_add_some_sub_parsers(
-           main_parser, TRUE,
-           COUNT_DATA_TAG, gnc_counter_sixtp_parser_create(),
-           BOOK_TAG, book_parser,
+    if (!sixtp_add_some_sub_parsers(
+                main_parser, TRUE,
+                COUNT_DATA_TAG, gnc_counter_sixtp_parser_create(),
+                BOOK_TAG, book_parser,
 
-           /* the following are present here only to support 
-            * the older, pre-book format.  Basically, the top-level 
-            * book is implicit. */
-           PRICEDB_TAG, gnc_pricedb_sixtp_parser_create(),
-           COMMODITY_TAG, gnc_commodity_sixtp_parser_create(),
-           ACCOUNT_TAG, gnc_account_sixtp_parser_create(),
-           TRANSACTION_TAG, gnc_transaction_sixtp_parser_create(),
-           SCHEDXACTION_TAG, gnc_schedXaction_sixtp_parser_create(),
-           TEMPLATE_TRANSACTION_TAG, gnc_template_transaction_sixtp_parser_create(),
-           NULL, NULL))
+                /* the following are present here only to support
+                 * the older, pre-book format.  Basically, the top-level
+                 * book is implicit. */
+                PRICEDB_TAG, gnc_pricedb_sixtp_parser_create(),
+                COMMODITY_TAG, gnc_commodity_sixtp_parser_create(),
+                ACCOUNT_TAG, gnc_account_sixtp_parser_create(),
+                TRANSACTION_TAG, gnc_transaction_sixtp_parser_create(),
+                SCHEDXACTION_TAG, gnc_schedXaction_sixtp_parser_create(),
+                TEMPLATE_TRANSACTION_TAG, gnc_template_transaction_sixtp_parser_create(),
+                NULL, NULL))
     {
         goto bail;
     }
 
-    if(!sixtp_add_some_sub_parsers(
-           book_parser, TRUE,
-           BOOK_ID_TAG, gnc_book_id_sixtp_parser_create(),
-           BOOK_SLOTS_TAG, gnc_book_slots_sixtp_parser_create(),
-           COUNT_DATA_TAG, gnc_counter_sixtp_parser_create(),
-           PRICEDB_TAG, gnc_pricedb_sixtp_parser_create(),
-           COMMODITY_TAG, gnc_commodity_sixtp_parser_create(),
-           ACCOUNT_TAG, gnc_account_sixtp_parser_create(),
-           BUDGET_TAG, gnc_budget_sixtp_parser_create(),
-           TRANSACTION_TAG, gnc_transaction_sixtp_parser_create(),
-           SCHEDXACTION_TAG, gnc_schedXaction_sixtp_parser_create(),
-           TEMPLATE_TRANSACTION_TAG, gnc_template_transaction_sixtp_parser_create(),
-           NULL, NULL))
+    if (!sixtp_add_some_sub_parsers(
+                book_parser, TRUE,
+                BOOK_ID_TAG, gnc_book_id_sixtp_parser_create(),
+                BOOK_SLOTS_TAG, gnc_book_slots_sixtp_parser_create(),
+                COUNT_DATA_TAG, gnc_counter_sixtp_parser_create(),
+                PRICEDB_TAG, gnc_pricedb_sixtp_parser_create(),
+                COMMODITY_TAG, gnc_commodity_sixtp_parser_create(),
+                ACCOUNT_TAG, gnc_account_sixtp_parser_create(),
+                BUDGET_TAG, gnc_budget_sixtp_parser_create(),
+                TRANSACTION_TAG, gnc_transaction_sixtp_parser_create(),
+                SCHEDXACTION_TAG, gnc_schedXaction_sixtp_parser_create(),
+                TEMPLATE_TRANSACTION_TAG, gnc_template_transaction_sixtp_parser_create(),
+                NULL, NULL))
     {
         goto bail;
     }
@@ -710,13 +721,14 @@
     be_data.parser = book_parser;
     qof_object_foreach_backend (GNC_FILE_BACKEND, add_parser_cb, &be_data);
     if (be_data.ok == FALSE)
-      goto bail;
+        goto bail;
 
     /* stop logging while we load */
     xaccLogDisable ();
     xaccDisableDataScrubbing();
 
-    if (push_handler) {
+    if (push_handler)
+    {
         gpointer parse_result = NULL;
         gxpf_data gpdata;
 
@@ -726,12 +738,15 @@
 
         retval = sixtp_parse_push(top_parser, push_handler, push_user_data,
                                   NULL, &gpdata, &parse_result);
-    } else {
+    }
+    else
+    {
         retval = gnc_xml_parse_file(top_parser, fbe->fullpath,
                                     generic_callback, gd, book);
     }
 
-    if (!retval) {
+    if (!retval)
+    {
         sixtp_destroy(top_parser);
         xaccLogEnable ();
         xaccEnableDataScrubbing();
@@ -767,15 +782,15 @@
      * account_end_handler finished reading the account.
      */
     gnc_account_foreach_descendant(root,
-				   (AccountCb) xaccAccountCommitEdit,
-				   NULL);
+                                   (AccountCb) xaccAccountCommitEdit,
+                                   NULL);
 
     /* start logging again */
     xaccLogEnable ();
 
     return TRUE;
 
- bail:
+bail:
     g_free(gd);
     return FALSE;
 }
@@ -797,39 +812,39 @@
     va_start(ap, out);
     type = va_arg(ap, char *);
 
-    while(type)
+    while (type)
     {
         int amount = va_arg(ap, int);
 
-        if(amount != 0)
+        if (amount != 0)
         {
 #if GNUCASH_REALLY_BUILD_AN_XML_TREE_ON_OUTPUT
-	    char *val;
-	    xmlNodePtr node;
+            char *val;
+            xmlNodePtr node;
 
             val = g_strdup_printf("%d", amount);
 
             node = xmlNewNode(NULL, BAD_CAST COUNT_DATA_TAG);
-	    /* Note: BADXML.
-	     *
-	     * This is invalid xml because the namespace isn't
-	     * declared in the tag itself. This should be changed to
-	     * 'type' at some point. */
+            /* Note: BADXML.
+             *
+             * This is invalid xml because the namespace isn't
+             * declared in the tag itself. This should be changed to
+             * 'type' at some point. */
             xmlSetProp(node, BAD_CAST "cd:type", BAD_CAST type);
             xmlNodeAddContent(node, BAD_CAST val);
 
             xmlElemDump(out, NULL, node);
             fprintf(out, "\n");
-        
+
             g_free(val);
             xmlFreeNode(node);
 #else
             fprintf(out, "<%s %s=\"%s\">%d</%s>\n",
-		    COUNT_DATA_TAG, "cd:type", type, amount, COUNT_DATA_TAG);
+                    COUNT_DATA_TAG, "cd:type", type, amount, COUNT_DATA_TAG);
 #endif
-        
+
         }
-        
+
         type = va_arg(ap, char *);
     }
 
@@ -839,18 +854,18 @@
 static gint
 compare_namespaces(gconstpointer a, gconstpointer b)
 {
-  const gchar *sa = (const gchar *) a;
-  const gchar *sb = (const gchar *) b;
-  return(safe_strcmp(sa, sb));
+    const gchar *sa = (const gchar *) a;
+    const gchar *sb = (const gchar *) b;
+    return(safe_strcmp(sa, sb));
 }
 
 static gint
 compare_commodity_ids(gconstpointer a, gconstpointer b)
 {
-  const gnc_commodity *ca = (const gnc_commodity *) a;
-  const gnc_commodity *cb = (const gnc_commodity *) b;
-  return(safe_strcmp(gnc_commodity_get_mnemonic(ca),
-                     gnc_commodity_get_mnemonic(cb)));
+    const gnc_commodity *ca = (const gnc_commodity *) a;
+    const gnc_commodity *cb = (const gnc_commodity *) b;
+    return(safe_strcmp(gnc_commodity_get_mnemonic(ca),
+                       gnc_commodity_get_mnemonic(cb)));
 }
 
 static void write_pricedb (FILE *out, QofBook *book, sixtp_gdv2 *gd);
@@ -862,29 +877,29 @@
 static void
 write_counts_cb (const char *type, gpointer data_p, gpointer be_data_p)
 {
-  GncXmlDataType_t *data = data_p;
-  struct file_backend *be_data = be_data_p;
+    GncXmlDataType_t *data = data_p;
+    struct file_backend *be_data = be_data_p;
 
-  g_return_if_fail (type && data && be_data);
-  g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
+    g_return_if_fail (type && data && be_data);
+    g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
 
-  if (data->get_count)
-    write_counts (be_data->out, data->type_name,
-                  (data->get_count) (be_data->book),
-                  NULL);
+    if (data->get_count)
+        write_counts (be_data->out, data->type_name,
+                      (data->get_count) (be_data->book),
+                      NULL);
 }
 
 static void
 write_data_cb (const char *type, gpointer data_p, gpointer be_data_p)
 {
-  GncXmlDataType_t *data = data_p;
-  struct file_backend *be_data = be_data_p;
+    GncXmlDataType_t *data = data_p;
+    struct file_backend *be_data = be_data_p;
 
-  g_return_if_fail (type && data && be_data);
-  g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
+    g_return_if_fail (type && data && be_data);
+    g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
 
-  if (data->write)
-    (data->write)(be_data->out, be_data->book);
+    if (data->write)
+        (data->write)(be_data->out, be_data->book);
 }
 
 static void
@@ -896,23 +911,23 @@
     /* We can't just blast out the dom tree, because the dom tree
      * doesn't have the books, transactions, etc underneath it.
      * But that is just as well, since I think the performance
-     * will be much better if we write out as we go along 
+     * will be much better if we write out as we go along
      */
     xmlNodePtr node;
 
     node = gnc_book_dom_tree_create(book);
 
-    if(!node)
+    if (!node)
     {
         return;
     }
-    
+
     xmlElemDump(out, NULL, node);
-    if(fprintf(out, "\n") < 0)
-	{
-		qof_backend_set_error(qof_book_get_backend(book), ERR_FILEIO_WRITE_ERROR);
-		return;
-	}
+    if (fprintf(out, "\n") < 0)
+    {
+        qof_backend_set_error(qof_book_get_backend(book), ERR_FILEIO_WRITE_ERROR);
+        return;
+    }
 
     xmlFreeNode(node);
 #endif
@@ -920,11 +935,11 @@
     be_data.out = out;
     be_data.book = book;
     be_data.gd = gd;
-    if(fprintf( out, "<%s version=\"%s\">\n", BOOK_TAG, gnc_v2_book_version_string) < 0)
-	{
-		qof_backend_set_error(qof_book_get_backend(book), ERR_FILEIO_WRITE_ERROR);
-		return;
-	}
+    if (fprintf( out, "<%s version=\"%s\">\n", BOOK_TAG, gnc_v2_book_version_string) < 0)
+    {
+        qof_backend_set_error(qof_book_get_backend(book), ERR_FILEIO_WRITE_ERROR);
+        return;
+    }
     write_book_parts (out, book);
 
     /* gd->counter.{foo}_total fields should have all these totals
@@ -940,9 +955,9 @@
                  gnc_book_count_transactions(book),
                  "schedxaction",
                  g_list_length(gnc_book_get_schedxactions(book)->sx_list),
-		 "budget", qof_collection_count(
+                 "budget", qof_collection_count(
                      qof_book_get_collection(book, GNC_ID_BUDGET)),
-		 NULL);
+                 NULL);
 
     qof_object_foreach_backend (GNC_FILE_BACKEND, write_counts_cb, &be_data);
 
@@ -953,14 +968,15 @@
     write_template_transaction_data(out, book, gd);
     write_schedXactions(out, book, gd);
 
-    qof_collection_foreach(qof_book_get_collection(book, GNC_ID_BUDGET), 
-        write_budget, &be_data);
+    qof_collection_foreach(qof_book_get_collection(book, GNC_ID_BUDGET),
+                           write_budget, &be_data);
 
     qof_object_foreach_backend (GNC_FILE_BACKEND, write_data_cb, &be_data);
 
-    if(fprintf( out, "</%s>\n", BOOK_TAG ) < 0) {
-		qof_backend_set_error(qof_book_get_backend(book), ERR_FILEIO_WRITE_ERROR);
-	}
+    if (fprintf( out, "</%s>\n", BOOK_TAG ) < 0)
+    {
+        qof_backend_set_error(qof_book_get_backend(book), ERR_FILEIO_WRITE_ERROR);
+    }
 }
 
 void
@@ -973,33 +989,34 @@
     tbl = gnc_book_get_commodity_table(book);
 
     namespaces = gnc_commodity_table_get_namespaces(tbl);
-    if(namespaces) 
+    if (namespaces)
     {
         namespaces = g_list_sort(namespaces, compare_namespaces);
     }
 
-    for(lp = namespaces; lp; lp = lp->next) 
+    for (lp = namespaces; lp; lp = lp->next)
     {
         GList *comms, *lp2;
-	xmlNodePtr comnode;
+        xmlNodePtr comnode;
 
-	comms = gnc_commodity_table_get_commodities(tbl, lp->data);
-	comms = g_list_sort(comms, compare_commodity_ids);
+        comms = gnc_commodity_table_get_commodities(tbl, lp->data);
+        comms = g_list_sort(comms, compare_commodity_ids);
 
-	for(lp2 = comms; lp2; lp2 = lp2->next) {
-	    comnode = gnc_commodity_dom_tree_create(lp2->data);
-	    if (comnode == NULL)
-	      continue;
+        for (lp2 = comms; lp2; lp2 = lp2->next)
+        {
+            comnode = gnc_commodity_dom_tree_create(lp2->data);
+            if (comnode == NULL)
+                continue;
 
-	    xmlElemDump(out, NULL, comnode);
-	    fprintf(out, "\n");
+            xmlElemDump(out, NULL, comnode);
+            fprintf(out, "\n");
 
-	    xmlFreeNode(comnode);
-	    gd->counter.commodities_loaded++;
-	    run_callback(gd, "commodities");
-	  }
+            xmlFreeNode(comnode);
+            gd->counter.commodities_loaded++;
+            run_callback(gd, "commodities");
+        }
 
-	g_list_free (comms);
+        g_list_free (comms);
     }
 
     if (namespaces) g_list_free (namespaces);
@@ -1012,11 +1029,11 @@
 
     node = gnc_pricedb_dom_tree_create(gnc_book_get_pricedb(book));
 
-    if(!node)
+    if (!node)
     {
         return;
     }
-    
+
     xmlElemDump(out, NULL, node);
     fprintf(out, "\n");
 
@@ -1048,8 +1065,8 @@
     be_data.out = out;
     be_data.gd = gd;
     xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
-				      xml_add_trn_data,
-				      (gpointer) &be_data);
+                                      xml_add_trn_data,
+                                      (gpointer) &be_data);
 }
 
 static void
@@ -1074,24 +1091,26 @@
 static void
 write_schedXactions( FILE *out, QofBook *book, sixtp_gdv2 *gd)
 {
-     GList *schedXactions;
-     SchedXaction *tmpSX;
-     xmlNodePtr node;
-     
-     schedXactions = gnc_book_get_schedxactions(book)->sx_list;
+    GList *schedXactions;
+    SchedXaction *tmpSX;
+    xmlNodePtr node;
 
-     if ( schedXactions == NULL )
-          return;
+    schedXactions = gnc_book_get_schedxactions(book)->sx_list;
 
-     do {
-          tmpSX = schedXactions->data;
-          node = gnc_schedXaction_dom_tree_create( tmpSX );
-          xmlElemDump( out, NULL, node );
-          fprintf( out, "\n" );
-          xmlFreeNode( node );
-          gd->counter.schedXactions_loaded++;
-          run_callback(gd, "schedXactions");
-     } while ( (schedXactions = schedXactions->next) );
+    if ( schedXactions == NULL )
+        return;
+
+    do
+    {
+        tmpSX = schedXactions->data;
+        node = gnc_schedXaction_dom_tree_create( tmpSX );
+        xmlElemDump( out, NULL, node );
+        fprintf( out, "\n" );
+        xmlFreeNode( node );
+        gd->counter.schedXactions_loaded++;
+        run_callback(gd, "schedXactions");
+    }
+    while ( (schedXactions = schedXactions->next) );
 }
 
 static void
@@ -1105,30 +1124,30 @@
     xmlElemDump( be->out, NULL, node );
     fprintf( be->out, "\n" );
     xmlFreeNode( node );
-    
+
     be->gd->counter.budgets_loaded++;
-    run_callback(be->gd, "budgets");    
+    run_callback(be->gd, "budgets");
 }
 
 void
 gnc_xml2_write_namespace_decl (FILE *out, const char *namespace)
 {
-  g_return_if_fail (namespace);
-  fprintf(out, "\n     xmlns:%s=\"http://www.gnucash.org/XML/%s\"",
-          namespace, namespace);
+    g_return_if_fail (namespace);
+    fprintf(out, "\n     xmlns:%s=\"http://www.gnucash.org/XML/%s\"",
+            namespace, namespace);
 }
 
 static void
 do_write_namespace_cb (const char *type, gpointer data_p, gpointer file_p)
 {
-  GncXmlDataType_t *data = data_p;
-  FILE *out = file_p;
+    GncXmlDataType_t *data = data_p;
+    FILE *out = file_p;
 
-  g_return_if_fail (type && data && out);
-  g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
+    g_return_if_fail (type && data && out);
+    g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
 
-  if (data->ns)
-    (data->ns)(out);
+    if (data->ns)
+        (data->ns)(out);
 }
 
 static void
@@ -1136,7 +1155,7 @@
 {
     fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
     fprintf(out, "<" GNC_V2_STRING);
-    
+
     gnc_xml2_write_namespace_decl (out, "gnc");
     gnc_xml2_write_namespace_decl (out, "act");
     gnc_xml2_write_namespace_decl (out, "book");
@@ -1176,19 +1195,19 @@
     be = qof_book_get_backend(book);
     gd = gnc_sixtp_gdv2_new(book, FALSE, file_rw_feedback, be->percentage);
     gd->counter.commodities_total =
-      gnc_commodity_table_get_size(gnc_book_get_commodity_table(book));
-    gd->counter.accounts_total = 1 + 
-      gnc_account_n_descendants(gnc_book_get_root_account(book));
+        gnc_commodity_table_get_size(gnc_book_get_commodity_table(book));
+    gd->counter.accounts_total = 1 +
+                                 gnc_account_n_descendants(gnc_book_get_root_account(book));
     gd->counter.transactions_total = gnc_book_count_transactions(book);
     gd->counter.schedXactions_total =
-      g_list_length(gnc_book_get_schedxactions(book)->sx_list);
+        g_list_length(gnc_book_get_schedxactions(book)->sx_list);
     gd->counter.budgets_total = qof_collection_count(
-        qof_book_get_collection(book, GNC_ID_BUDGET));
+                                    qof_book_get_collection(book, GNC_ID_BUDGET));
 
     write_book(out, book, gd);
 
     fprintf(out, "</" GNC_V2_STRING ">\n\n");
-    
+
     g_free(gd);
     return TRUE;
 }
@@ -1251,7 +1270,8 @@
         gchar *conv_name = g_win32_locale_filename_from_utf8(params->filename);
         gchar *perms;
 
-        if (!conv_name) {
+        if (!conv_name)
+        {
             g_warning("Could not convert '%s' to system codepage",
                       params->filename);
             goto cleanup_gz_thread_func;
@@ -1270,7 +1290,8 @@
     file = gzopen(params->filename, params->perms);
 #endif /* G_OS_WIN32 */
 
-    if (file == NULL) {
+    if (file == NULL)
+    {
         g_warning("Child threads gzopen failed");
         goto cleanup_gz_thread_func;
     }
@@ -1298,62 +1319,65 @@
 try_gz_open (const char *filename, const char *perms, gboolean use_gzip,
              gboolean compress)
 {
-  if (strstr(filename, ".gz.") != NULL) /* its got a temp extension */
-      use_gzip = TRUE;
+    if (strstr(filename, ".gz.") != NULL) /* its got a temp extension */
+        use_gzip = TRUE;
 
-  if (!use_gzip)
-    return g_fopen(filename, perms);
+    if (!use_gzip)
+        return g_fopen(filename, perms);
 
-  {
-    int filedes[2];
-    GThread *thread;
-    GError *error = NULL;
-    gz_thread_params_t *params;
-    FILE *file;
+    {
+        int filedes[2];
+        GThread *thread;
+        GError *error = NULL;
+        gz_thread_params_t *params;
+        FILE *file;
 
 #ifdef G_OS_WIN32
-    if (_pipe(filedes, 4096, _O_BINARY) < 0) {
+        if (_pipe(filedes, 4096, _O_BINARY) < 0)
+        {
 #else
-    if (pipe(filedes) < 0) {
+        if (pipe(filedes) < 0)
+        {
 #endif
-      g_warning("Pipe call failed. Opening uncompressed file.");
-      return g_fopen(filename, perms);
-    }
+            g_warning("Pipe call failed. Opening uncompressed file.");
+            return g_fopen(filename, perms);
+        }
 
-    params = g_new(gz_thread_params_t, 1);
-    params->fd = filedes[compress ? 0 : 1];
-    params->filename = g_strdup(filename);
-    params->perms = g_strdup(perms);
-    params->compress = compress;
+        params = g_new(gz_thread_params_t, 1);
+        params->fd = filedes[compress ? 0 : 1];
+        params->filename = g_strdup(filename);
+        params->perms = g_strdup(perms);
+        params->compress = compress;
 
-    thread = g_thread_create((GThreadFunc) gz_thread_func, params, TRUE, &error);
-    if (!thread) {
-      g_warning("Could not create thread for (de)compression: %s",
-                error->message);
-      g_error_free(error);
-      g_free(params->filename);
-      g_free(params->perms);
-      g_free(params);
-      close(filedes[0]);
-      close(filedes[1]);
+        thread = g_thread_create((GThreadFunc) gz_thread_func, params, TRUE, &error);
+        if (!thread)
+        {
+            g_warning("Could not create thread for (de)compression: %s",
+                      error->message);
+            g_error_free(error);
+            g_free(params->filename);
+            g_free(params->perms);
+            g_free(params);
+            close(filedes[0]);
+            close(filedes[1]);
 
-      return g_fopen(filename, perms);
-    }
+            return g_fopen(filename, perms);
+        }
 
-    if (compress)
-      file = fdopen(filedes[1], "w");
-    else
-      file = fdopen(filedes[0], "r");
+        if (compress)
+            file = fdopen(filedes[1], "w");
+        else
+            file = fdopen(filedes[0], "r");
 
-    G_LOCK(threads);
-    if (!threads)
-      threads = g_hash_table_new(g_direct_hash, g_direct_equal);
+        G_LOCK(threads);
+        if (!threads)
+            threads = g_hash_table_new(g_direct_hash, g_direct_equal);
 
-    g_hash_table_insert(threads, file, thread);
-    G_UNLOCK(threads);
+        g_hash_table_insert(threads, file, thread);
+        G_UNLOCK(threads);
 
-    return file;
-  }
+        return file;
+    }
 }
 
 static gboolean
@@ -1362,9 +1386,11 @@
     gboolean retval = TRUE;
 
     G_LOCK(threads);
-    if (threads) {
+    if (threads)
+    {
         GThread *thread = g_hash_table_lookup(threads, file);
-        if (thread) {
+        if (thread)
+        {
             g_hash_table_remove(threads, file);
             retval = GPOINTER_TO_INT(g_thread_join(thread));
         }
@@ -1441,17 +1467,20 @@
     unsigned char buf[2];
     int fd = g_open(name, O_RDONLY, 0);
 
-    if (fd == -1) {
+    if (fd == -1)
+    {
         return FALSE;
     }
 
-    if (read(fd, buf, 2) != 2) {
+    if (read(fd, buf, 2) != 2)
+    {
         close(fd);
         return FALSE;
     }
     close(fd);
 
-    if (buf[0] == 037 && buf[1] == 0213) {
+    if (buf[0] == 037 && buf[1] == 0213)
+    {
         return TRUE;
     }
 
@@ -1464,7 +1493,8 @@
     if (gnc_is_our_xml_file(name, GNC_V2_STRING, with_encoding))
         return TRUE;
 
-    if (is_gzipped_file(name)) {
+    if (is_gzipped_file(name))
+    {
         gzFile *file;
         char first_chunk[256];
         int num_read;
@@ -1474,7 +1504,8 @@
             gchar *conv_name = g_win32_locale_filename_from_utf8(name);
             if (!conv_name)
                 g_warning("Could not convert '%s' to system codepage", name);
-            else {
+            else
+            {
                 file = gzopen(conv_name, "rb");
                 g_free(conv_name);
             }
@@ -1506,19 +1537,25 @@
     glong number;
 
     for (cursor = strstr(string, "&#");
-         cursor && *cursor;
-         cursor = strstr(cursor, "&#")) {
+            cursor && *cursor;
+            cursor = strstr(cursor, "&#"))
+    {
         semicolon = strchr(cursor, ';');
-        if (semicolon && *semicolon) {
+        if (semicolon && *semicolon)
+        {
 
             /* parse number */
             errno = 0;
-            if (*(cursor+2) == 'x') {
-                number = strtol(cursor+3, &tail, 16);
-            } else {
-                number = strtol(cursor+2, &tail, 10);
+            if (*(cursor + 2) == 'x')
+            {
+                number = strtol(cursor + 3, &tail, 16);
             }
-            if (errno || tail != semicolon || number < 0 || number > 255) {
+            else
+            {
+                number = strtol(cursor + 2, &tail, 10);
+            }
+            if (errno || tail != semicolon || number < 0 || number > 255)
+            {
                 PWARN("Illegal character reference");
                 return;
             }
@@ -1526,17 +1563,22 @@
             /* overwrite '&' with the specified character */
             *cursor = (gchar) number;
             cursor++;
-            if (*(semicolon+1)) {
+            if (*(semicolon + 1))
+            {
                 /* move text after semicolon the the left */
-                tail = g_strdup(semicolon+1);
+                tail = g_strdup(semicolon + 1);
                 strcpy(cursor, tail);
                 g_free(tail);
-            } else {
+            }
+            else
+            {
                 /* cut here */
                 *cursor = '\0';
             }
 
-        } else {
+        }
+        else
+        {
             PWARN("Unclosed character reference");
             return;
         }
@@ -1544,20 +1586,24 @@
 }
 
 static void
-conv_free(conv_type *conv) {
-    if (conv) {
+conv_free(conv_type *conv)
+{
+    if (conv)
+    {
         g_free(conv->utf8_string);
         g_free(conv);
     }
 }
 
 static void
-conv_list_free(GList *conv_list) {
+conv_list_free(GList *conv_list)
+{
     g_list_foreach(conv_list, (GFunc) conv_free, NULL);
     g_list_free(conv_list);
 }
 
-typedef struct  {
+typedef struct
+{
     GQuark encoding;
     GIConv iconv;
 } iconv_item_type;
@@ -1567,19 +1613,20 @@
                         GHashTable **unique, GHashTable **ambiguous,
                         GList **impossible)
 {
-    FILE *file=NULL;
-    GList *iconv_list=NULL, *conv_list=NULL, *iter;
-    iconv_item_type *iconv_item=NULL, *ascii=NULL;
+    FILE *file = NULL;
+    GList *iconv_list = NULL, *conv_list = NULL, *iter;
+    iconv_item_type *iconv_item = NULL, *ascii = NULL;
     const gchar *enc;
-    GHashTable *processed=NULL;
+    GHashTable *processed = NULL;
     gint n_impossible = 0;
-    GError *error=NULL;
+    GError *error = NULL;
     gboolean is_compressed;
-    gboolean clean_return=FALSE;
+    gboolean clean_return = FALSE;
 
     is_compressed = is_gzipped_file(filename);
     file = try_gz_open(filename, "r", is_compressed, FALSE);
-    if (file == NULL) {
+    if (file == NULL)
+    {
         PWARN("Unable to open file %s", filename);
         goto cleanup_find_ambs;
     }
@@ -1588,50 +1635,61 @@
     ascii = g_new(iconv_item_type, 1);
     ascii->encoding = g_quark_from_string("ASCII");
     ascii->iconv = g_iconv_open("UTF-8", "ASCII");
-    if (ascii->iconv == (GIConv) -1) {
+    if (ascii->iconv == (GIConv) - 1)
+    {
         PWARN("Unable to open ASCII ICONV conversion descriptor");
         goto cleanup_find_ambs;
     }
 
     /* call iconv_open on encodings */
-    for (iter = encodings; iter; iter = iter->next) {
+    for (iter = encodings; iter; iter = iter->next)
+    {
         iconv_item = g_new(iconv_item_type, 1);
         iconv_item->encoding = GPOINTER_TO_UINT (iter->data);
-        if (iconv_item->encoding == ascii->encoding) {
+        if (iconv_item->encoding == ascii->encoding)
+        {
             continue;
         }
 
         enc = g_quark_to_string(iconv_item->encoding);
         iconv_item->iconv = g_iconv_open("UTF-8", enc);
-        if (iconv_item->iconv == (GIConv) -1) {
+        if (iconv_item->iconv == (GIConv) - 1)
+        {
             PWARN("Unable to open IConv conversion descriptor for '%s'", enc);
             goto cleanup_find_ambs;
-        } else {
+        }
+        else
+        {
             iconv_list = g_list_prepend(iconv_list, iconv_item);
         }
     }
 
     /* prepare data containers */
     if (unique)
-      *unique = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
-                                      (GDestroyNotify) conv_free);
+        *unique = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+                                        (GDestroyNotify) conv_free);
     if (ambiguous)
-      *ambiguous = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
-                                         (GDestroyNotify) conv_list_free);
+        *ambiguous = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+                                           (GDestroyNotify) conv_list_free);
     if (impossible)
-      *impossible = NULL;
+        *impossible = NULL;
     processed = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 
     /* loop through lines */
-    while (1) {
+    while (1)
+    {
         gchar line[256], *word, *utf8;
         gchar **word_array, **word_cursor;
         conv_type *conv = NULL;
 
-        if (!fgets(line, sizeof(line)-1, file)) {
-            if (feof(file)) {
+        if (!fgets(line, sizeof(line) - 1, file))
+        {
+            if (feof(file))
+            {
                 break;
-            } else {
+            }
+            else
+            {
                 goto cleanup_find_ambs;
             }
         }
@@ -1641,14 +1699,16 @@
         word_array = g_strsplit_set(line, "> <", 0);
 
         /* loop through words */
-        for (word_cursor = word_array; *word_cursor; word_cursor++) {
+        for (word_cursor = word_array; *word_cursor; word_cursor++)
+        {
             word = *word_cursor;
             if (!word)
-              continue;
+                continue;
 
             utf8 = g_convert_with_iconv(word, -1, ascii->iconv,
                                         NULL, NULL, &error);
-            if (utf8) {
+            if (utf8)
+            {
                 /* pure ascii */
                 g_free(utf8);
                 continue;
@@ -1656,49 +1716,63 @@
             g_error_free(error);
             error = NULL;
 
-            if (g_hash_table_lookup_extended(processed, word, NULL, NULL)) {
+            if (g_hash_table_lookup_extended(processed, word, NULL, NULL))
+            {
                 /* already processed */
                 continue;
             }
 
             /* loop through encodings */
             conv_list = NULL;
-            for (iter = iconv_list; iter; iter = iter->next) {
+            for (iter = iconv_list; iter; iter = iter->next)
+            {
                 iconv_item = iter->data;
                 utf8 = g_convert_with_iconv(word, -1, iconv_item->iconv,
                                             NULL, NULL, &error);
-                if (utf8) {
+                if (utf8)
+                {
                     conv = g_new(conv_type, 1);
                     conv->encoding = iconv_item->encoding;
                     conv->utf8_string = utf8;
                     conv_list = g_list_prepend(conv_list, conv);
-                } else {
+                }
+                else
+                {
                     g_error_free(error);
                     error = NULL;
                 }
             }
 
             /* no successful conversion */
-            if (!conv_list) {
+            if (!conv_list)
+            {
                 if (impossible)
                     *impossible = g_list_append(*impossible, g_strdup(word));
                 n_impossible++;
             }
 
             /* more than one successful conversion */
-            else if (conv_list->next) {
-                if (ambiguous) {
+            else if (conv_list->next)
+            {
+                if (ambiguous)
+                {
                     g_hash_table_insert(*ambiguous, g_strdup(word), conv_list);
-                } else {
+                }
+                else
+                {
                     conv_list_free(conv_list);
                 }
             }
 
             /* only one successful conversion */
-            else {
-                if (unique) {
+            else
+            {
+                if (unique)
+                {
                     g_hash_table_insert(*unique, g_strdup(word), conv);
-                } else {
+                }
+                else
+                {
                     conv_free(conv);
                 }
                 g_list_free(conv_list);
@@ -1711,11 +1785,14 @@
 
     clean_return = TRUE;
 
- cleanup_find_ambs:
+cleanup_find_ambs:
 
-    if (iconv_list) {
-        for (iter = iconv_list; iter; iter = iter->next) {
-            if (iter->data) {
+    if (iconv_list)
+    {
+        for (iter = iconv_list; iter; iter = iter->next)
+        {
+            if (iter->data)
+            {
                 g_iconv_close(((iconv_item_type*) iter->data)->iconv);
                 g_free(iter->data);
             }
@@ -1726,7 +1803,8 @@
         g_hash_table_destroy(processed);
     if (ascii)
         g_free(ascii);
-    if (file) {
+    if (file)
+    {
         fclose(file);
         if (is_compressed)
             wait_for_gzip(file);
@@ -1735,7 +1813,8 @@
     return (clean_return) ? n_impossible : -1;
 }
 
-typedef struct {
+typedef struct
+{
     gchar *filename;
     GHashTable *subst;
 } push_data_type;
@@ -1746,35 +1825,42 @@
 {
     const gchar *filename;
     FILE *file = NULL;
-    GIConv ascii=(GIConv)-1;
-    GString *output=NULL;
-    GError *error=NULL;
+    GIConv ascii = (GIConv) - 1;
+    GString *output = NULL;
+    GError *error = NULL;
     gboolean is_compressed;
 
     filename = push_data->filename;
     is_compressed = is_gzipped_file(filename);
     file = try_gz_open(filename, "r", is_compressed, FALSE);
-    if (file == NULL) {
+    if (file == NULL)
+    {
         PWARN("Unable to open file %s", filename);
         goto cleanup_push_handler;
     }
 
     ascii = g_iconv_open("UTF-8", "ASCII");
-    if (ascii == (GIConv) -1) {
+    if (ascii == (GIConv) - 1)
+    {
         PWARN("Unable to open ASCII ICONV conversion descriptor");
         goto cleanup_push_handler;
     }
 
     /* loop through lines */
-    while (1) {
+    while (1)
+    {
         gchar line[256], *word, *repl, *utf8;
         gint pos, len;
         gchar *start, *cursor;
 
-        if (!fgets(line, sizeof(line)-1, file)) {
-            if (feof(file)) {
+        if (!fgets(line, sizeof(line) - 1, file))
+        {
+            if (feof(file))
+            {
                 break;
-            } else {
+            }
+            else
+            {
                 goto cleanup_push_handler;
             }
         }
@@ -1785,10 +1871,12 @@
         /* loop through words */
         cursor = output->str;
         pos = 0;
-        while (1) {
+        while (1)
+        {
             /* ignore delimiters */
-            while (*cursor=='>' || *cursor==' ' || *cursor=='<' ||
-                   *cursor=='\n') {
+            while (*cursor == '>' || *cursor == ' ' || *cursor == '<' ||
+                    *cursor == '\n')
+            {
                 cursor++;
                 pos += 1;
             }
@@ -1800,39 +1888,47 @@
             /* search for a delimiter */
             start = cursor;
             len = 0;
-            while (*cursor && *cursor!='>' && *cursor!=' ' && *cursor!='<' &&
-                   *cursor!='\n') {
+            while (*cursor && *cursor != '>' && *cursor != ' ' && *cursor != '<' &&
+                    *cursor != '\n')
+            {
                 cursor++;
                 len++;
             }
 
             utf8 = g_convert_with_iconv(start, len, ascii, NULL, NULL, &error);
 
-            if (utf8) {
+            if (utf8)
+            {
                 /* pure ascii */
                 g_free(utf8);
                 pos += len;
-            } else {
+            }
+            else
+            {
                 g_error_free(error);
                 error = NULL;
 
                 word = g_strndup(start, len);
                 repl = g_hash_table_lookup(push_data->subst, word);
                 g_free(word);
-                if (repl) {
+                if (repl)
+                {
                     /* there is a replacement */
                     output = g_string_insert(g_string_erase(output, pos, len),
                                              pos, repl);
                     pos += strlen(repl);
                     cursor = output->str + pos;
-                } else {
+                }
+                else
+                {
                     /* there is no replacement, return immediately */
                     goto cleanup_push_handler;
                 }
             }
         }
 
-        if (xmlParseChunk(xml_context, output->str, output->len, 0) != 0) {
+        if (xmlParseChunk(xml_context, output->str, output->len, 0) != 0)
+        {
             goto cleanup_push_handler;
         }
     }
@@ -1840,13 +1936,14 @@
     /* last chunk */
     xmlParseChunk(xml_context, "", 0, 1);
 
- cleanup_push_handler:
+cleanup_push_handler:
 
     if (output)
         g_string_free(output, TRUE);
-    if (ascii != (GIConv) -1)
+    if (ascii != (GIConv) - 1)
         g_iconv_close(ascii);
-    if (file) {
+    if (file)
+    {
         fclose(file);
         if (is_compressed)
             wait_for_gzip(file);
@@ -1864,8 +1961,8 @@
     push_data->subst = subst;
 
     success = qof_session_load_from_xml_file_v2_full(
-        fbe, book, (sixtp_push_handler) parse_with_subst_push_handler,
-        push_data);
+                  fbe, book, (sixtp_push_handler) parse_with_subst_push_handler,
+                  push_data);
 
     if (success)
         qof_book_kvp_changed(book);

Modified: gnucash/trunk/src/backend/xml/io-gncxml-v2.h
===================================================================
--- gnucash/trunk/src/backend/xml/io-gncxml-v2.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/io-gncxml-v2.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -100,15 +100,15 @@
 #define GNC_FILE_BACKEND_VERS	2
 typedef struct
 {
-  int		version;	/* backend version number */
-  const char *	type_name;	/* The XML tag for this type */
+    int		version;	/* backend version number */
+    const char *	type_name;	/* The XML tag for this type */
 
-  sixtp *	(*create_parser) (void);
-  gboolean	(*add_item)(sixtp_gdv2 *, gpointer obj);
-  int	      (*get_count) (QofBook *);
-  void		(*write) (FILE*, QofBook*);
-  void		(*scrub) (QofBook *);
-  void		(*ns) (FILE*);
+    sixtp *	(*create_parser) (void);
+    gboolean	(*add_item)(sixtp_gdv2 *, gpointer obj);
+    int	      (*get_count) (QofBook *);
+    void		(*write) (FILE*, QofBook*);
+    void		(*scrub) (QofBook *);
+    void		(*ns) (FILE*);
 } GncXmlDataType_t;
 
 /**
@@ -119,9 +119,9 @@
  **/
 typedef struct
 {
-	AccountList	*accts;
-	TransList	*transactions;
-	QofBook *book;
+    AccountList	*accts;
+    TransList	*transactions;
+    QofBook *book;
 } gnc_template_xaction_data;
 
 /** Call after loading each record */
@@ -137,9 +137,9 @@
 /** write just the commodities and accounts to a file */
 gboolean gnc_book_write_accounts_to_xml_filehandle_v2(QofBackend *be, QofBook *book, FILE *fh);
 gboolean gnc_book_write_accounts_to_xml_file_v2(QofBackend * be, QofBook *book,
-						const char *filename);
+        const char *filename);
 
-/** The is_gncxml_file() routine checks to see if the first few 
+/** The is_gncxml_file() routine checks to see if the first few
  * chars of the file look like gnc-xml data.
  */
 gboolean gnc_is_xml_data_file_v2(const gchar *name, gboolean *with_encoding);
@@ -150,9 +150,10 @@
 void gnc_xml2_write_namespace_decl (FILE *out, const char *namespace);
 
 
-typedef struct {
-  GQuark encoding;
-  gchar *utf8_string;
+typedef struct
+{
+    GQuark encoding;
+    gchar *utf8_string;
 } conv_type;
 
 /** Read a file as plain byte stream to find words that are not completely ASCII.

Modified: gnucash/trunk/src/backend/xml/io-gncxml.h
===================================================================
--- gnucash/trunk/src/backend/xml/io-gncxml.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/io-gncxml.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -42,9 +42,9 @@
 /** Read in an account group from a file */
 gboolean qof_session_load_from_xml_file(QofBook *, const char * filename);
 
-/** The is_gncxml_file() routine checks to see if the first few 
+/** The is_gncxml_file() routine checks to see if the first few
  * chars of the file look like gnc-xml data.
  */
 gboolean gnc_is_xml_data_file(const gchar *name);
- 
+
 #endif /* IO_GNCXML_H */

Modified: gnucash/trunk/src/backend/xml/io-utils.c
===================================================================
--- gnucash/trunk/src/backend/xml/io-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/io-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -40,9 +40,9 @@
 */
 
 static const gchar *emacs_trailer =
-"<!-- Local variables: -->\n"
-"<!-- mode: xml        -->\n"
-"<!-- End:             -->\n";
+    "<!-- Local variables: -->\n"
+    "<!-- mode: xml        -->\n"
+    "<!-- End:             -->\n";
 
 
 void
@@ -60,7 +60,7 @@
     xmlNodePtr accnode;
 
     accnode =
-      gnc_account_dom_tree_create(account, gd && gd->exporting, allow_incompat);
+        gnc_account_dom_tree_create(account, gd && gd->exporting, allow_incompat);
 
     xmlElemDump(out, NULL, accnode);
     fprintf(out, "\n");
@@ -77,11 +77,11 @@
     gboolean allow_incompat = TRUE;
 
     if (allow_incompat)
-      write_one_account(out, root, gd, allow_incompat);
+        write_one_account(out, root, gd, allow_incompat);
 
     descendants = gnc_account_get_descendants(root);
-    for (node = descendants; node; node = g_list_next(node)) 
-      write_one_account(out, node->data, gd, allow_incompat);
+    for (node = descendants; node; node = g_list_next(node))
+        write_one_account(out, node->data, gd, allow_incompat);
     g_list_free(descendants);
 }
 

Modified: gnucash/trunk/src/backend/xml/io-utils.h
===================================================================
--- gnucash/trunk/src/backend/xml/io-utils.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/io-utils.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -38,4 +38,4 @@
 void write_emacs_trailer(FILE *out);
 
 
-#endif /* IO_UTILS_H */    
+#endif /* IO_UTILS_H */

Modified: gnucash/trunk/src/backend/xml/sixtp-dom-generators.c
===================================================================
--- gnucash/trunk/src/backend/xml/sixtp-dom-generators.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/sixtp-dom-generators.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -70,7 +70,7 @@
 {
     gchar *text;
     xmlNodePtr result;
-    
+
     text = g_strdup_printf("%u", an_int );
     g_return_val_if_fail(text, NULL);
     result = text_to_dom_tree(tag, text);
@@ -106,14 +106,14 @@
     xmlNodePtr ret;
 
     g_return_val_if_fail(c, NULL);
-    
+
     ret = xmlNewNode(NULL, BAD_CAST tag);
 
-    if(!gnc_commodity_get_namespace(c) || !gnc_commodity_get_mnemonic(c))
+    if (!gnc_commodity_get_namespace(c) || !gnc_commodity_get_mnemonic(c))
     {
         return NULL;
     }
-    
+
     xmlNewTextChild(ret, NULL, BAD_CAST "cmdty:space", BAD_CAST gnc_commodity_get_namespace_compat(c));
     xmlNewTextChild(ret, NULL, BAD_CAST "cmdty:id", BAD_CAST gnc_commodity_get_mnemonic(c));
 
@@ -127,7 +127,7 @@
 
     ret = g_new(gchar, TIMESPEC_SEC_FORMAT_MAX);
 
-    if(!timespec_secs_to_given_string (ts, ret))
+    if (!timespec_secs_to_given_string (ts, ret))
     {
         g_free(ret);
         return NULL;
@@ -145,55 +145,59 @@
 xmlNodePtr
 timespec_to_dom_tree(const char *tag, const Timespec *spec)
 {
-	xmlNodePtr ret;
-	gchar *date_str = NULL;
-	gchar *ns_str = NULL;
-    
-	g_return_val_if_fail(spec, NULL);
+    xmlNodePtr ret;
+    gchar *date_str = NULL;
+    gchar *ns_str = NULL;
 
-	date_str = timespec_sec_to_string(spec);
+    g_return_val_if_fail(spec, NULL);
 
-	if(!date_str) {
-		return NULL;
-	}
-    
-	ret = xmlNewNode(NULL, BAD_CAST tag);
-    
-	xmlNewTextChild(ret, NULL, BAD_CAST "ts:date", BAD_CAST date_str);
+    date_str = timespec_sec_to_string(spec);
 
-	if(spec->tv_nsec > 0){
-		ns_str = timespec_nsec_to_string(spec);
-		if(ns_str){
-			xmlNewTextChild(ret, NULL, BAD_CAST "ts:ns", BAD_CAST ns_str);
-		}
-	}
+    if (!date_str)
+    {
+        return NULL;
+    }
 
-	g_free(date_str);
-	if(ns_str){
-		g_free(ns_str);
-	}
-    
-	return ret;
+    ret = xmlNewNode(NULL, BAD_CAST tag);
+
+    xmlNewTextChild(ret, NULL, BAD_CAST "ts:date", BAD_CAST date_str);
+
+    if (spec->tv_nsec > 0)
+    {
+        ns_str = timespec_nsec_to_string(spec);
+        if (ns_str)
+        {
+            xmlNewTextChild(ret, NULL, BAD_CAST "ts:ns", BAD_CAST ns_str);
+        }
+    }
+
+    g_free(date_str);
+    if (ns_str)
+    {
+        g_free(ns_str);
+    }
+
+    return ret;
 }
 
 xmlNodePtr
 gdate_to_dom_tree(const char *tag, const GDate *date)
 {
-	xmlNodePtr ret;
-	gchar *date_str = NULL;
+    xmlNodePtr ret;
+    gchar *date_str = NULL;
 
-	g_return_val_if_fail(date, NULL);
-	date_str = g_new( gchar, 512 );
+    g_return_val_if_fail(date, NULL);
+    date_str = g_new( gchar, 512 );
 
-	g_date_strftime( date_str, 512, "%Y-%m-%d", date );
+    g_date_strftime( date_str, 512, "%Y-%m-%d", date );
 
-	ret = xmlNewNode(NULL, BAD_CAST tag);
+    ret = xmlNewNode(NULL, BAD_CAST tag);
 
-	xmlNewTextChild(ret, NULL, BAD_CAST "gdate", BAD_CAST date_str);
+    xmlNewTextChild(ret, NULL, BAD_CAST "gdate", BAD_CAST date_str);
 
-	g_free(date_str);
+    g_free(date_str);
 
-	return ret;
+    return ret;
 }
 
 xmlNodePtr
@@ -203,7 +207,7 @@
     gchar *numstr;
 
     g_return_val_if_fail(num, NULL);
-    
+
     numstr = gnc_numeric_to_string(*num);
     g_return_val_if_fail(numstr, NULL);
 
@@ -220,9 +224,9 @@
 double_to_string(double value)
 {
     gchar *numstr;
-#ifdef USE_GUILE_FOR_DOUBLE_CONVERSION 
+#ifdef USE_GUILE_FOR_DOUBLE_CONVERSION
     numstr = gh_scm2newstr(scm_call_1(scm_c_eval_string("number->string"),
-				      scm_make_real(value)),
+                                      scm_make_real(value)),
                            NULL);
 
 #else /* don't USE_GUILE_FOR_DOUBLE_CONVERSION */
@@ -235,10 +239,10 @@
     numstr = g_strdup_printf ("%24.18g", value);
 
 #endif /* USE_GUILE_FOR_DOUBLE_CONVERSION */
-    if(!numstr)
+    if (!numstr)
     {
         return NULL;
-        
+
     }
     else
     {
@@ -269,13 +273,13 @@
     kvp_type = kvp_value_get_type(val);
 
     if (kvp_type == KVP_TYPE_STRING)
-      val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, BAD_CAST kvp_value_get_string(val));
+        val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, BAD_CAST kvp_value_get_string(val));
     else if (kvp_type == KVP_TYPE_TIMESPEC)
-      val_node = NULL;
+        val_node = NULL;
     else
-      val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, NULL);
+        val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, NULL);
 
-    switch(kvp_value_get_type(val))
+    switch (kvp_value_get_type(val))
     {
     case KVP_TYPE_GINT64:
         add_text_to_node(val_node, "integer",
@@ -283,11 +287,11 @@
                                          kvp_value_get_gint64(val)));
         break;
     case KVP_TYPE_DOUBLE:
-        add_text_to_node(val_node,"double",
+        add_text_to_node(val_node, "double",
                          double_to_string(kvp_value_get_double(val)));
         break;
     case KVP_TYPE_NUMERIC:
-        add_text_to_node(val_node,"numeric",
+        add_text_to_node(val_node, "numeric",
                          gnc_numeric_to_string(kvp_value_get_numeric(val)));
         break;
     case KVP_TYPE_STRING:
@@ -295,16 +299,16 @@
         break;
     case KVP_TYPE_GUID:
         /* THREAD-UNSAFE */
-        add_text_to_node(val_node,"guid",
+        add_text_to_node(val_node, "guid",
                          g_strdup(guid_to_string(kvp_value_get_guid(val))));
         break;
     case KVP_TYPE_TIMESPEC:
     {
-      Timespec ts = kvp_value_get_timespec (val);
+        Timespec ts = kvp_value_get_timespec (val);
 
-      val_node = timespec_to_dom_tree (tag, &ts);
-      xmlSetProp (val_node, BAD_CAST "type", BAD_CAST "timespec");
-      xmlAddChild (node, val_node);
+        val_node = timespec_to_dom_tree (tag, &ts);
+        xmlSetProp (val_node, BAD_CAST "type", BAD_CAST "timespec");
+        xmlAddChild (node, val_node);
     }
     break;
     case KVP_TYPE_BINARY:
@@ -321,15 +325,15 @@
     case KVP_TYPE_GLIST:
     {
         GList *cursor;
-        
+
         xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "list");
-        for(cursor = kvp_value_get_glist(val); cursor; cursor = cursor->next)
+        for (cursor = kvp_value_get_glist(val); cursor; cursor = cursor->next)
         {
             kvp_value *val = (kvp_value*)cursor->data;
             add_kvp_value_node(val_node, "slot:value", val);
         }
     }
-    
+
     break;
     case KVP_TYPE_FRAME:
     {
@@ -339,7 +343,7 @@
 
         frame = kvp_value_get_frame (val);
         if (!frame || !kvp_frame_get_hash (frame))
-          break;
+            break;
 
         g_hash_table_foreach(kvp_frame_get_hash(frame),
                              add_kvp_slot, val_node);
@@ -363,31 +367,31 @@
 
     add_kvp_value_node(slot_node, "slot:value", (kvp_value*)value);
 }
-    
+
 xmlNodePtr
 kvp_frame_to_dom_tree(const char *tag, const kvp_frame *frame)
 {
     xmlNodePtr ret;
 
-    if(!frame)
+    if (!frame)
     {
         return NULL;
     }
 
-    if(!kvp_frame_get_hash(frame))
+    if (!kvp_frame_get_hash(frame))
     {
         return NULL;
     }
 
-    if(g_hash_table_size(kvp_frame_get_hash(frame)) == 0)
+    if (g_hash_table_size(kvp_frame_get_hash(frame)) == 0)
     {
         return NULL;
     }
-    
+
     ret = xmlNewNode(NULL, BAD_CAST tag);
-    
+
     g_hash_table_foreach(kvp_frame_get_hash(frame), add_kvp_slot, ret);
-    
+
     return ret;
 }
 

Modified: gnucash/trunk/src/backend/xml/sixtp-dom-parsers.c
===================================================================
--- gnucash/trunk/src/backend/xml/sixtp-dom-parsers.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/sixtp-dom-parsers.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -36,12 +36,12 @@
 GUID*
 dom_tree_to_guid(xmlNodePtr node)
 {
-    if(!node->properties)
+    if (!node->properties)
     {
         return NULL;
     }
 
-    if(strcmp((char*) node->properties->name, "type") != 0)
+    if (strcmp((char*) node->properties->name, "type") != 0)
     {
         PERR("Unknown attribute for id tag: %s",
              node->properties->name ?
@@ -55,7 +55,7 @@
         type = (char*)xmlNodeGetContent (node->properties->xmlAttrPropertyValue);
 
         /* handle new and guid the same for the moment */
-        if((safe_strcmp("guid", type) == 0) || (safe_strcmp("new", type) == 0))
+        if ((safe_strcmp("guid", type) == 0) || (safe_strcmp("new", type) == 0))
         {
             GUID *gid = g_new(GUID, 1);
             char *guid_str;
@@ -66,7 +66,7 @@
             xmlFree (type);
             return gid;
         }
-        else 
+        else
         {
             PERR("Unknown type %s for attribute type for tag %s",
                  type ? type : "(null)",
@@ -84,10 +84,10 @@
     gchar *text;
     gint64 daint;
     kvp_value* ret = NULL;
-    
+
     text = dom_tree_to_text(node);
 
-    if(string_to_gint64(text, &daint))
+    if (string_to_gint64(text, &daint))
     {
         ret = kvp_value_new_gint64(daint);
     }
@@ -143,17 +143,22 @@
 {
     gchar* text;
 
-	text = dom_tree_to_text(node);
-	if (strcasecmp(text, "true") == 0) {
-	    *b = TRUE;
-		return TRUE;
-	} else if(strcasecmp(text, "false") == 0) {
-	    *b = FALSE;
-		return TRUE;
-	} else {
-	    *b = FALSE;
-		return FALSE;
-	}
+    text = dom_tree_to_text(node);
+    if (strcasecmp(text, "true") == 0)
+    {
+        *b = TRUE;
+        return TRUE;
+    }
+    else if (strcasecmp(text, "false") == 0)
+    {
+        *b = FALSE;
+        return TRUE;
+    }
+    else
+    {
+        *b = FALSE;
+        return FALSE;
+    }
 }
 
 kvp_value*
@@ -165,13 +170,13 @@
 
     text = dom_tree_to_text(node);
 
-    if(string_to_double(text, &dadoub))
+    if (string_to_double(text, &dadoub))
     {
         ret = kvp_value_new_double(dadoub);
     }
 
     g_free(text);
-    
+
     return ret;
 }
 
@@ -183,13 +188,13 @@
 
     danum = dom_tree_to_gnc_numeric(node);
 
-    if(danum)
+    if (danum)
     {
         ret = kvp_value_new_gnc_numeric(*danum);
     }
 
     g_free(danum);
-    
+
     return ret;
 }
 
@@ -200,13 +205,13 @@
     kvp_value *ret = NULL;
 
     datext = dom_tree_to_text(node);
-    if(datext)
+    if (datext)
     {
         ret = kvp_value_new_string(datext);
     }
 
     g_free(datext);
-    
+
     return ret;
 }
 
@@ -217,67 +222,67 @@
     kvp_value *ret = NULL;
 
     daguid = dom_tree_to_guid(node);
-    if(daguid)
+    if (daguid)
     {
         ret = kvp_value_new_guid(daguid);
     }
 
     g_free(daguid);
-    
+
     return ret;
 }
 
 kvp_value*
 dom_tree_to_timespec_kvp_value (xmlNodePtr node)
 {
-  Timespec ts;
-  kvp_value * ret = NULL;
+    Timespec ts;
+    kvp_value * ret = NULL;
 
-  ts = dom_tree_to_timespec (node);
-  if (ts.tv_sec || ts.tv_nsec)
-  {
-    ret = kvp_value_new_timespec (ts);
-  }
-  return ret;
+    ts = dom_tree_to_timespec (node);
+    if (ts.tv_sec || ts.tv_nsec)
+    {
+        ret = kvp_value_new_timespec (ts);
+    }
+    return ret;
 }
 
 gboolean
 string_to_binary(const gchar *str,  void **v, guint64 *data_len)
 {
-  guint64 str_len;
-  guchar *data;
-  unsigned int i, j;
+    guint64 str_len;
+    guchar *data;
+    unsigned int i, j;
 
-  g_return_val_if_fail(v != NULL, FALSE);
-  g_return_val_if_fail(data_len != NULL, FALSE);
+    g_return_val_if_fail(v != NULL, FALSE);
+    g_return_val_if_fail(data_len != NULL, FALSE);
 
-  str_len = strlen(str);
+    str_len = strlen(str);
 
-  /* Since no whitespace is allowed and hex encoding is 2 text chars
-     per binary char, the result must be half the input size and the
-     input size must be even. */
-  if((str_len % 2) != 0)
-      return(FALSE);
-  *data_len = str_len / 2;
-  data = g_new0(guchar, *data_len);
+    /* Since no whitespace is allowed and hex encoding is 2 text chars
+       per binary char, the result must be half the input size and the
+       input size must be even. */
+    if ((str_len % 2) != 0)
+        return(FALSE);
+    *data_len = str_len / 2;
+    data = g_new0(guchar, *data_len);
 
-  for(j = 0, i = 0; i < str_len; i += 2, j++)
-  {
-      gchar tmpstr[3];
-      long int converted;
+    for (j = 0, i = 0; i < str_len; i += 2, j++)
+    {
+        gchar tmpstr[3];
+        long int converted;
 
-      tmpstr[0] = str[i];
-      tmpstr[1] = str[i + 1];
-      tmpstr[2] = '\0';
+        tmpstr[0] = str[i];
+        tmpstr[1] = str[i + 1];
+        tmpstr[2] = '\0';
 
-      converted = strtol(tmpstr, NULL, 16);
+        converted = strtol(tmpstr, NULL, 16);
 
-      data[j] = (unsigned char)converted;
-  }
+        data[j] = (unsigned char)converted;
+    }
 
-  *v = data;
+    *v = data;
 
-  return(TRUE);
+    return(TRUE);
 }
 
 kvp_value*
@@ -290,7 +295,7 @@
 
     text = dom_tree_to_text(node);
 
-    if(string_to_binary(text, &val, &len))
+    if (string_to_binary(text, &val, &len))
     {
         ret = kvp_value_new_binary_nc(val, len);
     }
@@ -298,7 +303,7 @@
     {
         PERR("string_to_binary returned false");
     }
-    
+
     g_free(text);
 
     return ret;
@@ -311,15 +316,15 @@
     xmlNodePtr mark;
     kvp_value *ret = NULL;
 
-    for(mark = node->xmlChildrenNode; mark; mark = mark->next)
+    for (mark = node->xmlChildrenNode; mark; mark = mark->next)
     {
         kvp_value *new_val;
 
         if (safe_strcmp ((char*)mark->name, "text") == 0)
-          continue;
+            continue;
 
         new_val = dom_tree_to_kvp_value(mark);
-        if(new_val)
+        if (new_val)
         {
             list = g_list_append(list, (gpointer)new_val);
         }
@@ -338,13 +343,13 @@
 
     frame = dom_tree_to_kvp_frame(node);
 
-    if(frame)
+    if (frame)
     {
         ret = kvp_value_new_frame(frame);
     }
 
     kvp_frame_delete(frame);
-    
+
     return ret;
 }
 
@@ -355,7 +360,8 @@
     kvp_value* (*converter)(xmlNodePtr node);
 };
 
-struct kvp_val_converter val_converters[] = {
+struct kvp_val_converter val_converters[] =
+{
     { "integer", dom_tree_to_integer_kvp_value },
     { "double", dom_tree_to_double_kvp_value },
     { "numeric", dom_tree_to_numeric_kvp_value },
@@ -367,7 +373,7 @@
     { "frame", dom_tree_to_frame_kvp_value },
     { 0, 0 },
 };
-    
+
 kvp_value*
 dom_tree_to_kvp_value(xmlNodePtr node)
 {
@@ -377,29 +383,29 @@
     kvp_value *ret = NULL;
 
     xml_type = xmlGetProp(node, BAD_CAST "type");
-    if(xml_type)
+    if (xml_type)
     {
         type = g_strdup ((char*) xml_type);
         xmlFree (xml_type);
     }
     else
-      type = NULL;
+        type = NULL;
 
-    for(mark = val_converters; mark->tag; mark++)
+    for (mark = val_converters; mark->tag; mark++)
     {
-        if(safe_strcmp(type, mark->tag) == 0)
+        if (safe_strcmp(type, mark->tag) == 0)
         {
             ret = (mark->converter)(node);
         }
     }
 
-    if(!mark->tag)
+    if (!mark->tag)
     {
         /* FIXME: deal with unknown type tag here */
     }
 
     g_free(type);
-    
+
     return ret;
 }
 
@@ -411,34 +417,34 @@
     g_return_val_if_fail(node, FALSE);
     g_return_val_if_fail(frame, FALSE);
 
-    for(mark = node->xmlChildrenNode; mark; mark = mark->next)
+    for (mark = node->xmlChildrenNode; mark; mark = mark->next)
     {
-        if(safe_strcmp((char*)mark->name, "slot") == 0)
+        if (safe_strcmp((char*)mark->name, "slot") == 0)
         {
             xmlNodePtr mark2;
             gchar *key = NULL;
             kvp_value *val = NULL;
 
-            for(mark2 = mark->xmlChildrenNode; mark2; mark2 = mark2->next)
+            for (mark2 = mark->xmlChildrenNode; mark2; mark2 = mark2->next)
             {
-                if(safe_strcmp((char*)mark2->name, "slot:key") == 0)
+                if (safe_strcmp((char*)mark2->name, "slot:key") == 0)
                 {
                     key = dom_tree_to_text(mark2);
                 }
-                else if(safe_strcmp((char*)mark2->name, "slot:value") == 0)
+                else if (safe_strcmp((char*)mark2->name, "slot:value") == 0)
                 {
                     val = dom_tree_to_kvp_value(mark2);
                 }
                 else
                 {
-                    /* FIXME: should put some error here. 
+                    /* FIXME: should put some error here.
                      *        But ignore text type! */
                 }
             }
 
-            if(key)
+            if (key)
             {
-                if(val)
+                if (val)
                 {
                     kvp_frame_set_slot_nc(frame, key, val);
                 }
@@ -459,7 +465,7 @@
 dom_tree_to_kvp_frame(xmlNodePtr node)
 {
     kvp_frame *ret;
-    
+
     g_return_val_if_fail(node, NULL);
 
     ret = kvp_frame_new();
@@ -476,38 +482,38 @@
 gchar *
 dom_tree_to_text(xmlNodePtr tree)
 {
-  /* Expect *only* text and comment sibling nodes in the given tree --
-     which actually may only be a "list".  i.e. if you're trying to
-     extract bar from <foo>bar</foo>, pass in <foo>->xmlChildrenNode
-     to this function.  This expectation is different from the rest of
-     the dom_tree_to_* converters...
+    /* Expect *only* text and comment sibling nodes in the given tree --
+       which actually may only be a "list".  i.e. if you're trying to
+       extract bar from <foo>bar</foo>, pass in <foo>->xmlChildrenNode
+       to this function.  This expectation is different from the rest of
+       the dom_tree_to_* converters...
 
-     Ignores comment nodes and collapse text nodes into one string.
-     Returns NULL if expectations are unsatisfied.
-  */
-  gchar *result;
-  gchar *temp;
+       Ignores comment nodes and collapse text nodes into one string.
+       Returns NULL if expectations are unsatisfied.
+    */
+    gchar *result;
+    gchar *temp;
 
-  g_return_val_if_fail(tree, NULL);
+    g_return_val_if_fail(tree, NULL);
 
-  /* no nodes means it's an empty string text */
-  if(!tree->xmlChildrenNode)
-  {
-      DEBUG("No children");
-      return g_strdup("");
-  }
+    /* no nodes means it's an empty string text */
+    if (!tree->xmlChildrenNode)
+    {
+        DEBUG("No children");
+        return g_strdup("");
+    }
 
-  temp = (char*)xmlNodeListGetString (NULL, tree->xmlChildrenNode, TRUE);
-  if (!temp) 
-  {
-    DEBUG("Null string");
-    return NULL;
-  }
+    temp = (char*)xmlNodeListGetString (NULL, tree->xmlChildrenNode, TRUE);
+    if (!temp)
+    {
+        DEBUG("Null string");
+        return NULL;
+    }
 
-  DEBUG("node string [%s]", (temp == NULL ? "(null)" : temp));
-  result = g_strdup (temp);
-  xmlFree (temp);
-  return result;
+    DEBUG("node string [%s]", (temp == NULL ? "(null)" : temp));
+    result = g_strdup (temp);
+    xmlFree (temp);
+    return result;
 }
 
 gnc_numeric*
@@ -515,12 +521,12 @@
 {
     gchar *content = dom_tree_to_text(node);
     gnc_numeric *ret;
-    if(!content)
+    if (!content)
         return NULL;
 
     ret = g_new(gnc_numeric, 1);
 
-    if(string_to_gnc_numeric(content, ret))
+    if (string_to_gnc_numeric(content, ret))
     {
         g_free(content);
         return ret;
@@ -545,219 +551,249 @@
 Timespec
 dom_tree_to_timespec(xmlNodePtr node)
 {
-  /* Turn something like this
-     
-     <date-posted>
-       <s>Mon, 05 Jun 2000 23:16:19 -0500</s>
-       <ns>658864000</ns>
-     </date-posted>
-     
-     into a Timespec.  If this returns FALSE, the effects on *ts are
-     undefined.  The XML is valid if it has at least one of <s> or <ns>
-     and no more than one of each.  Order is irrelevant. */
+    /* Turn something like this
 
-  Timespec ret;
-  gboolean seen_s = FALSE;
-  gboolean seen_ns = FALSE;
-  xmlNodePtr n;
+       <date-posted>
+         <s>Mon, 05 Jun 2000 23:16:19 -0500</s>
+         <ns>658864000</ns>
+       </date-posted>
 
-  
-  ret.tv_sec = 0;
-  ret.tv_nsec = 0;
-  for(n = node->xmlChildrenNode; n; n = n->next) {
-    switch(n->type) {
-    case XML_COMMENT_NODE:
-    case XML_TEXT_NODE:
-      break;
-    case XML_ELEMENT_NODE:
-      if(safe_strcmp("ts:date", (char*)n->name) == 0) {
-        if(seen_s)
+       into a Timespec.  If this returns FALSE, the effects on *ts are
+       undefined.  The XML is valid if it has at least one of <s> or <ns>
+       and no more than one of each.  Order is irrelevant. */
+
+    Timespec ret;
+    gboolean seen_s = FALSE;
+    gboolean seen_ns = FALSE;
+    xmlNodePtr n;
+
+
+    ret.tv_sec = 0;
+    ret.tv_nsec = 0;
+    for (n = node->xmlChildrenNode; n; n = n->next)
+    {
+        switch (n->type)
         {
+        case XML_COMMENT_NODE:
+        case XML_TEXT_NODE:
+            break;
+        case XML_ELEMENT_NODE:
+            if (safe_strcmp("ts:date", (char*)n->name) == 0)
+            {
+                if (seen_s)
+                {
+                    return timespec_failure(ret);
+                }
+                else
+                {
+                    gchar *content = dom_tree_to_text(n);
+                    if (!content)
+                    {
+                        return timespec_failure(ret);
+                    }
+
+                    if (!string_to_timespec_secs(content, &ret))
+                    {
+                        g_free(content);
+                        return timespec_failure(ret);
+                    }
+                    g_free(content);
+                    seen_s = TRUE;
+                }
+            }
+            else if (safe_strcmp("ts:ns", (char*)n->name) == 0)
+            {
+                if (seen_ns)
+                {
+                    return timespec_failure(ret);
+                }
+                else
+                {
+                    gchar *content = dom_tree_to_text(n);
+                    if (!content)
+                    {
+                        return timespec_failure(ret);
+                    }
+
+                    if (!string_to_timespec_nsecs(content, &ret))
+                    {
+                        g_free(content);
+                        return timespec_failure(ret);
+                    }
+                    g_free(content);
+                    seen_ns = TRUE;
+                }
+            }
+            break;
+        default:
+            PERR("unexpected sub-node.");
             return timespec_failure(ret);
+            break;
         }
-        else
-        {
-          gchar *content = dom_tree_to_text(n);
-          if(!content)
-          {
-              return timespec_failure(ret);
-          }
-          
-          if(!string_to_timespec_secs(content, &ret)) {
-              g_free(content);
-              return timespec_failure(ret);
-          }
-          g_free(content);
-          seen_s = TRUE;
-        }
-      }
-      else if(safe_strcmp("ts:ns", (char*)n->name) == 0) {
-        if(seen_ns)
-        {
-            return timespec_failure(ret);
-        }
-        else
-        {
-          gchar *content = dom_tree_to_text(n);
-          if(!content)
-          {
-              return timespec_failure(ret);
-          }
-          
-          if(!string_to_timespec_nsecs(content, &ret)) {
-              g_free(content);
-              return timespec_failure(ret);
-          }
-          g_free(content);
-          seen_ns = TRUE;
-        }
-      }
-      break;
-    default:
-      PERR("unexpected sub-node.");
-      return timespec_failure(ret);
-      break;
     }
-  }
 
-  if(!seen_s)
-  {
-      PERR("no ts:date node found.");
-      return timespec_failure(ret);
-  }
-  
-  return ret;
+    if (!seen_s)
+    {
+        PERR("no ts:date node found.");
+        return timespec_failure(ret);
+    }
+
+    return ret;
 }
 
 GDate*
 dom_tree_to_gdate(xmlNodePtr node)
 {
-  /* Turn something like this
+    /* Turn something like this
 
-     <sx:startdate>
-         <gdate>2001-04-03</gdate>
-     </sx:startdate>
+       <sx:startdate>
+           <gdate>2001-04-03</gdate>
+       </sx:startdate>
 
-     into a GDate.  If the xml is invalid, returns NULL. */
+       into a GDate.  If the xml is invalid, returns NULL. */
 
-  GDate *ret;
-  gboolean seen_date = FALSE;
-  xmlNodePtr n;
+    GDate *ret;
+    gboolean seen_date = FALSE;
+    xmlNodePtr n;
 
-  /* creates an invalid date */
-  ret = g_date_new();
+    /* creates an invalid date */
+    ret = g_date_new();
 
-  for(n = node->xmlChildrenNode; n; n = n->next) {
-    switch(n->type) {
-    case XML_COMMENT_NODE:
-    case XML_TEXT_NODE:
-      break;
-    case XML_ELEMENT_NODE:
-      if(safe_strcmp("gdate", (char*)n->name) == 0) {
-        if(seen_date) {
-            goto failure;
-        } else {
-          gchar *content = dom_tree_to_text(n);
-          gint year, month, day;
-          if(!content) {
-              goto failure;
-          }
+    for (n = node->xmlChildrenNode; n; n = n->next)
+    {
+        switch (n->type)
+        {
+        case XML_COMMENT_NODE:
+        case XML_TEXT_NODE:
+            break;
+        case XML_ELEMENT_NODE:
+            if (safe_strcmp("gdate", (char*)n->name) == 0)
+            {
+                if (seen_date)
+                {
+                    goto failure;
+                }
+                else
+                {
+                    gchar *content = dom_tree_to_text(n);
+                    gint year, month, day;
+                    if (!content)
+                    {
+                        goto failure;
+                    }
 
-          if(sscanf(content, "%d-%d-%d", &year, &month, &day ) != 3) {
-            g_free(content);
+                    if (sscanf(content, "%d-%d-%d", &year, &month, &day ) != 3)
+                    {
+                        g_free(content);
+                        goto failure;
+                    }
+                    g_free(content);
+                    seen_date = TRUE;
+                    g_date_set_dmy( ret, day, month, year );
+                    if ( !g_date_valid( ret ) )
+                    {
+                        PWARN("invalid date");
+                        goto failure;
+                    }
+                }
+            }
+            break;
+        default:
+            PERR("unexpected sub-node.");
             goto failure;
-          }
-          g_free(content);
-          seen_date = TRUE;
-          g_date_set_dmy( ret, day, month, year );
-          if( !g_date_valid( ret ) ) {
-            PWARN("invalid date");
-            goto failure;
-          }
         }
-      }
-      break;
-    default:
-      PERR("unexpected sub-node.");
-      goto failure;
     }
-  }
 
-  if(!seen_date) {
-      PWARN("no gdate node found.");
-      goto failure;
-  }
+    if (!seen_date)
+    {
+        PWARN("no gdate node found.");
+        goto failure;
+    }
 
-  return ret;
+    return ret;
 failure:
-  g_date_free( ret );
-  return NULL;
+    g_date_free( ret );
+    return NULL;
 }
 
 
 gnc_commodity *
 dom_tree_to_commodity_ref_no_engine(xmlNodePtr node, QofBook *book)
 {
-  /* Turn something like this
-     
-     <currency>
-       <cmdty:space>NASDAQ</cmdty:space>
-       <cmdty:id>LNUX</cmdty:space>
-     </currency>
-     
-     into a gnc_commodity*, returning NULL on failure.  Both sub-nodes
-     are required, though for now, order is irrelevant. */
+    /* Turn something like this
 
-  gnc_commodity *c = NULL;
-  gchar *space_str = NULL;
-  gchar *id_str = NULL;
-  xmlNodePtr n;
+       <currency>
+         <cmdty:space>NASDAQ</cmdty:space>
+         <cmdty:id>LNUX</cmdty:space>
+       </currency>
 
-  if(!node) return NULL;
-  if(!node->xmlChildrenNode) return NULL;
-  
-  for(n = node->xmlChildrenNode; n; n = n->next) {
-    switch(n->type) {
-    case XML_COMMENT_NODE:
-    case XML_TEXT_NODE:
-      break;
-    case XML_ELEMENT_NODE:
-      if(safe_strcmp("cmdty:space", (char*)n->name) == 0) {
-        if(space_str) {
-          return NULL;
-        } else {
-          gchar *content = dom_tree_to_text(n);
-          if(!content) return NULL;
-          space_str = content;
+       into a gnc_commodity*, returning NULL on failure.  Both sub-nodes
+       are required, though for now, order is irrelevant. */
+
+    gnc_commodity *c = NULL;
+    gchar *space_str = NULL;
+    gchar *id_str = NULL;
+    xmlNodePtr n;
+
+    if (!node) return NULL;
+    if (!node->xmlChildrenNode) return NULL;
+
+    for (n = node->xmlChildrenNode; n; n = n->next)
+    {
+        switch (n->type)
+        {
+        case XML_COMMENT_NODE:
+        case XML_TEXT_NODE:
+            break;
+        case XML_ELEMENT_NODE:
+            if (safe_strcmp("cmdty:space", (char*)n->name) == 0)
+            {
+                if (space_str)
+                {
+                    return NULL;
+                }
+                else
+                {
+                    gchar *content = dom_tree_to_text(n);
+                    if (!content) return NULL;
+                    space_str = content;
+                }
+            }
+            else if (safe_strcmp("cmdty:id", (char*)n->name) == 0)
+            {
+                if (id_str)
+                {
+                    return NULL;
+                }
+                else
+                {
+                    gchar *content = dom_tree_to_text(n);
+                    if (!content) return NULL;
+                    id_str = content;
+                }
+            }
+            break;
+        default:
+            PERR("unexpected sub-node.");
+            return NULL;
+            break;
         }
-      } else if(safe_strcmp("cmdty:id", (char*)n->name) == 0) {
-        if(id_str) {
-          return NULL;
-        } else {
-          gchar *content = dom_tree_to_text(n);
-          if(!content) return NULL;
-          id_str = content;
-        }
-      }
-      break;
-    default:
-      PERR("unexpected sub-node.");
-      return NULL;
-      break;
     }
-  }
-  if(!(space_str && id_str)) {
-    c = NULL;
-  } else {
-    g_strstrip(space_str);
-    g_strstrip(id_str);
-    c = gnc_commodity_new(book, NULL, space_str, id_str, NULL, 0);
-  }
+    if (!(space_str && id_str))
+    {
+        c = NULL;
+    }
+    else
+    {
+        g_strstrip(space_str);
+        g_strstrip(id_str);
+        c = gnc_commodity_new(book, NULL, space_str, id_str, NULL, 0);
+    }
 
-  g_free(space_str);
-  g_free(id_str);
+    g_free(space_str);
+    g_free(id_str);
 
-  return c;
+    return c;
 }
 
 gnc_commodity*
@@ -790,7 +826,7 @@
 static inline void
 dom_tree_handlers_reset(struct dom_tree_handler *handlers)
 {
-    for(;handlers->tag != NULL; handlers++)
+    for (; handlers->tag != NULL; handlers++)
     {
         handlers->gotten = 0;
     }
@@ -800,9 +836,9 @@
 dom_tree_handlers_all_gotten_p(struct dom_tree_handler *handlers)
 {
     gboolean ret = TRUE;
-    for(;handlers->tag != NULL;handlers++)
+    for (; handlers->tag != NULL; handlers++)
     {
-        if(handlers->required && ! handlers->gotten)
+        if (handlers->required && ! handlers->gotten)
         {
             PERR("Not defined and it should be: %s",
                  handlers->tag ? handlers->tag : "(null)");
@@ -817,9 +853,9 @@
 gnc_xml_set_data(const gchar* tag, xmlNodePtr node, gpointer item,
                  struct dom_tree_handler *handlers)
 {
-    for(;handlers->tag != NULL; handlers++)
+    for (; handlers->tag != NULL; handlers++)
     {
-        if(safe_strcmp(tag, handlers->tag) == 0)
+        if (safe_strcmp(tag, handlers->tag) == 0)
         {
             (handlers->handler)(node, item);
             handlers->gotten = TRUE;
@@ -827,7 +863,7 @@
         }
     }
 
-    if(!handlers->tag) 
+    if (!handlers->tag)
     {
         PERR("Unhandled tag: %s",
              tag ? tag : "(null)");
@@ -846,13 +882,13 @@
 
     dom_tree_handlers_reset(handlers);
 
-    for(achild = node->xmlChildrenNode; achild; achild = achild->next)
+    for (achild = node->xmlChildrenNode; achild; achild = achild->next)
     {
         /* ignore stray text nodes */
         if (safe_strcmp ((char*)achild->name, "text") == 0)
-          continue;
+            continue;
 
-        if(!gnc_xml_set_data((char*)achild->name, achild, data, handlers))
+        if (!gnc_xml_set_data((char*)achild->name, achild, data, handlers))
         {
             PERR("gnc_xml_set_data failed");
             successful = FALSE;
@@ -860,7 +896,7 @@
         }
     }
 
-    if(!dom_tree_handlers_all_gotten_p(handlers))
+    if (!dom_tree_handlers_all_gotten_p(handlers))
     {
         PERR("didn't find all of the expected tags in the input");
         successful = FALSE;
@@ -873,10 +909,10 @@
 dom_tree_valid_timespec (Timespec *ts, const xmlChar *name)
 {
 
-  if (ts->tv_sec || ts->tv_nsec)
-    return TRUE;
+    if (ts->tv_sec || ts->tv_nsec)
+        return TRUE;
 
-  g_warning("Invalid timestamp in data file.  Look for a '%s' entry "
-	    "with a date of 1969-12-31 or 1970-01-01.", name);
-  return FALSE;
+    g_warning("Invalid timestamp in data file.  Look for a '%s' entry "
+              "with a date of 1969-12-31 or 1970-01-01.", name);
+    return FALSE;
 }

Modified: gnucash/trunk/src/backend/xml/sixtp-parsers.h
===================================================================
--- gnucash/trunk/src/backend/xml/sixtp-parsers.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/sixtp-parsers.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -28,7 +28,7 @@
 #include "sixtp.h"
 
 /* Create a parser that will turn the entire sub-tree into a DOM tree
-   an pass it in as (don't put anything into parent_data) 
+   an pass it in as (don't put anything into parent_data)
    you must deal with the xml tree in *result.
 */
 sixtp* sixtp_dom_parser_new(sixtp_end_handler ender,

Modified: gnucash/trunk/src/backend/xml/sixtp-stack.c
===================================================================
--- gnucash/trunk/src/backend/xml/sixtp-stack.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/sixtp-stack.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -27,26 +27,26 @@
 #include "sixtp-stack.h"
 
 void
-sixtp_stack_frame_destroy(sixtp_stack_frame *sf) 
+sixtp_stack_frame_destroy(sixtp_stack_frame *sf)
 {
-  GSList *lp;
+    GSList *lp;
 
-  /* cleanup all the child data */
-  for(lp = sf->data_from_children; lp; lp = lp->next) 
-  {
-    sixtp_child_result_destroy((sixtp_child_result *) lp->data);
-  }
-  g_slist_free(sf->data_from_children);
-  sf->data_from_children = NULL;
+    /* cleanup all the child data */
+    for (lp = sf->data_from_children; lp; lp = lp->next)
+    {
+        sixtp_child_result_destroy((sixtp_child_result *) lp->data);
+    }
+    g_slist_free(sf->data_from_children);
+    sf->data_from_children = NULL;
 
-  g_free(sf);
+    g_free(sf);
 }
 
 sixtp_stack_frame*
 sixtp_stack_frame_new(sixtp* next_parser, char *tag)
 {
     sixtp_stack_frame* new_frame;
-    
+
     new_frame = g_new0(sixtp_stack_frame, 1);
     new_frame->parser = next_parser;
     new_frame->tag = tag;
@@ -59,60 +59,60 @@
 }
 
 void
-sixtp_stack_frame_print(sixtp_stack_frame *sf, gint indent, FILE *f) 
+sixtp_stack_frame_print(sixtp_stack_frame *sf, gint indent, FILE *f)
 {
-  gchar *is = g_strnfill(indent, ' ');
+    gchar *is = g_strnfill(indent, ' ');
 
-  fprintf(f, "%s(stack-frame %p\n", is, sf);
-  fprintf(f, "%s             (line %d) (col %d)\n", is, sf->line, sf->col );
-  fprintf(f, "%s             (parser %p)\n", is, sf->parser);
-  fprintf(f, "%s             (tag %s)\n", is, sf->tag ? sf->tag : "(null)");
-  fprintf(f, "%s             (data-for-children %p)\n", is,
-          sf->data_for_children);
+    fprintf(f, "%s(stack-frame %p\n", is, sf);
+    fprintf(f, "%s             (line %d) (col %d)\n", is, sf->line, sf->col );
+    fprintf(f, "%s             (parser %p)\n", is, sf->parser);
+    fprintf(f, "%s             (tag %s)\n", is, sf->tag ? sf->tag : "(null)");
+    fprintf(f, "%s             (data-for-children %p)\n", is,
+            sf->data_for_children);
 
-  {
-    GSList *lp;
-    fprintf(f, "%s             (data-from-children", is);
-    for(lp = sf->data_from_children; lp; lp = lp->next) 
     {
-      fputc(' ', f);
-      sixtp_child_result_print((sixtp_child_result *) lp->data, f);
+        GSList *lp;
+        fprintf(f, "%s             (data-from-children", is);
+        for (lp = sf->data_from_children; lp; lp = lp->next)
+        {
+            fputc(' ', f);
+            sixtp_child_result_print((sixtp_child_result *) lp->data, f);
+        }
+        fprintf(f, ")\n");
     }
-    fprintf(f, ")\n");
-  }
 
-  fprintf(f, "%s             (frame-data %p))\n", is, sf->frame_data);
-  fflush(f);
-  g_free(is);
+    fprintf(f, "%s             (frame-data %p))\n", is, sf->frame_data);
+    fflush(f);
+    g_free(is);
 }
 
 GSList*
-sixtp_pop_and_destroy_frame(GSList *frame_stack) 
+sixtp_pop_and_destroy_frame(GSList *frame_stack)
 {
-  sixtp_stack_frame *dead_frame = (sixtp_stack_frame *) frame_stack->data;
-  GSList* result;
+    sixtp_stack_frame *dead_frame = (sixtp_stack_frame *) frame_stack->data;
+    GSList* result;
 
-  result = g_slist_next(frame_stack);
-  sixtp_stack_frame_destroy(dead_frame);
-  g_slist_free_1(frame_stack);
-  return(result);
+    result = g_slist_next(frame_stack);
+    sixtp_stack_frame_destroy(dead_frame);
+    g_slist_free_1(frame_stack);
+    return(result);
 }
 
 void
-sixtp_print_frame_stack(GSList *stack, FILE *f) 
+sixtp_print_frame_stack(GSList *stack, FILE *f)
 {
-  /* first, some debugging output */
-  GSList *printcopy = g_slist_reverse(g_slist_copy(stack));
-  GSList *lp;
-  int indent = 0;
-  
-  for(lp = printcopy; lp; lp = lp->next) 
-  {
-    sixtp_stack_frame *frame = (sixtp_stack_frame *) lp->data;
-    sixtp_stack_frame_print(frame, indent, f);
-    indent += 2;
-  }
+    /* first, some debugging output */
+    GSList *printcopy = g_slist_reverse(g_slist_copy(stack));
+    GSList *lp;
+    int indent = 0;
 
+    for (lp = printcopy; lp; lp = lp->next)
+    {
+        sixtp_stack_frame *frame = (sixtp_stack_frame *) lp->data;
+        sixtp_stack_frame_print(frame, indent, f);
+        indent += 2;
+    }
+
 }
 
 
@@ -135,44 +135,44 @@
     ret->data.global_data = global_data;
 
     ret->top_frame = sixtp_stack_frame_new(initial_parser, NULL);
-    
+
     ret->top_frame_data = top_level_data;
 
     ret->data.stack = g_slist_prepend(ret->data.stack,
                                       (gpointer) ret->top_frame);
 
-    if(initial_parser->start_handler)
+    if (initial_parser->start_handler)
     {
-        if(!initial_parser->start_handler(NULL,
-                                          &ret->top_frame_data,
-                                          &ret->data.global_data,
-                                          &ret->top_frame->data_for_children,
-                                          &ret->top_frame->frame_data,
-                                          NULL, NULL))
+        if (!initial_parser->start_handler(NULL,
+                                           &ret->top_frame_data,
+                                           &ret->data.global_data,
+                                           &ret->top_frame->data_for_children,
+                                           &ret->top_frame->frame_data,
+                                           NULL, NULL))
         {
             sixtp_handle_catastrophe(&ret->data);
             sixtp_context_destroy(ret);
             return NULL;
         }
     }
-    
+
     return ret;
 }
 
 void
 sixtp_context_run_end_handler(sixtp_parser_context* ctxt)
 {
-    if(ctxt->top_frame->parser->end_handler)
+    if (ctxt->top_frame->parser->end_handler)
     {
         ctxt->data.parsing_ok &=
-        ctxt->top_frame->parser->end_handler(
-            ctxt->top_frame->data_for_children,
-            ctxt->top_frame->data_from_children,
-            NULL,
-            ctxt->top_frame_data,
-            ctxt->data.global_data,
-            &ctxt->top_frame->frame_data,
-            NULL);
+            ctxt->top_frame->parser->end_handler(
+                ctxt->top_frame->data_for_children,
+                ctxt->top_frame->data_from_children,
+                NULL,
+                ctxt->top_frame_data,
+                ctxt->data.global_data,
+                &ctxt->top_frame->frame_data,
+                NULL);
     }
 }
 
@@ -182,7 +182,7 @@
     sixtp_stack_frame_destroy(context->top_frame);
     g_slist_free(context->data.stack);
     context->data.saxParserCtxt->userData = NULL;
-    context->data.saxParserCtxt->sax = NULL;    
+    context->data.saxParserCtxt->sax = NULL;
     xmlFreeParserCtxt(context->data.saxParserCtxt);
     context->data.saxParserCtxt = NULL;
     g_free(context);

Modified: gnucash/trunk/src/backend/xml/sixtp-stack.h
===================================================================
--- gnucash/trunk/src/backend/xml/sixtp-stack.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/sixtp-stack.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -28,19 +28,20 @@
 
 #include "sixtp.h"
 
-typedef struct sixtp_stack_frame {
-  sixtp *parser;
-  gchar *tag;
-  gpointer data_for_children;
-  GSList *data_from_children; /* in reverse chronological order */
-  gpointer frame_data;
+typedef struct sixtp_stack_frame
+{
+    sixtp *parser;
+    gchar *tag;
+    gpointer data_for_children;
+    GSList *data_from_children; /* in reverse chronological order */
+    gpointer frame_data;
 
-  /* Line and column [of the start tag]; set during parsing. */
-  int line;
-  int col;
+    /* Line and column [of the start tag]; set during parsing. */
+    int line;
+    int col;
 } sixtp_stack_frame;
 
-struct _sixtp_parser_context_struct 
+struct _sixtp_parser_context_struct
 {
     xmlSAXHandler handler;
     sixtp_sax_data data;

Modified: gnucash/trunk/src/backend/xml/sixtp-to-dom-parser.c
===================================================================
--- gnucash/trunk/src/backend/xml/sixtp-to-dom-parser.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/sixtp-to-dom-parser.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -43,7 +43,7 @@
     xmlNodePtr thing;
     gchar** atptr = attrs;
 
-    if(parent_data == NULL)
+    if (parent_data == NULL)
     {
         thing = xmlNewNode(global_namespace, BAD_CAST tag);
         /* only publish the result if we're the parent */
@@ -59,9 +59,9 @@
     }
     *data_for_children = thing;
 
-    if(attrs != NULL)
+    if (attrs != NULL)
     {
-        while(*atptr != 0)
+        while (*atptr != 0)
         {
             xmlSetProp(thing, BAD_CAST atptr[0], BAD_CAST atptr[1]);
             atptr += 2;
@@ -79,14 +79,14 @@
                  gpointer *result,
                  const gchar *tag)
 {
-  if(*result) xmlFreeNode(*result);
+    if (*result) xmlFreeNode(*result);
 }
 
 static gboolean dom_chars_handler(
     GSList *sibling_data, gpointer parent_data, gpointer global_data,
     gpointer *result, const char *text, int length)
 {
-    if(length > 0)
+    if (length > 0)
     {
         xmlNodeAddContentLen((xmlNodePtr)parent_data, BAD_CAST text, length);
     }
@@ -101,29 +101,29 @@
     sixtp *top_level;
 
     g_return_val_if_fail(ender, NULL);
-    
-    if(!(top_level =
-         sixtp_set_any(sixtp_new(), FALSE,
-                       SIXTP_START_HANDLER_ID, dom_start_handler,
-                       SIXTP_CHARACTERS_HANDLER_ID, dom_chars_handler,
-                       SIXTP_END_HANDLER_ID, ender,
-                       SIXTP_FAIL_HANDLER_ID, dom_fail_handler,
-                       SIXTP_NO_MORE_HANDLERS)))
+
+    if (!(top_level =
+                sixtp_set_any(sixtp_new(), FALSE,
+                              SIXTP_START_HANDLER_ID, dom_start_handler,
+                              SIXTP_CHARACTERS_HANDLER_ID, dom_chars_handler,
+                              SIXTP_END_HANDLER_ID, ender,
+                              SIXTP_FAIL_HANDLER_ID, dom_fail_handler,
+                              SIXTP_NO_MORE_HANDLERS)))
     {
         return NULL;
     }
 
-    if(cleanup_result_by_default_func)
+    if (cleanup_result_by_default_func)
     {
-      sixtp_set_cleanup_result(top_level, cleanup_result_by_default_func);
+        sixtp_set_cleanup_result(top_level, cleanup_result_by_default_func);
     }
 
-    if(cleanup_result_by_default_func)
+    if (cleanup_result_by_default_func)
     {
-      sixtp_set_result_fail(top_level, cleanup_result_on_fail_func);
+        sixtp_set_result_fail(top_level, cleanup_result_on_fail_func);
     }
 
-    if(!sixtp_add_sub_parser(top_level, SIXTP_MAGIC_CATCHER, top_level))
+    if (!sixtp_add_sub_parser(top_level, SIXTP_MAGIC_CATCHER, top_level))
     {
         sixtp_destroy(top_level);
         return NULL;

Modified: gnucash/trunk/src/backend/xml/sixtp-utils.c
===================================================================
--- gnucash/trunk/src/backend/xml/sixtp-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/sixtp-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -51,15 +51,17 @@
 gboolean
 isspace_str(const gchar *str, int nomorethan)
 {
-  const gchar *cursor = str;
-  while(*cursor && (nomorethan != 0)) {
-    if(!isspace(*cursor)) {
-      return(FALSE);
+    const gchar *cursor = str;
+    while (*cursor && (nomorethan != 0))
+    {
+        if (!isspace(*cursor))
+        {
+            return(FALSE);
+        }
+        cursor++;
+        nomorethan--;
     }
-    cursor++;
-    nomorethan--;
-  }
-  return(TRUE);
+    return(TRUE);
 }
 
 gboolean
@@ -70,7 +72,7 @@
                                  const char *text,
                                  int length)
 {
-  return(isspace_str(text, length));
+    return(isspace_str(text, length));
 }
 
 gboolean
@@ -78,15 +80,15 @@
                          gpointer parent_data,
                          gpointer global_data,
                          gpointer *result,
-                         
+
                          const char *text,
                          int length)
 {
-  gchar *copytxt = g_strndup(text, length);
-  g_return_val_if_fail(result, FALSE);
+    gchar *copytxt = g_strndup(text, length);
+    g_return_val_if_fail(result, FALSE);
 
-  *result = copytxt;
-  return(TRUE);
+    *result = copytxt;
+    return(TRUE);
 }
 
 
@@ -99,40 +101,40 @@
                                gpointer *result,
                                const gchar *tag)
 {
-  if(data_for_children) g_free(data_for_children);
+    if (data_for_children) g_free(data_for_children);
 }
 
 gchar *
 concatenate_child_result_chars(GSList *data_from_children)
 {
-  GSList *lp;
-  gchar *name = g_strdup("");
+    GSList *lp;
+    gchar *name = g_strdup("");
 
-  g_return_val_if_fail(name, NULL);
+    g_return_val_if_fail(name, NULL);
 
-  /* child data lists are in reverse chron order */
-  data_from_children = g_slist_reverse(g_slist_copy(data_from_children));
+    /* child data lists are in reverse chron order */
+    data_from_children = g_slist_reverse(g_slist_copy(data_from_children));
 
-  for(lp = data_from_children; lp; lp = lp->next) 
-  {
-    sixtp_child_result *cr = (sixtp_child_result *) lp->data;
-    if(cr->type != SIXTP_CHILD_RESULT_CHARS) 
+    for (lp = data_from_children; lp; lp = lp->next)
     {
-      PERR ("result type is not chars");
-      g_slist_free (data_from_children);
-      g_free(name);
-      return(NULL);
-    } 
-    else 
-    {
-      char *temp;
-      temp = g_strconcat(name, (gchar *) cr->data, NULL);
-      g_free (name);
-      name = temp;
+        sixtp_child_result *cr = (sixtp_child_result *) lp->data;
+        if (cr->type != SIXTP_CHILD_RESULT_CHARS)
+        {
+            PERR ("result type is not chars");
+            g_slist_free (data_from_children);
+            g_free(name);
+            return(NULL);
+        }
+        else
+        {
+            char *temp;
+            temp = g_strconcat(name, (gchar *) cr->data, NULL);
+            g_free (name);
+            name = temp;
+        }
     }
-  }
-  g_slist_free (data_from_children);
-  return(name);
+    g_slist_free (data_from_children);
+    return(name);
 }
 
 /****************************************************************************/
@@ -142,14 +144,14 @@
 
 /*********/
 /* double
-   
+
    RLB writes:
    We have to use guile because AFAICT, libc, and C in general isn't
    smart enough to actually parse it's own output, especially not
    portably (big surprise).
 
    Linas writes:
-   I don't understand the claim; I'm just going to use 
+   I don't understand the claim; I'm just going to use
    atof or strtod to accomplish this.
 
    RLB writes: FIXME: OK, but at the very least this may cause a
@@ -159,49 +161,51 @@
  */
 
 gboolean
-string_to_double(const char *str, double *result) 
+string_to_double(const char *str, double *result)
 {
-  g_return_val_if_fail(str, FALSE);
-  g_return_val_if_fail(result, FALSE);
+    g_return_val_if_fail(str, FALSE);
+    g_return_val_if_fail(result, FALSE);
 
-#ifdef USE_GUILE_FOR_DOUBLE_CONVERSION 
-  {
-    /* FIXME: NOT THREAD SAFE - USES STATIC DATA */
-    static SCM string_to_number;
-    static gboolean ready = FALSE;
-  
-    SCM conversion_result;
-  
-    if(!ready) {
-      string_to_number = scm_c_eval_string("string->number");
-      scm_gc_protect_object(string_to_number);
-      ready = TRUE;
+#ifdef USE_GUILE_FOR_DOUBLE_CONVERSION
+    {
+        /* FIXME: NOT THREAD SAFE - USES STATIC DATA */
+        static SCM string_to_number;
+        static gboolean ready = FALSE;
+
+        SCM conversion_result;
+
+        if (!ready)
+        {
+            string_to_number = scm_c_eval_string("string->number");
+            scm_gc_protect_object(string_to_number);
+            ready = TRUE;
+        }
+
+        conversion_result = scm_call_1(string_to_number, scm_makfrom0str(str));
+        if (!conversion_result == SCM_BOOL_F)
+        {
+            return(FALSE);
+        }
+
+        *result = scm_num2dbl(conversion_result, G_STRFUNC);
     }
-    
-    conversion_result = scm_call_1(string_to_number, scm_makfrom0str(str));
-    if(!conversion_result == SCM_BOOL_F) {
-      return(FALSE);
+
+#else /* don't USE_GUILE_FOR_DOUBLE_CONVERSION */
+    {
+        char *endptr = 0x0;
+
+        /* We're just going to use plain-old libc for the double conversion.
+         * There was some question as to whether libc is accurate enough
+         * in its printf function for doubles, but I don't understand
+         * how it couldn't be ...
+         */
+
+        *result = strtod (str, &endptr);
+        if (endptr == str) return (FALSE);
     }
-  
-    *result = scm_num2dbl(conversion_result, G_STRFUNC);
-  } 
-  
-#else /* don't USE_GUILE_FOR_DOUBLE_CONVERSION */
-  {
-    char *endptr = 0x0;
-  
-    /* We're just going to use plain-old libc for the double conversion.
-     * There was some question as to whether libc is accurate enough
-     * in its printf function for doubles, but I don't understand
-     * how it couldn't be ...
-     */
-    
-    *result = strtod (str, &endptr);
-    if (endptr == str) return (FALSE);
-  } 
 #endif /* USE_GUILE_FOR_DOUBLE_CONVERSION */
 
-  return(TRUE);
+    return(TRUE);
 }
 
 /*********/
@@ -212,31 +216,32 @@
 gboolean
 string_to_gint64(const gchar *str, gint64 *v)
 {
-  /* convert a string to a gint64. only whitespace allowed before and after. */
-  long long int v_in;
-  int num_read;
+    /* convert a string to a gint64. only whitespace allowed before and after. */
+    long long int v_in;
+    int num_read;
 
-  g_return_val_if_fail(str, FALSE);
-  
-  /* must use "<" here because %n's effects aren't well defined */
-  if(sscanf(str, " " QOF_SCANF_LLD "%n", &v_in, &num_read) < 1) {
-    return(FALSE);
-  }
+    g_return_val_if_fail(str, FALSE);
 
-  /*
-   * Mac OS X version 10.1 and under has a silly bug where scanf
-   * returns bad values in num_read if there is a space before %n. It
-   * is fixed in the next release 10.2 afaik
-   */  
-  while( (*((gchar*)str + num_read)!='\0') &&
-	 isspace(*((unsigned char*)str + num_read)))
-    num_read++;
+    /* must use "<" here because %n's effects aren't well defined */
+    if (sscanf(str, " " QOF_SCANF_LLD "%n", &v_in, &num_read) < 1)
+    {
+        return(FALSE);
+    }
 
-  if (v)
-    *v = v_in;
+    /*
+     * Mac OS X version 10.1 and under has a silly bug where scanf
+     * returns bad values in num_read if there is a space before %n. It
+     * is fixed in the next release 10.2 afaik
+     */
+    while ( (*((gchar*)str + num_read) != '\0') &&
+            isspace(*((unsigned char*)str + num_read)))
+        num_read++;
 
-  if(!isspace_str(str + num_read, -1)) return(FALSE);
-  return(TRUE);
+    if (v)
+        *v = v_in;
+
+    if (!isspace_str(str + num_read, -1)) return(FALSE);
+    return(TRUE);
 }
 
 /*********/
@@ -246,23 +251,24 @@
 gboolean
 string_to_gint32(const gchar *str, gint32 *v)
 {
-  /* convert a string to a gint32. only whitespace allowed before and after. */
-  int num_read;
-  int v_in;
+    /* convert a string to a gint32. only whitespace allowed before and after. */
+    int num_read;
+    int v_in;
 
-  /* must use "<" here because %n's effects aren't well defined */
-  if(sscanf(str, " %d%n", &v_in, &num_read) < 1) {
-    return(FALSE);
-  }
-  while( (*((gchar*)str + num_read)!='\0') &&
-	 isspace(*((unsigned char*)str + num_read)))
-    num_read++;
+    /* must use "<" here because %n's effects aren't well defined */
+    if (sscanf(str, " %d%n", &v_in, &num_read) < 1)
+    {
+        return(FALSE);
+    }
+    while ( (*((gchar*)str + num_read) != '\0') &&
+            isspace(*((unsigned char*)str + num_read)))
+        num_read++;
 
-  if (v)
-    *v = v_in;
+    if (v)
+        *v = v_in;
 
-  if(!isspace_str(str + num_read, -1)) return(FALSE);
-  return(TRUE);
+    if (!isspace_str(str + num_read, -1)) return(FALSE);
+    return(TRUE);
 }
 
 /************/
@@ -272,55 +278,63 @@
 gboolean
 hex_string_to_binary(const gchar *str,  void **v, guint64 *data_len)
 {
-  /* Convert a hex string to binary.  No whitespace allowed. */
-  const gchar *cursor = str;
-  guint64 str_len;
-  gboolean error = FALSE;
-  
-  g_return_val_if_fail(str, FALSE);
-  g_return_val_if_fail(v, FALSE);
-  g_return_val_if_fail(data_len, FALSE);
+    /* Convert a hex string to binary.  No whitespace allowed. */
+    const gchar *cursor = str;
+    guint64 str_len;
+    gboolean error = FALSE;
 
-  str_len = strlen(str);
-  /* Since no whitespace is allowed and hex encoding is 2 text chars
-     per binary char, the result must be half the input size and the
-     input size must be even. */
-  if((str_len % 2) != 0) return(FALSE);
-  *data_len = 0;
-  *v = g_new0(char, str_len / 2);
-  
-  g_return_val_if_fail(*v, FALSE);
+    g_return_val_if_fail(str, FALSE);
+    g_return_val_if_fail(v, FALSE);
+    g_return_val_if_fail(data_len, FALSE);
 
-  while(*cursor && *(cursor + 1)) {
-    gchar tmpstr[2];
-    int tmpint;
+    str_len = strlen(str);
+    /* Since no whitespace is allowed and hex encoding is 2 text chars
+       per binary char, the result must be half the input size and the
+       input size must be even. */
+    if ((str_len % 2) != 0) return(FALSE);
+    *data_len = 0;
+    *v = g_new0(char, str_len / 2);
 
-    if(isspace(*cursor) || isspace(*(cursor + 1))) {
-      error = TRUE;
-    } else {
-      int num_read;
-      tmpstr[0] = *cursor;
-      tmpstr[0] = *(cursor + 1);
-      
-      if((sscanf(tmpstr, "%x%n", &tmpint, &num_read) < 1)
-         || (num_read != 2)) {
-        error = TRUE;
-      } else {
-        *((gchar *) (v + *data_len)) = tmpint;
-        *data_len += 1;
-        cursor += 2;
-      }
+    g_return_val_if_fail(*v, FALSE);
+
+    while (*cursor && *(cursor + 1))
+    {
+        gchar tmpstr[2];
+        int tmpint;
+
+        if (isspace(*cursor) || isspace(*(cursor + 1)))
+        {
+            error = TRUE;
+        }
+        else
+        {
+            int num_read;
+            tmpstr[0] = *cursor;
+            tmpstr[0] = *(cursor + 1);
+
+            if ((sscanf(tmpstr, "%x%n", &tmpint, &num_read) < 1)
+                    || (num_read != 2))
+            {
+                error = TRUE;
+            }
+            else
+            {
+                *((gchar *) (v + *data_len)) = tmpint;
+                *data_len += 1;
+                cursor += 2;
+            }
+        }
     }
-  }
 
-  if(error || (*data_len != (str_len / 2))) {
-    g_free(*v);
-    *v = NULL;
-    *data_len = 0;
-    return(FALSE);
-  }
+    if (error || (*data_len != (str_len / 2)))
+    {
+        g_free(*v);
+        *v = NULL;
+        *data_len = 0;
+        return(FALSE);
+    }
 
-  return(TRUE);
+    return(TRUE);
 }
 
 /***************************************************************************/
@@ -351,31 +365,31 @@
                                  gpointer parent_data,
                                  gpointer global_data,
                                  gpointer *result,
-                                 const gchar *tag) 
+                                 const gchar *tag)
 {
-  gchar *txt = NULL;
-  
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  *result = txt;
-  return(TRUE);
+    gchar *txt = NULL;
+
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+    *result = txt;
+    return(TRUE);
 }
 
 
 sixtp*
-simple_chars_only_parser_new(sixtp_end_handler end_handler) 
+simple_chars_only_parser_new(sixtp_end_handler end_handler)
 {
     return sixtp_set_any(
-        sixtp_new(), FALSE,
-        SIXTP_END_HANDLER_ID, (end_handler
-                               ? end_handler
-                               : generic_return_chars_end_handler),
-        SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
-        SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
-        SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
-        SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
-        SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
-        SIXTP_NO_MORE_HANDLERS);
+               sixtp_new(), FALSE,
+               SIXTP_END_HANDLER_ID, (end_handler
+                                      ? end_handler
+                                      : generic_return_chars_end_handler),
+               SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
+               SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
+               SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
+               SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
+               SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
+               SIXTP_NO_MORE_HANDLERS);
 }
 
 
@@ -388,34 +402,35 @@
  * whatever comes first.  The old implementation called mktime after setting
  * the environment variable TZ to UTC.  It did not work on Windows, at least.
  */
-static const gint days_before[] = {
-  0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
+static const gint days_before[] =
+{
+    0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
 };
 
 static time_t
 gnc_timegm (struct tm *tm)
 {
-  time_t retval;
-  if (tm->tm_mon < 0 || tm->tm_mon > 11)
-    return (time_t) -1;
+    time_t retval;
+    if (tm->tm_mon < 0 || tm->tm_mon > 11)
+        return (time_t) - 1;
 
-  retval = (tm->tm_year - 70) * 365;
-  retval += (tm->tm_year - 68) / 4;
-  retval += days_before[tm->tm_mon] + tm->tm_mday - 1;
+    retval = (tm->tm_year - 70) * 365;
+    retval += (tm->tm_year - 68) / 4;
+    retval += days_before[tm->tm_mon] + tm->tm_mday - 1;
 
-  if (tm->tm_year % 4 == 0 && tm->tm_mon < 2)
-    retval -= 1;
-  
-  retval = ((((retval * 24) + tm->tm_hour) * 60) + tm->tm_min) * 60 + tm->tm_sec;
+    if (tm->tm_year % 4 == 0 && tm->tm_mon < 2)
+        retval -= 1;
 
-  return retval;
+    retval = ((((retval * 24) + tm->tm_hour) * 60) + tm->tm_min) * 60 + tm->tm_sec;
+
+    return retval;
 }
 #endif /* HAVE_TIMEGM */
 
 
 /****************************************************************************/
 /* generic timespec handler.
-   
+
    A collection of node functions intended to parse a sub-node set
    that looks like this:
 
@@ -431,126 +446,128 @@
 */
 
 gboolean
-string_to_timespec_secs(const gchar *str, Timespec *ts) {
+string_to_timespec_secs(const gchar *str, Timespec *ts)
+{
 
-  struct tm parsed_time;
-  const gchar *strpos;
-  time_t parsed_secs;
-  long int gmtoff;
+    struct tm parsed_time;
+    const gchar *strpos;
+    time_t parsed_secs;
+    long int gmtoff;
 
-  if (!str || !ts) return FALSE;
+    if (!str || !ts) return FALSE;
 
-  memset(&parsed_time, 0, sizeof(struct tm));
+    memset(&parsed_time, 0, sizeof(struct tm));
 
-  /* If you change this, make sure you also change the output code, if
-     necessary. */
-  /*fprintf(stderr, "parsing (%s)\n", str);*/
-  strpos = strptime(str, TIMESPEC_PARSE_TIME_FORMAT, &parsed_time);
+    /* If you change this, make sure you also change the output code, if
+       necessary. */
+    /*fprintf(stderr, "parsing (%s)\n", str);*/
+    strpos = strptime(str, TIMESPEC_PARSE_TIME_FORMAT, &parsed_time);
 
-  g_return_val_if_fail(strpos, FALSE);
+    g_return_val_if_fail(strpos, FALSE);
 
-  {
-    char sign;
-    int h1;
-    int h2;
-    int m1;
-    int m2;
-    int num_read;
+    {
+        char sign;
+        int h1;
+        int h2;
+        int m1;
+        int m2;
+        int num_read;
 
-    /* must use "<" here because %n's effects aren't well defined */
-    if(sscanf(strpos, " %c%1d%1d%1d%1d%n",
-              &sign,
-              &h1,
-              &h2,
-              &m1,
-              &m2,
-              &num_read) < 5) {
-      return(FALSE);
-    }
+        /* must use "<" here because %n's effects aren't well defined */
+        if (sscanf(strpos, " %c%1d%1d%1d%1d%n",
+                   &sign,
+                   &h1,
+                   &h2,
+                   &m1,
+                   &m2,
+                   &num_read) < 5)
+        {
+            return(FALSE);
+        }
 
-    if((sign != '+') && (sign != '-')) return(FALSE);
-    if(!isspace_str(strpos + num_read, -1)) return(FALSE);
+        if ((sign != '+') && (sign != '-')) return(FALSE);
+        if (!isspace_str(strpos + num_read, -1)) return(FALSE);
 
-    gmtoff = (h1 * 10 + h2) * 60 * 60;
-    gmtoff += (m1 * 10 + m2) * 60;
-    if(sign == '-') gmtoff = - gmtoff;
+        gmtoff = (h1 * 10 + h2) * 60 * 60;
+        gmtoff += (m1 * 10 + m2) * 60;
+        if (sign == '-') gmtoff = - gmtoff;
 
-    parsed_time.tm_isdst = -1;
-  }
+        parsed_time.tm_isdst = -1;
+    }
 
-  parsed_secs = gnc_timegm(&parsed_time);
+    parsed_secs = gnc_timegm(&parsed_time);
 
-  if(parsed_secs == (time_t) -1) return(FALSE);
+    if (parsed_secs == (time_t) - 1) return(FALSE);
 
-  parsed_secs -= gmtoff;
+    parsed_secs -= gmtoff;
 
-  ts->tv_sec = parsed_secs;
+    ts->tv_sec = parsed_secs;
 
-  return(TRUE);
+    return(TRUE);
 }
 
 gboolean
 string_to_timespec_nsecs(const gchar *str, Timespec *ts)
 {
-  long int nanosecs;
-  unsigned int charcount;
+    long int nanosecs;
+    unsigned int charcount;
 
-  if (!str || !ts) return FALSE;
+    if (!str || !ts) return FALSE;
 
-  /* The '%n' doesn't count as a conversion. */
-  if (1 != sscanf(str, " %ld%n", &nanosecs, &charcount))
-    return FALSE;
+    /* The '%n' doesn't count as a conversion. */
+    if (1 != sscanf(str, " %ld%n", &nanosecs, &charcount))
+        return FALSE;
 
-  while( (*((gchar*)str + charcount)!='\0') &&
-	 isspace(*((unsigned char*)str + charcount)))
-    charcount++;
+    while ( (*((gchar*)str + charcount) != '\0') &&
+            isspace(*((unsigned char*)str + charcount)))
+        charcount++;
 
-  if(charcount != strlen(str)) return(FALSE);
+    if (charcount != strlen(str)) return(FALSE);
 
-  ts->tv_nsec = nanosecs;
+    ts->tv_nsec = nanosecs;
 
-  return(TRUE);
+    return(TRUE);
 }
 
 gboolean
 timespec_secs_to_given_string (const Timespec *ts, gchar *str)
 {
-  struct tm parsed_time;
-  size_t num_chars;
-  time_t tmp_time;
-  long int tz;
-  int minutes;
-  int hours;
-  int sign;
+    struct tm parsed_time;
+    size_t num_chars;
+    time_t tmp_time;
+    long int tz;
+    int minutes;
+    int hours;
+    int sign;
 
-  if (!ts || !str)
-    return FALSE;
+    if (!ts || !str)
+        return FALSE;
 
-  tmp_time = ts->tv_sec;
+    tmp_time = ts->tv_sec;
 
-  if (!localtime_r(&tmp_time, &parsed_time))
-    return FALSE;
+    if (!localtime_r(&tmp_time, &parsed_time))
+        return FALSE;
 
-  num_chars = qof_strftime(str, TIMESPEC_SEC_FORMAT_MAX,
-                           TIMESPEC_TIME_FORMAT, &parsed_time);
-  if (num_chars == 0)
-    return FALSE;
+    num_chars = qof_strftime(str, TIMESPEC_SEC_FORMAT_MAX,
+                             TIMESPEC_TIME_FORMAT, &parsed_time);
+    if (num_chars == 0)
+        return FALSE;
 
-  str += num_chars;
+    str += num_chars;
 
-  tz = gnc_timezone (&parsed_time);
+    tz = gnc_timezone (&parsed_time);
 
-  /* gnc_timezone is seconds west of UTC */
-  sign = (tz > 0) ? -1 : 1;
+    /* gnc_timezone is seconds west of UTC */
+    sign = (tz > 0) ? -1 : 1;
 
-  minutes = ABS (tz) / 60;
-  hours = minutes / 60;
-  minutes -= hours * 60;
+    minutes = ABS (tz) / 60;
+    hours = minutes / 60;
+    minutes -= hours * 60;
 
-  g_snprintf (str, TIMESPEC_SEC_FORMAT_MAX - num_chars,
-              " %c%02d%02d", (sign > 0) ? '+' : '-', hours, minutes);
+    g_snprintf (str, TIMESPEC_SEC_FORMAT_MAX - num_chars,
+                " %c%02d%02d", (sign > 0) ? '+' : '-', hours, minutes);
 
-  return TRUE;
+    return TRUE;
 }
 
 /* Top level timespec node:
@@ -576,10 +593,10 @@
                                gpointer *data_for_children, gpointer *result,
                                const gchar *tag, gchar **attrs)
 {
-  TimespecParseInfo *tsp = g_new0(TimespecParseInfo, 1);
-  g_return_val_if_fail(tsp, FALSE);
-  *data_for_children = tsp;
-  return(TRUE);
+    TimespecParseInfo *tsp = g_new0(TimespecParseInfo, 1);
+    g_return_val_if_fail(tsp, FALSE);
+    *data_for_children = tsp;
+    return(TRUE);
 }
 
 /* You can't use this function directly.  You have to call it from
@@ -587,14 +604,18 @@
    new timespec.  Otherwise, you can presume that everything's been
    cleaned up properly and return FALSE.  */
 gboolean
-timespec_parse_ok(TimespecParseInfo *info) {
+timespec_parse_ok(TimespecParseInfo *info)
+{
 
-  if((info->s_block_count > 1) || (info->ns_block_count > 1) ||
-     ((info->s_block_count == 0) && (info->ns_block_count == 0))) {
-    return(FALSE);
-  } else {
-    return(TRUE);
-  }
+    if ((info->s_block_count > 1) || (info->ns_block_count > 1) ||
+            ((info->s_block_count == 0) && (info->ns_block_count == 0)))
+    {
+        return(FALSE);
+    }
+    else
+    {
+        return(TRUE);
+    }
 }
 
 /* generic_timespec_end_handler - must be customized and provided by
@@ -623,22 +644,22 @@
                                   gpointer parent_data, gpointer global_data,
                                   gpointer *result, const gchar *tag)
 {
-  gchar *txt = NULL;
-  TimespecParseInfo *info = (TimespecParseInfo *) parent_data;
-  gboolean ok;
+    gchar *txt = NULL;
+    TimespecParseInfo *info = (TimespecParseInfo *) parent_data;
+    gboolean ok;
 
-  g_return_val_if_fail(parent_data, FALSE);
+    g_return_val_if_fail(parent_data, FALSE);
 
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  ok = string_to_timespec_secs(txt, &(info->ts));
-  g_free(txt);
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
 
-  g_return_val_if_fail(ok, FALSE);
+    ok = string_to_timespec_secs(txt, &(info->ts));
+    g_free(txt);
 
-  info->s_block_count++;
-  return(TRUE);
+    g_return_val_if_fail(ok, FALSE);
+
+    info->s_block_count++;
+    return(TRUE);
 }
 
 /* <s> (parent timespec-node)
@@ -664,65 +685,65 @@
                                    gpointer parent_data, gpointer global_data,
                                    gpointer *result, const gchar *tag)
 {
-  gchar *txt = NULL;
-  TimespecParseInfo *info = (TimespecParseInfo *) parent_data;
-  gboolean ok;
+    gchar *txt = NULL;
+    TimespecParseInfo *info = (TimespecParseInfo *) parent_data;
+    gboolean ok;
 
-  g_return_val_if_fail(parent_data, FALSE);
+    g_return_val_if_fail(parent_data, FALSE);
 
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  ok = string_to_timespec_nsecs(txt, &(info->ts));
-  g_free(txt);
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
 
-  g_return_val_if_fail(ok, FALSE);
+    ok = string_to_timespec_nsecs(txt, &(info->ts));
+    g_free(txt);
 
-  info->ns_block_count++;
-  return(TRUE);
+    g_return_val_if_fail(ok, FALSE);
+
+    info->ns_block_count++;
+    return(TRUE);
 }
 
 static sixtp*
 timespec_sixtp_new(sixtp_end_handler ender)
 {
     return sixtp_set_any(
-        sixtp_new(), FALSE,
-        SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
-        SIXTP_END_HANDLER_ID, ender,
-        SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
-        SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
-        SIXTP_NO_MORE_HANDLERS);
+               sixtp_new(), FALSE,
+               SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
+               SIXTP_END_HANDLER_ID, ender,
+               SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
+               SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
+               SIXTP_NO_MORE_HANDLERS);
 }
 
 sixtp *
-generic_timespec_parser_new(sixtp_end_handler end_handler) 
+generic_timespec_parser_new(sixtp_end_handler end_handler)
 {
-  sixtp *top_level =
-  sixtp_set_any(sixtp_new(), FALSE,
-                SIXTP_START_HANDLER_ID, generic_timespec_start_handler,
-                SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
-                SIXTP_END_HANDLER_ID, end_handler,
-                SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
-                SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children,
-                SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
-                SIXTP_NO_MORE_HANDLERS);
-  g_return_val_if_fail(top_level, NULL);
+    sixtp *top_level =
+        sixtp_set_any(sixtp_new(), FALSE,
+                      SIXTP_START_HANDLER_ID, generic_timespec_start_handler,
+                      SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
+                      SIXTP_END_HANDLER_ID, end_handler,
+                      SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
+                      SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children,
+                      SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
+                      SIXTP_NO_MORE_HANDLERS);
+    g_return_val_if_fail(top_level, NULL);
 
-  if(!sixtp_add_some_sub_parsers(
-         top_level, TRUE,
-         "s", timespec_sixtp_new(generic_timespec_secs_end_handler),
-         "ns", timespec_sixtp_new(generic_timespec_nsecs_end_handler),
-         0))
-  {
-      return NULL;
-  }
-  
-  return(top_level);
+    if (!sixtp_add_some_sub_parsers(
+                top_level, TRUE,
+                "s", timespec_sixtp_new(generic_timespec_secs_end_handler),
+                "ns", timespec_sixtp_new(generic_timespec_nsecs_end_handler),
+                0))
+    {
+        return NULL;
+    }
+
+    return(top_level);
 }
 
 /****************************************************************************/
 /* <?> generic guid handler...
-   
+
    Attempts to parse the current accumulated characters data as a guid
    and return it.
 
@@ -747,51 +768,51 @@
                          gpointer parent_data, gpointer global_data,
                          gpointer *result, const gchar *tag)
 {
-  gchar *txt = NULL;
-  GUID *gid;
-  gboolean ok;
+    gchar *txt = NULL;
+    GUID *gid;
+    gboolean ok;
 
-  txt = concatenate_child_result_chars(data_from_children);
-  g_return_val_if_fail(txt, FALSE);
-  
-  gid = g_new(GUID, 1);
-  if(!gid) 
-  {
+    txt = concatenate_child_result_chars(data_from_children);
+    g_return_val_if_fail(txt, FALSE);
+
+    gid = g_new(GUID, 1);
+    if (!gid)
+    {
+        g_free(txt);
+        return(FALSE);
+    }
+
+    ok = string_to_guid(txt, gid);
     g_free(txt);
-    return(FALSE);
-  }
 
-  ok = string_to_guid(txt, gid);
-  g_free(txt);
+    if (!ok)
+    {
+        PERR ("couldn't parse GUID");
+        g_free(gid);
+        return(FALSE);
+    }
 
-  if(!ok) 
-  {
-    PERR ("couldn't parse GUID");
-    g_free(gid);
-    return(FALSE);
-  }
-
-  *result = gid;
-  return(TRUE);
+    *result = gid;
+    return(TRUE);
 }
 
 sixtp*
-generic_guid_parser_new(void) 
+generic_guid_parser_new(void)
 {
     return sixtp_set_any(
-        sixtp_new(), FALSE,
-        SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
-        SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
-        SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
-        SIXTP_END_HANDLER_ID, generic_guid_end_handler,
-        SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
-        SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
-        SIXTP_NO_MORE_HANDLERS);
+               sixtp_new(), FALSE,
+               SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
+               SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
+               SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
+               SIXTP_END_HANDLER_ID, generic_guid_end_handler,
+               SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
+               SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
+               SIXTP_NO_MORE_HANDLERS);
 }
 
 /****************************************************************************/
 /* <?> generic gnc_numeric handler...
-   
+
    Attempts to parse the current accumulated characters data as a
    gnc_numeric and return it.
 
@@ -816,47 +837,47 @@
                                 gpointer parent_data, gpointer global_data,
                                 gpointer *result, const gchar *tag)
 {
-  gnc_numeric *num = NULL;
-  gchar *txt = NULL;
-  gboolean ok = FALSE;
+    gnc_numeric *num = NULL;
+    gchar *txt = NULL;
+    gboolean ok = FALSE;
 
-  txt = concatenate_child_result_chars(data_from_children);
+    txt = concatenate_child_result_chars(data_from_children);
 
-  if(txt) 
-  {
-    num = g_new(gnc_numeric, 1);
-    if(num) 
+    if (txt)
     {
-      if(string_to_gnc_numeric(txt, num)) 
-      {
-        ok = TRUE;
-        *result = num;
-      }
+        num = g_new(gnc_numeric, 1);
+        if (num)
+        {
+            if (string_to_gnc_numeric(txt, num))
+            {
+                ok = TRUE;
+                *result = num;
+            }
+        }
     }
-  }
 
-  g_free(txt);
-  if(!ok) 
-  {
-    PERR ("couldn't parse numeric quantity");
-    g_free(num);
-  }
+    g_free(txt);
+    if (!ok)
+    {
+        PERR ("couldn't parse numeric quantity");
+        g_free(num);
+    }
 
-  return(ok);
+    return(ok);
 }
 
 sixtp*
-generic_gnc_numeric_parser_new(void) 
+generic_gnc_numeric_parser_new(void)
 {
     return sixtp_set_any(
-        sixtp_new(), FALSE,
-        SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
-        SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
-        SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
-        SIXTP_END_HANDLER_ID, generic_gnc_numeric_end_handler,
-        SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
-        SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
-        SIXTP_NO_MORE_HANDLERS);
+               sixtp_new(), FALSE,
+               SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
+               SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
+               SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
+               SIXTP_END_HANDLER_ID, generic_gnc_numeric_end_handler,
+               SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
+               SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
+               SIXTP_NO_MORE_HANDLERS);
 }
 
 /***************************************************************************/
@@ -865,12 +886,12 @@
 restore_char_generator(sixtp_end_handler ender)
 {
     return sixtp_set_any(
-        sixtp_new(), FALSE,
-        SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
-        SIXTP_END_HANDLER_ID, ender,
-        SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
-        SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
-        SIXTP_NO_MORE_HANDLERS);
+               sixtp_new(), FALSE,
+               SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
+               SIXTP_END_HANDLER_ID, ender,
+               SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
+               SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
+               SIXTP_NO_MORE_HANDLERS);
 }
 
 /***************************** END OF FILE *********************************/

Modified: gnucash/trunk/src/backend/xml/sixtp-utils.h
===================================================================
--- gnucash/trunk/src/backend/xml/sixtp-utils.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/sixtp-utils.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -28,10 +28,11 @@
 
 #include "sixtp.h"
 
-typedef struct {
-  Timespec ts;
-  guint s_block_count;
-  guint ns_block_count;
+typedef struct
+{
+    Timespec ts;
+    guint s_block_count;
+    guint ns_block_count;
 } TimespecParseInfo;
 
 #define TIMESPEC_TIME_FORMAT  "%Y-%m-%d %H:%M:%S"
@@ -41,11 +42,11 @@
 gboolean isspace_str(const gchar *str, int nomorethan);
 
 gboolean allow_and_ignore_only_whitespace(GSList *sibling_data,
-                                          gpointer parent_data,
-                                          gpointer global_data,
-                                          gpointer *result,
-                                          const char *text,
-                                          int length);
+        gpointer parent_data,
+        gpointer global_data,
+        gpointer *result,
+        const char *text,
+        int length);
 
 gboolean generic_accumulate_chars(GSList *sibling_data,
                                   gpointer parent_data,
@@ -74,12 +75,12 @@
 gboolean hex_string_to_binary(const gchar *str,  void **v, guint64 *data_len);
 
 gboolean generic_return_chars_end_handler(gpointer data_for_children,
-                                          GSList* data_from_children,
-                                          GSList* sibling_data,
-                                          gpointer parent_data,
-                                          gpointer global_data,
-                                          gpointer *result,
-                                          const gchar *tag);
+        GSList* data_from_children,
+        GSList* sibling_data,
+        gpointer parent_data,
+        gpointer global_data,
+        gpointer *result,
+        const gchar *tag);
 
 sixtp* simple_chars_only_parser_new(sixtp_end_handler end_handler);
 

Modified: gnucash/trunk/src/backend/xml/sixtp.c
===================================================================
--- gnucash/trunk/src/backend/xml/sixtp.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/sixtp.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -39,116 +39,117 @@
 
 /************************************************************************/
 gboolean
-is_child_result_from_node_named(sixtp_child_result *cr, const char *tag) 
+is_child_result_from_node_named(sixtp_child_result *cr, const char *tag)
 {
-  return((cr->type == SIXTP_CHILD_RESULT_NODE)
-         &&
-         (safe_strcmp(cr->tag, tag) == 0));
+    return((cr->type == SIXTP_CHILD_RESULT_NODE)
+           &&
+           (safe_strcmp(cr->tag, tag) == 0));
 }
 
 void
-sixtp_child_free_data(sixtp_child_result *result) 
+sixtp_child_free_data(sixtp_child_result *result)
 {
-  if(result->data) g_free(result->data);
+    if (result->data) g_free(result->data);
 }
 
 void
-sixtp_child_result_destroy(sixtp_child_result *r) 
+sixtp_child_result_destroy(sixtp_child_result *r)
 {
-  if(r->should_cleanup && r->cleanup_handler) 
-  {
-    r->cleanup_handler(r);
-  }
-  if(r->type == SIXTP_CHILD_RESULT_NODE) g_free(r->tag);
-  g_free(r);
+    if (r->should_cleanup && r->cleanup_handler)
+    {
+        r->cleanup_handler(r);
+    }
+    if (r->type == SIXTP_CHILD_RESULT_NODE) g_free(r->tag);
+    g_free(r);
 }
 
 void
-sixtp_child_result_print(sixtp_child_result *cr, FILE *f) 
+sixtp_child_result_print(sixtp_child_result *cr, FILE *f)
 {
-  fprintf(f, "((tag %s) (data %p))",
-          cr->tag ? cr->tag : "(null)",
-          cr->data);
+    fprintf(f, "((tag %s) (data %p))",
+            cr->tag ? cr->tag : "(null)",
+            cr->data);
 }
 
 /************************************************************************/
 
 
 void
-sixtp_set_start(sixtp *parser, sixtp_start_handler start_handler) 
+sixtp_set_start(sixtp *parser, sixtp_start_handler start_handler)
 {
-  parser->start_handler = start_handler;
+    parser->start_handler = start_handler;
 }
 
 void
-sixtp_set_before_child(sixtp *parser, sixtp_before_child_handler handler) 
+sixtp_set_before_child(sixtp *parser, sixtp_before_child_handler handler)
 {
-  parser->before_child = handler;
+    parser->before_child = handler;
 }
 
 void
 sixtp_set_after_child(sixtp *parser, sixtp_after_child_handler handler)
 {
-  parser->after_child = handler;
+    parser->after_child = handler;
 }
 
 void
-sixtp_set_end(sixtp *parser, sixtp_end_handler end_handler) 
+sixtp_set_end(sixtp *parser, sixtp_end_handler end_handler)
 {
-  parser->end_handler = end_handler;
+    parser->end_handler = end_handler;
 }
 
 void
-sixtp_set_chars(sixtp *parser, sixtp_characters_handler char_handler) 
+sixtp_set_chars(sixtp *parser, sixtp_characters_handler char_handler)
 {
-  parser->characters_handler = char_handler;
+    parser->characters_handler = char_handler;
 }
 
 void
-sixtp_set_cleanup_result(sixtp *parser, sixtp_result_handler handler) 
+sixtp_set_cleanup_result(sixtp *parser, sixtp_result_handler handler)
 {
-  parser->cleanup_result = handler;
+    parser->cleanup_result = handler;
 }
 
 void
-sixtp_set_cleanup_chars(sixtp *parser, sixtp_result_handler handler) 
+sixtp_set_cleanup_chars(sixtp *parser, sixtp_result_handler handler)
 {
-  parser->cleanup_chars = handler;
+    parser->cleanup_chars = handler;
 }
 
 void
 sixtp_set_fail(sixtp *parser,
-               sixtp_fail_handler handler) {
-  parser->fail_handler = handler;
+               sixtp_fail_handler handler)
+{
+    parser->fail_handler = handler;
 }
 
 void
-sixtp_set_result_fail(sixtp *parser, sixtp_result_handler handler) 
+sixtp_set_result_fail(sixtp *parser, sixtp_result_handler handler)
 {
-  parser->result_fail_handler = handler;
+    parser->result_fail_handler = handler;
 }
 
 void
-sixtp_set_chars_fail(sixtp *parser, sixtp_result_handler handler) 
+sixtp_set_chars_fail(sixtp *parser, sixtp_result_handler handler)
 {
-  parser->chars_fail_handler = handler;
+    parser->chars_fail_handler = handler;
 }
 
 sixtp *
-sixtp_new(void) 
+sixtp_new(void)
 {
-  sixtp *s = g_new0(sixtp, 1);
+    sixtp *s = g_new0(sixtp, 1);
 
-  if(s) 
-  {
-    s->child_parsers = g_hash_table_new(g_str_hash, g_str_equal);
-    if(!s->child_parsers) 
+    if (s)
     {
-      g_free(s);
-      s = NULL;
+        s->child_parsers = g_hash_table_new(g_str_hash, g_str_equal);
+        if (!s->child_parsers)
+        {
+            g_free(s);
+            s = NULL;
+        }
     }
-  }
-  return(s);
+    return(s);
 }
 
 sixtp*
@@ -156,20 +157,20 @@
 {
     va_list ap;
     sixtp_handler_type type;
-    
+
     va_start(ap, cleanup);
-    
-    if(!tochange)
+
+    if (!tochange)
     {
         g_warning("Null tochange passed");
         return NULL;
     }
 
-    do 
+    do
     {
         type = va_arg(ap, sixtp_handler_type);
 
-        switch(type)
+        switch (type)
         {
         case SIXTP_NO_MORE_HANDLERS:
             va_end(ap);
@@ -178,43 +179,43 @@
         case SIXTP_START_HANDLER_ID:
             sixtp_set_start(tochange, va_arg(ap, sixtp_start_handler));
             break;
-            
+
         case SIXTP_BEFORE_CHILD_HANDLER_ID:
             sixtp_set_before_child(tochange,
                                    va_arg(ap, sixtp_before_child_handler));
             break;
-            
+
         case SIXTP_AFTER_CHILD_HANDLER_ID:
             sixtp_set_after_child(tochange,
                                   va_arg(ap, sixtp_after_child_handler));
             break;
-            
+
         case SIXTP_END_HANDLER_ID:
             sixtp_set_end(tochange, va_arg(ap, sixtp_end_handler));
             break;
-            
+
         case SIXTP_CHARACTERS_HANDLER_ID:
             sixtp_set_chars(tochange, va_arg(ap, sixtp_characters_handler));
             break;
-            
+
         case SIXTP_FAIL_HANDLER_ID:
             sixtp_set_fail(tochange, va_arg(ap, sixtp_fail_handler));
             break;
-            
+
         case SIXTP_CLEANUP_RESULT_ID:
             sixtp_set_cleanup_result(tochange,
                                      va_arg(ap, sixtp_result_handler));
             break;
-            
+
         case SIXTP_CLEANUP_CHARS_ID:
             sixtp_set_cleanup_chars(tochange,
                                     va_arg(ap, sixtp_result_handler));
             break;
-            
+
         case SIXTP_RESULT_FAIL_ID:
             sixtp_set_result_fail(tochange, va_arg(ap, sixtp_result_handler));
             break;
-            
+
         case SIXTP_CHARS_FAIL_ID:
             sixtp_set_chars_fail(tochange, va_arg(ap, sixtp_result_handler));
             break;
@@ -222,13 +223,14 @@
         default:
             va_end(ap);
             g_critical("Bogus sixtp type %d", type);
-            if(cleanup)
+            if (cleanup)
             {
                 sixtp_destroy(tochange);
             }
             return NULL;
         }
-    } while(1);
+    }
+    while (1);
 
     va_end(ap);
     return tochange;
@@ -238,56 +240,56 @@
                                 gpointer user_data);
 
 static void
-sixtp_destroy_node(sixtp *sp, GHashTable *corpses) 
+sixtp_destroy_node(sixtp *sp, GHashTable *corpses)
 {
-  g_return_if_fail(sp);
-  g_return_if_fail(corpses);
-  g_hash_table_foreach(sp->child_parsers, sixtp_destroy_child, corpses);
-  g_hash_table_destroy(sp->child_parsers);
-  g_free(sp);
+    g_return_if_fail(sp);
+    g_return_if_fail(corpses);
+    g_hash_table_foreach(sp->child_parsers, sixtp_destroy_child, corpses);
+    g_hash_table_destroy(sp->child_parsers);
+    g_free(sp);
 }
 
 static void
-sixtp_destroy_child(gpointer key, gpointer value, gpointer user_data) 
+sixtp_destroy_child(gpointer key, gpointer value, gpointer user_data)
 {
-  GHashTable *corpses = (GHashTable *) user_data;
-  sixtp *child = (sixtp *) value;
-  gpointer lookup_key;
-  gpointer lookup_value;
+    GHashTable *corpses = (GHashTable *) user_data;
+    sixtp *child = (sixtp *) value;
+    gpointer lookup_key;
+    gpointer lookup_value;
 
-  g_debug("Killing sixtp child under key <%s>", key ? (char *) key : "(null)");
-  g_free(key);
+    g_debug("Killing sixtp child under key <%s>", key ? (char *) key : "(null)");
+    g_free(key);
 
-  if(!corpses) 
-  {
-    g_critical("no corpses in sixtp_destroy_child <%s>",
-               key ? (char *) key : "(null)");
-    return;
-  }
-  if(!child) 
-  {
-    g_critical("no child in sixtp_destroy_child <%s>",
-               key ? (char *) key : "");
-    return;
-  }
+    if (!corpses)
+    {
+        g_critical("no corpses in sixtp_destroy_child <%s>",
+                   key ? (char *) key : "(null)");
+        return;
+    }
+    if (!child)
+    {
+        g_critical("no child in sixtp_destroy_child <%s>",
+                   key ? (char *) key : "");
+        return;
+    }
 
-  if(!g_hash_table_lookup_extended(corpses, (gconstpointer) child,
-                                   &lookup_key, &lookup_value)) 
-  {
-    /* haven't killed this one yet. */
-    g_hash_table_insert(corpses, child, (gpointer) 1);
-    sixtp_destroy_node(child, corpses);
-  }
+    if (!g_hash_table_lookup_extended(corpses, (gconstpointer) child,
+                                      &lookup_key, &lookup_value))
+    {
+        /* haven't killed this one yet. */
+        g_hash_table_insert(corpses, child, (gpointer) 1);
+        sixtp_destroy_node(child, corpses);
+    }
 }
 
 void
-sixtp_destroy(sixtp *sp) 
+sixtp_destroy(sixtp *sp)
 {
-  GHashTable *corpses;
-  g_return_if_fail(sp);
-  corpses = g_hash_table_new(g_direct_hash, g_direct_equal);
-  sixtp_destroy_node(sp, corpses);
-  g_hash_table_destroy(corpses);
+    GHashTable *corpses;
+    g_return_if_fail(sp);
+    corpses = g_hash_table_new(g_direct_hash, g_direct_equal);
+    sixtp_destroy_node(sp, corpses);
+    g_hash_table_destroy(corpses);
 }
 
 
@@ -296,13 +298,13 @@
 gboolean
 sixtp_add_sub_parser(sixtp *parser, const gchar* tag, sixtp *sub_parser)
 {
-  g_return_val_if_fail(parser, FALSE);
-  g_return_val_if_fail(tag, FALSE);
-  g_return_val_if_fail(sub_parser, FALSE);
+    g_return_val_if_fail(parser, FALSE);
+    g_return_val_if_fail(tag, FALSE);
+    g_return_val_if_fail(sub_parser, FALSE);
 
-  g_hash_table_insert(parser->child_parsers, 
-                      g_strdup(tag), (gpointer) sub_parser);
-  return(TRUE);
+    g_hash_table_insert(parser->child_parsers,
+                        g_strdup(tag), (gpointer) sub_parser);
+    return(TRUE);
 }
 
 /*
@@ -320,8 +322,8 @@
     va_start(ap, cleanup);
 
     have_error = 0;
-    
-    if(!tochange)
+
+    if (!tochange)
     {
         have_error = 1;
     }
@@ -329,18 +331,18 @@
     do
     {
         tag = va_arg(ap, char*);
-        if(!tag)
+        if (!tag)
         {
             break;
         }
 
         handler = va_arg(ap, sixtp*);
-        if(!handler)
+        if (!handler)
         {
             g_warning("Handler for tag %s is null",
                       tag ? tag : "(null)");
 
-            if(cleanup)
+            if (cleanup)
             {
                 sixtp_destroy(tochange);
                 tochange = NULL;
@@ -361,7 +363,8 @@
         {
             sixtp_add_sub_parser(tochange, tag, handler);
         }
-    } while (1);
+    }
+    while (1);
 
     va_end(ap);
     return tochange;
@@ -372,300 +375,301 @@
 void
 sixtp_sax_start_handler(void *user_data,
                         const xmlChar *name,
-                        const xmlChar **attrs) 
+                        const xmlChar **attrs)
 {
-  sixtp_sax_data *pdata = (sixtp_sax_data *) user_data;
-  sixtp_stack_frame *current_frame = NULL;
-  sixtp *current_parser = NULL;
-  sixtp *next_parser = NULL;
-  gchar *next_parser_tag = NULL;
-  gboolean lookup_success = FALSE;
-  sixtp_stack_frame *new_frame = NULL;
+    sixtp_sax_data *pdata = (sixtp_sax_data *) user_data;
+    sixtp_stack_frame *current_frame = NULL;
+    sixtp *current_parser = NULL;
+    sixtp *next_parser = NULL;
+    gchar *next_parser_tag = NULL;
+    gboolean lookup_success = FALSE;
+    sixtp_stack_frame *new_frame = NULL;
 
-  current_frame = (sixtp_stack_frame *) pdata->stack->data;
-  current_parser = current_frame->parser;
+    current_frame = (sixtp_stack_frame *) pdata->stack->data;
+    current_parser = current_frame->parser;
 
-  /* Use an extended lookup so we can get *our* copy of the key.
-     Since we've strduped it, we know its lifetime... */
-  lookup_success = g_hash_table_lookup_extended(current_parser->child_parsers,
-                                                name,
-                                                (gpointer) &next_parser_tag,
-                                                (gpointer) &next_parser);
-  
-  if(!lookup_success) 
-  {
-       /* magic catch all value */ 
-      lookup_success = g_hash_table_lookup_extended(
-          current_parser->child_parsers, SIXTP_MAGIC_CATCHER,
-          (gpointer) &next_parser_tag, (gpointer) &next_parser);
-      if(!lookup_success) 
-      {
-          g_critical("Tag <%s> not allowed in current context.",
-                     name ? (char *) name : "(null)");
-          pdata->parsing_ok = FALSE;
-	  next_parser = pdata->bad_xml_parser;
-      }
-  }
+    /* Use an extended lookup so we can get *our* copy of the key.
+       Since we've strduped it, we know its lifetime... */
+    lookup_success = g_hash_table_lookup_extended(current_parser->child_parsers,
+                     name,
+                     (gpointer) & next_parser_tag,
+                     (gpointer) & next_parser);
 
-  if(current_frame->parser->before_child) 
-  {
-    GSList *parent_data_from_children = NULL;
-    gpointer parent_data_for_children = NULL;
+    if (!lookup_success)
+    {
+        /* magic catch all value */
+        lookup_success = g_hash_table_lookup_extended(
+                             current_parser->child_parsers, SIXTP_MAGIC_CATCHER,
+                             (gpointer) & next_parser_tag, (gpointer) & next_parser);
+        if (!lookup_success)
+        {
+            g_critical("Tag <%s> not allowed in current context.",
+                       name ? (char *) name : "(null)");
+            pdata->parsing_ok = FALSE;
+            next_parser = pdata->bad_xml_parser;
+        }
+    }
 
-    if(g_slist_length(pdata->stack) > 1) 
+    if (current_frame->parser->before_child)
     {
-      /* we're not in the top level node */
-      sixtp_stack_frame *parent_frame =
-        (sixtp_stack_frame *) pdata->stack->next->data;
-      parent_data_from_children = parent_frame->data_from_children;
-      parent_data_from_children = parent_frame->data_for_children;
+        GSList *parent_data_from_children = NULL;
+        gpointer parent_data_for_children = NULL;
+
+        if (g_slist_length(pdata->stack) > 1)
+        {
+            /* we're not in the top level node */
+            sixtp_stack_frame *parent_frame =
+                (sixtp_stack_frame *) pdata->stack->next->data;
+            parent_data_from_children = parent_frame->data_from_children;
+            parent_data_from_children = parent_frame->data_for_children;
+        }
+
+        pdata->parsing_ok &=
+            current_frame->parser->before_child(current_frame->data_for_children,
+                                                current_frame->data_from_children,
+                                                parent_data_from_children,
+                                                parent_data_for_children,
+                                                pdata->global_data,
+                                                &(current_frame->frame_data),
+                                                current_frame->tag,
+                                                (gchar*) name);
     }
 
-    pdata->parsing_ok &=
-      current_frame->parser->before_child(current_frame->data_for_children,
-                                          current_frame->data_from_children,
-                                          parent_data_from_children,
-                                          parent_data_for_children,
-                                          pdata->global_data,
-                                          &(current_frame->frame_data),
-                                          current_frame->tag,
-                                          (gchar*) name);
-  }
+    /* now allocate the new stack frame and shift to it */
+    new_frame = sixtp_stack_frame_new( next_parser, g_strdup((char*) name));
 
-  /* now allocate the new stack frame and shift to it */
-  new_frame = sixtp_stack_frame_new( next_parser, g_strdup((char*) name));
+    new_frame->line = xmlSAX2GetLineNumber( pdata->saxParserCtxt );
+    new_frame->col  = xmlSAX2GetColumnNumber( pdata->saxParserCtxt );
 
-  new_frame->line = xmlSAX2GetLineNumber( pdata->saxParserCtxt );
-  new_frame->col  = xmlSAX2GetColumnNumber( pdata->saxParserCtxt );
-  
-  pdata->stack = g_slist_prepend(pdata->stack, (gpointer) new_frame);
-  
-  if(next_parser->start_handler) 
-  {
-    pdata->parsing_ok &=
-      next_parser->start_handler(current_frame->data_from_children,
-                                 current_frame->data_for_children,
-                                 pdata->global_data,
-                                 &new_frame->data_for_children,
-                                 &new_frame->frame_data,
-                                 (gchar*) name,
-                                 (gchar**)attrs);
-  }
+    pdata->stack = g_slist_prepend(pdata->stack, (gpointer) new_frame);
+
+    if (next_parser->start_handler)
+    {
+        pdata->parsing_ok &=
+            next_parser->start_handler(current_frame->data_from_children,
+                                       current_frame->data_for_children,
+                                       pdata->global_data,
+                                       &new_frame->data_for_children,
+                                       &new_frame->frame_data,
+                                       (gchar*) name,
+                                       (gchar**)attrs);
+    }
 }
 
 void
-sixtp_sax_characters_handler(void *user_data, const xmlChar *text, int len) 
+sixtp_sax_characters_handler(void *user_data, const xmlChar *text, int len)
 {
-  sixtp_sax_data *pdata = (sixtp_sax_data *) user_data;
-  sixtp_stack_frame *frame;
+    sixtp_sax_data *pdata = (sixtp_sax_data *) user_data;
+    sixtp_stack_frame *frame;
 
-  frame = (sixtp_stack_frame *) pdata->stack->data;
-  if(frame->parser->characters_handler) 
-  {
-    gpointer result = NULL;
+    frame = (sixtp_stack_frame *) pdata->stack->data;
+    if (frame->parser->characters_handler)
+    {
+        gpointer result = NULL;
 
-    pdata->parsing_ok &=
-      frame->parser->characters_handler(frame->data_from_children,
-                                        frame->data_for_children,
-                                        pdata->global_data,
-                                        &result,
-                                        (gchar*) text,
-                                        len);
-    if(pdata->parsing_ok && result)
-    {
-        /* push the result onto the current "child" list. */
-        sixtp_child_result *child_data = g_new0(sixtp_child_result, 1);
-        
-        child_data->type = SIXTP_CHILD_RESULT_CHARS;
-        child_data->tag = NULL;
-        child_data->data = result;
-        child_data->should_cleanup = TRUE;
-        child_data->cleanup_handler = frame->parser->cleanup_chars;
-        child_data->fail_handler = frame->parser->chars_fail_handler;
-        frame->data_from_children = g_slist_prepend(frame->data_from_children,
-                                                    child_data);
+        pdata->parsing_ok &=
+            frame->parser->characters_handler(frame->data_from_children,
+                                              frame->data_for_children,
+                                              pdata->global_data,
+                                              &result,
+                                              (gchar*) text,
+                                              len);
+        if (pdata->parsing_ok && result)
+        {
+            /* push the result onto the current "child" list. */
+            sixtp_child_result *child_data = g_new0(sixtp_child_result, 1);
+
+            child_data->type = SIXTP_CHILD_RESULT_CHARS;
+            child_data->tag = NULL;
+            child_data->data = result;
+            child_data->should_cleanup = TRUE;
+            child_data->cleanup_handler = frame->parser->cleanup_chars;
+            child_data->fail_handler = frame->parser->chars_fail_handler;
+            frame->data_from_children = g_slist_prepend(frame->data_from_children,
+                                        child_data);
+        }
     }
-  }
 }
 
 void
-sixtp_sax_end_handler(void *user_data, const xmlChar *name) 
+sixtp_sax_end_handler(void *user_data, const xmlChar *name)
 {
-  sixtp_sax_data *pdata = (sixtp_sax_data *) user_data;
-  sixtp_stack_frame *current_frame;
-  sixtp_stack_frame *parent_frame;
-  sixtp_child_result *child_result_data = NULL;
-  gchar *end_tag = NULL;
+    sixtp_sax_data *pdata = (sixtp_sax_data *) user_data;
+    sixtp_stack_frame *current_frame;
+    sixtp_stack_frame *parent_frame;
+    sixtp_child_result *child_result_data = NULL;
+    gchar *end_tag = NULL;
 
-  current_frame = (sixtp_stack_frame *) pdata->stack->data;
-  parent_frame = (sixtp_stack_frame *) pdata->stack->next->data;
+    current_frame = (sixtp_stack_frame *) pdata->stack->data;
+    parent_frame = (sixtp_stack_frame *) pdata->stack->next->data;
 
-  /* time to make sure we got the right closing tag.  Is this really
-     necessary? */
-  if(safe_strcmp(current_frame->tag, (gchar*) name) != 0) 
-  {
-    g_warning("bad closing tag (start <%s>, end <%s>)", current_frame->tag, name);
-    pdata->parsing_ok = FALSE;
+    /* time to make sure we got the right closing tag.  Is this really
+       necessary? */
+    if (safe_strcmp(current_frame->tag, (gchar*) name) != 0)
+    {
+        g_warning("bad closing tag (start <%s>, end <%s>)", current_frame->tag, name);
+        pdata->parsing_ok = FALSE;
 
-    /* See if we're just off by one and try to recover */
-    if(safe_strcmp(parent_frame->tag, (gchar*) name) == 0) {
-      pdata->stack = sixtp_pop_and_destroy_frame(pdata->stack);
-      current_frame = (sixtp_stack_frame *) pdata->stack->data;
-      parent_frame = (sixtp_stack_frame *) pdata->stack->next->data;
-      g_warning("found matching start <%s> tag up one level", name);
+        /* See if we're just off by one and try to recover */
+        if (safe_strcmp(parent_frame->tag, (gchar*) name) == 0)
+        {
+            pdata->stack = sixtp_pop_and_destroy_frame(pdata->stack);
+            current_frame = (sixtp_stack_frame *) pdata->stack->data;
+            parent_frame = (sixtp_stack_frame *) pdata->stack->next->data;
+            g_warning("found matching start <%s> tag up one level", name);
+        }
     }
-  }
-  
-  /* tag's OK, proceed. */
-  if(current_frame->parser->end_handler) 
-  {
-    pdata->parsing_ok &= 
-      current_frame->parser->end_handler(current_frame->data_for_children,
-                                         current_frame->data_from_children,
-                                         parent_frame->data_from_children,
-                                         parent_frame->data_for_children,
-                                         pdata->global_data,
-                                         &current_frame->frame_data,
-                                         current_frame->tag);
-  }
 
-  if(current_frame->frame_data) 
-  {
-    /* push the result onto the parent's child result list. */
-    child_result_data = g_new(sixtp_child_result, 1);
-    
-    child_result_data->type = SIXTP_CHILD_RESULT_NODE;
-    child_result_data->tag = g_strdup(current_frame->tag);
-    child_result_data->data = current_frame->frame_data;
-    child_result_data->should_cleanup = TRUE;
-    child_result_data->cleanup_handler = current_frame->parser->cleanup_result;
-    child_result_data->fail_handler =
-      current_frame->parser->result_fail_handler;
-    parent_frame->data_from_children =
-      g_slist_prepend(parent_frame->data_from_children, child_result_data);
-  }
+    /* tag's OK, proceed. */
+    if (current_frame->parser->end_handler)
+    {
+        pdata->parsing_ok &=
+            current_frame->parser->end_handler(current_frame->data_for_children,
+                                               current_frame->data_from_children,
+                                               parent_frame->data_from_children,
+                                               parent_frame->data_for_children,
+                                               pdata->global_data,
+                                               &current_frame->frame_data,
+                                               current_frame->tag);
+    }
 
-  /* grab it before it goes away - we own the reference */
-  end_tag = current_frame->tag;
+    if (current_frame->frame_data)
+    {
+        /* push the result onto the parent's child result list. */
+        child_result_data = g_new(sixtp_child_result, 1);
 
-  g_debug("Finished with end of <%s>", end_tag ? end_tag : "(null)");
+        child_result_data->type = SIXTP_CHILD_RESULT_NODE;
+        child_result_data->tag = g_strdup(current_frame->tag);
+        child_result_data->data = current_frame->frame_data;
+        child_result_data->should_cleanup = TRUE;
+        child_result_data->cleanup_handler = current_frame->parser->cleanup_result;
+        child_result_data->fail_handler =
+            current_frame->parser->result_fail_handler;
+        parent_frame->data_from_children =
+            g_slist_prepend(parent_frame->data_from_children, child_result_data);
+    }
 
-  /*sixtp_print_frame_stack(pdata->stack, stderr);*/
+    /* grab it before it goes away - we own the reference */
+    end_tag = current_frame->tag;
 
-  pdata->stack = sixtp_pop_and_destroy_frame(pdata->stack);
+    g_debug("Finished with end of <%s>", end_tag ? end_tag : "(null)");
 
-  /* reset pointer after stack pop */
-  current_frame = (sixtp_stack_frame *) pdata->stack->data;
-  /* reset the parent, checking to see if we're at the top level node */
-  parent_frame = (sixtp_stack_frame *) 
-    ((g_slist_length(pdata->stack) > 1) ? (pdata->stack->next->data) : NULL);
+    /*sixtp_print_frame_stack(pdata->stack, stderr);*/
 
-  if(current_frame->parser->after_child) 
-  {      
+    pdata->stack = sixtp_pop_and_destroy_frame(pdata->stack);
+
     /* reset pointer after stack pop */
-    GSList *parent_data_from_children = NULL;
-    gpointer parent_data_for_children = NULL;
+    current_frame = (sixtp_stack_frame *) pdata->stack->data;
+    /* reset the parent, checking to see if we're at the top level node */
+    parent_frame = (sixtp_stack_frame *)
+                   ((g_slist_length(pdata->stack) > 1) ? (pdata->stack->next->data) : NULL);
 
-    if(parent_frame) 
+    if (current_frame->parser->after_child)
     {
-      /* we're not in the top level node */
-      sixtp_stack_frame *parent_frame =
-        (sixtp_stack_frame *) pdata->stack->next->data;
-      parent_data_from_children = parent_frame->data_from_children;
-      parent_data_from_children = parent_frame->data_for_children;
+        /* reset pointer after stack pop */
+        GSList *parent_data_from_children = NULL;
+        gpointer parent_data_for_children = NULL;
+
+        if (parent_frame)
+        {
+            /* we're not in the top level node */
+            sixtp_stack_frame *parent_frame =
+                (sixtp_stack_frame *) pdata->stack->next->data;
+            parent_data_from_children = parent_frame->data_from_children;
+            parent_data_from_children = parent_frame->data_for_children;
+        }
+
+        pdata->parsing_ok &=
+            current_frame->parser->after_child(current_frame->data_for_children,
+                                               current_frame->data_from_children,
+                                               parent_data_from_children,
+                                               parent_data_for_children,
+                                               pdata->global_data,
+                                               &(current_frame->frame_data),
+                                               current_frame->tag,
+                                               end_tag,
+                                               child_result_data);
     }
 
-    pdata->parsing_ok &=
-      current_frame->parser->after_child(current_frame->data_for_children,
-                                         current_frame->data_from_children,
-                                         parent_data_from_children,
-                                         parent_data_for_children,
-                                         pdata->global_data,
-                                         &(current_frame->frame_data),
-                                         current_frame->tag,
-                                         end_tag,
-                                         child_result_data);
-  }
-
-  g_free (end_tag);
+    g_free (end_tag);
 }
 
 xmlEntityPtr
-sixtp_sax_get_entity_handler(void *user_data, const xmlChar *name) 
+sixtp_sax_get_entity_handler(void *user_data, const xmlChar *name)
 {
-  return xmlGetPredefinedEntity(name);
+    return xmlGetPredefinedEntity(name);
 }
 
 
 void
-sixtp_handle_catastrophe(sixtp_sax_data *sax_data) 
+sixtp_handle_catastrophe(sixtp_sax_data *sax_data)
 {
-  /* Something has gone wrong.  To handle it, we have to traverse the
-     stack, calling, at each level, the frame failure handler (the
-     handler for the current, unfinished block) and then the sibling
-     handlers.  The order is reverse chronological - oldest child
-     results cleaned up last.  This holds overall as well, stack
-     frames are cleaned up in their order on the stack which will be
-     youngest to oldest.  */
+    /* Something has gone wrong.  To handle it, we have to traverse the
+       stack, calling, at each level, the frame failure handler (the
+       handler for the current, unfinished block) and then the sibling
+       handlers.  The order is reverse chronological - oldest child
+       results cleaned up last.  This holds overall as well, stack
+       frames are cleaned up in their order on the stack which will be
+       youngest to oldest.  */
 
-  GSList *lp;
-  GSList **stack = &(sax_data->stack);
+    GSList *lp;
+    GSList **stack = &(sax_data->stack);
 
-  g_critical("parse failed at:");
-  sixtp_print_frame_stack(sax_data->stack, stderr);
+    g_critical("parse failed at:");
+    sixtp_print_frame_stack(sax_data->stack, stderr);
 
-  while(*stack) 
-  {
-    sixtp_stack_frame *current_frame = (sixtp_stack_frame *) (*stack)->data;
-
-    /* cleanup the current frame */
-    if(current_frame->parser->fail_handler) 
+    while (*stack)
     {
-      GSList *sibling_data;
-      gpointer parent_data;
+        sixtp_stack_frame *current_frame = (sixtp_stack_frame *) (*stack)->data;
 
-      if((*stack)->next == NULL) 
-      {
-        /* This is the top of the stack... */
-        parent_data = NULL;
-        sibling_data = NULL; 
-      } 
-      else 
-      {
-        sixtp_stack_frame *parent_frame =
-          (sixtp_stack_frame *) (*stack)->next->data;
-        parent_data = parent_frame->data_for_children;
-        sibling_data = parent_frame->data_from_children;
-      }
+        /* cleanup the current frame */
+        if (current_frame->parser->fail_handler)
+        {
+            GSList *sibling_data;
+            gpointer parent_data;
 
-      current_frame->parser->fail_handler(current_frame->data_for_children,
-                                          current_frame->data_from_children,
-                                          sibling_data,
-                                          parent_data,
-                                          sax_data->global_data,
-                                          &current_frame->frame_data,
-                                          current_frame->tag);
-    }
+            if ((*stack)->next == NULL)
+            {
+                /* This is the top of the stack... */
+                parent_data = NULL;
+                sibling_data = NULL;
+            }
+            else
+            {
+                sixtp_stack_frame *parent_frame =
+                    (sixtp_stack_frame *) (*stack)->next->data;
+                parent_data = parent_frame->data_for_children;
+                sibling_data = parent_frame->data_from_children;
+            }
 
-    /* now cleanup any children's results */
-    for(lp = current_frame->data_from_children; lp; lp = lp->next) 
-    {
-      sixtp_child_result *cresult = (sixtp_child_result *) lp->data;
-      if(cresult->fail_handler) 
-      {
-          cresult->fail_handler(cresult);
-      }
-    }
+            current_frame->parser->fail_handler(current_frame->data_for_children,
+                                                current_frame->data_from_children,
+                                                sibling_data,
+                                                parent_data,
+                                                sax_data->global_data,
+                                                &current_frame->frame_data,
+                                                current_frame->tag);
+        }
 
-    if((*stack)->next == NULL) 
-    {
-      /* This is the top of the stack. The top frame seems to want to
-       * be destroyed by sixtp_context_destroy. */
-      break;
+        /* now cleanup any children's results */
+        for (lp = current_frame->data_from_children; lp; lp = lp->next)
+        {
+            sixtp_child_result *cresult = (sixtp_child_result *) lp->data;
+            if (cresult->fail_handler)
+            {
+                cresult->fail_handler(cresult);
+            }
+        }
+
+        if ((*stack)->next == NULL)
+        {
+            /* This is the top of the stack. The top frame seems to want to
+             * be destroyed by sixtp_context_destroy. */
+            break;
+        }
+
+        *stack = sixtp_pop_and_destroy_frame(*stack);
     }
-
-    *stack = sixtp_pop_and_destroy_frame(*stack);
-  }
 }
 
 static gboolean
@@ -674,19 +678,19 @@
                         gpointer parent_data, gpointer global_data,
                         gpointer *result, const gchar *tag)
 {
-  return TRUE;
+    return TRUE;
 }
 
 static gboolean
 sixtp_parse_file_common(sixtp *sixtp,
-			xmlParserCtxtPtr xml_context,
-			gpointer data_for_top_level,
-			gpointer global_data,
-			gpointer *parse_result) 
+                        xmlParserCtxtPtr xml_context,
+                        gpointer data_for_top_level,
+                        gpointer global_data,
+                        gpointer *parse_result)
 {
     sixtp_parser_context *ctxt;
 
-    if(!(ctxt = sixtp_context_new(sixtp, global_data, data_for_top_level)))
+    if (!(ctxt = sixtp_context_new(sixtp, global_data, data_for_top_level)))
     {
         g_critical("sixtp_context_new returned null");
         return FALSE;
@@ -701,16 +705,16 @@
 
     sixtp_context_run_end_handler(ctxt);
 
-    if(ctxt->data.parsing_ok)
+    if (ctxt->data.parsing_ok)
     {
-        if(parse_result)
+        if (parse_result)
             *parse_result = ctxt->top_frame->frame_data;
         sixtp_context_destroy(ctxt);
         return TRUE;
     }
     else
     {
-        if(parse_result)
+        if (parse_result)
             *parse_result = NULL;
         if (g_slist_length(ctxt->data.stack) > 1)
             sixtp_handle_catastrophe(&ctxt->data);
@@ -724,7 +728,7 @@
                  const char *filename,
                  gpointer data_for_top_level,
                  gpointer global_data,
-                 gpointer *parse_result) 
+                 gpointer *parse_result)
 {
     gboolean ret;
     xmlParserCtxtPtr context;
@@ -732,7 +736,8 @@
 #ifdef G_OS_WIN32
     {
         gchar *conv_name = g_win32_locale_filename_from_utf8(filename);
-        if (!conv_name) {
+        if (!conv_name)
+        {
             g_warning("Could not convert '%s' to system codepage", filename);
             return FALSE;
         }
@@ -753,7 +758,7 @@
                    int bufsz,
                    gpointer data_for_top_level,
                    gpointer global_data,
-                   gpointer *parse_result) 
+                   gpointer *parse_result)
 {
     gboolean ret;
     xmlParserCtxtPtr context = xmlCreateMemoryParserCtxt( bufp, bufsz );
@@ -773,12 +778,14 @@
     sixtp_parser_context *ctxt;
     xmlParserCtxtPtr xml_context;
 
-    if (!push_handler) {
+    if (!push_handler)
+    {
         g_critical("No push handler specified");
         return FALSE;
     }
 
-    if (!(ctxt = sixtp_context_new(sixtp, global_data, data_for_top_level))) {
+    if (!(ctxt = sixtp_context_new(sixtp, global_data, data_for_top_level)))
+    {
         g_critical("sixtp_context_new returned null");
         return FALSE;
     }
@@ -787,18 +794,21 @@
                                           NULL, 0, NULL);
     ctxt->data.saxParserCtxt = xml_context;
     ctxt->data.bad_xml_parser = sixtp_dom_parser_new(gnc_bad_xml_end_handler,
-                                                     NULL, NULL);
+                                NULL, NULL);
 
     (*push_handler)(xml_context, push_user_data);
 
     sixtp_context_run_end_handler(ctxt);
 
-    if (ctxt->data.parsing_ok) {
+    if (ctxt->data.parsing_ok)
+    {
         if (parse_result)
             *parse_result = ctxt->top_frame->frame_data;
         sixtp_context_destroy(ctxt);
         return TRUE;
-    } else {
+    }
+    else
+    {
         if (parse_result)
             *parse_result = NULL;
         if (g_slist_length(ctxt->data.stack) > 1)
@@ -812,12 +822,12 @@
 static gboolean
 eat_whitespace(char **cursor)
 {
-    while(**cursor && isspace(**cursor))
+    while (**cursor && isspace(**cursor))
     {
         (*cursor)++;
     }
 
-    if(**cursor == '\0')
+    if (**cursor == '\0')
     {
         return FALSE;
     }
@@ -830,12 +840,12 @@
 static gboolean
 search_for(unsigned char marker, char **cursor)
 {
-    while(**cursor && **cursor != marker)
+    while (**cursor && **cursor != marker)
     {
         (*cursor)++;
     }
 
-    if(**cursor == '\0')
+    if (**cursor == '\0')
     {
         return FALSE;
     }
@@ -850,87 +860,92 @@
 gnc_is_our_xml_file(const char *filename, const char *first_tag,
                     gboolean *with_encoding)
 {
-  FILE *f = NULL;
-  char first_chunk[256];
-  ssize_t num_read;
+    FILE *f = NULL;
+    char first_chunk[256];
+    ssize_t num_read;
 
-  g_return_val_if_fail(filename, FALSE);
-  g_return_val_if_fail(first_tag, FALSE);
+    g_return_val_if_fail(filename, FALSE);
+    g_return_val_if_fail(first_tag, FALSE);
 
-  f = g_fopen(filename, "r");
-  if (f == NULL) {
-    return FALSE;
-  }
+    f = g_fopen(filename, "r");
+    if (f == NULL)
+    {
+        return FALSE;
+    }
 
-  num_read = fread(first_chunk, sizeof(char), sizeof(first_chunk) - 1, f);
-  fclose(f);
+    num_read = fread(first_chunk, sizeof(char), sizeof(first_chunk) - 1, f);
+    fclose(f);
 
-  if(num_read == 0)
-  {
-      return FALSE;
-  }
+    if (num_read == 0)
+    {
+        return FALSE;
+    }
 
-  first_chunk[num_read] = '\0';
+    first_chunk[num_read] = '\0';
 
-  return gnc_is_our_first_xml_chunk(first_chunk, first_tag, with_encoding);
+    return gnc_is_our_first_xml_chunk(first_chunk, first_tag, with_encoding);
 }
 
 gboolean
 gnc_is_our_first_xml_chunk(char *chunk, const char *first_tag,
                            gboolean *with_encoding)
 {
-  char *cursor = NULL;
+    char *cursor = NULL;
 
-  if (with_encoding) {
-    *with_encoding = FALSE;
-  }
+    if (with_encoding)
+    {
+        *with_encoding = FALSE;
+    }
 
-  cursor = chunk;
+    cursor = chunk;
 
-  if(!eat_whitespace(&cursor))
-  {
-      return FALSE;
-  }
+    if (!eat_whitespace(&cursor))
+    {
+        return FALSE;
+    }
 
-  if(strncmp(cursor, "<?xml", 5) == 0)
-  {
-      char *tag_compare;
-      gboolean result;
+    if (strncmp(cursor, "<?xml", 5) == 0)
+    {
+        char *tag_compare;
+        gboolean result;
 
-      if(!search_for('>', &cursor))
-      {
-          return FALSE;
-      }
+        if (!search_for('>', &cursor))
+        {
+            return FALSE;
+        }
 
-      if(!eat_whitespace(&cursor))
-      {
-          return FALSE;
-      }
+        if (!eat_whitespace(&cursor))
+        {
+            return FALSE;
+        }
 
-      tag_compare = g_strdup_printf("<%s", first_tag);
+        tag_compare = g_strdup_printf("<%s", first_tag);
 
-      result = (strncmp(cursor, tag_compare, strlen(tag_compare)) == 0);
-      g_free (tag_compare);
+        result = (strncmp(cursor, tag_compare, strlen(tag_compare)) == 0);
+        g_free (tag_compare);
 
-      if (result && with_encoding) {
-        *cursor = '\0';
-        cursor = chunk;
-        while (search_for('e', &cursor)) {
-          if (strncmp(cursor, "ncoding=", 8) == 0) {
-            *with_encoding = TRUE;
-            break;
-          }
+        if (result && with_encoding)
+        {
+            *cursor = '\0';
+            cursor = chunk;
+            while (search_for('e', &cursor))
+            {
+                if (strncmp(cursor, "ncoding=", 8) == 0)
+                {
+                    *with_encoding = TRUE;
+                    break;
+                }
+            }
         }
-      }
 
-      return result;
-  }
-  else
-  {
-      return FALSE;
-  }
+        return result;
+    }
+    else
+    {
+        return FALSE;
+    }
 
-  return FALSE;
+    return FALSE;
 }
 
 /************************* END OF FILE *********************************/

Modified: gnucash/trunk/src/backend/xml/sixtp.h
===================================================================
--- gnucash/trunk/src/backend/xml/sixtp.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/sixtp.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -43,23 +43,23 @@
                                         gchar **attrs);
 
 typedef gboolean (*sixtp_before_child_handler)(gpointer data_for_children,
-                                               GSList* data_from_children,
-                                               GSList* sibling_data,
-                                               gpointer parent_data,
-                                               gpointer global_data,
-                                               gpointer *result,
-                                               const gchar *tag,
-                                               const gchar *child_tag);
+        GSList* data_from_children,
+        GSList* sibling_data,
+        gpointer parent_data,
+        gpointer global_data,
+        gpointer *result,
+        const gchar *tag,
+        const gchar *child_tag);
 
 typedef gboolean (*sixtp_after_child_handler)(gpointer data_for_children,
-                                              GSList* data_from_children,
-                                              GSList* sibling_data,
-                                              gpointer parent_data,
-                                              gpointer global_data,
-                                              gpointer *result,
-                                              const gchar *tag,
-                                              const gchar *child_tag,
-                                              sixtp_child_result *child_result);
+        GSList* data_from_children,
+        GSList* sibling_data,
+        gpointer parent_data,
+        gpointer global_data,
+        gpointer *result,
+        const gchar *tag,
+        const gchar *child_tag,
+        sixtp_child_result *child_result);
 
 typedef gboolean (*sixtp_end_handler)(gpointer data_for_children,
                                       GSList* data_from_children,
@@ -70,11 +70,11 @@
                                       const gchar *tag);
 
 typedef gboolean (*sixtp_characters_handler)(GSList *sibling_data,
-                                             gpointer parent_data,
-                                             gpointer global_data,
-                                             gpointer *result,
-                                             const char *text,
-                                             int length);
+        gpointer parent_data,
+        gpointer global_data,
+        gpointer *result,
+        const char *text,
+        int length);
 
 typedef void (*sixtp_result_handler)(sixtp_child_result *result);
 
@@ -89,32 +89,33 @@
 typedef void (*sixtp_push_handler)(xmlParserCtxtPtr xml_context,
                                    gpointer user_data);
 
-typedef struct sixtp 
+typedef struct sixtp
 {
-  /* If you change this, don't forget to modify all the copy/etc. functions */
-  sixtp_start_handler start_handler;
-  sixtp_before_child_handler before_child;
-  sixtp_after_child_handler after_child;
-  sixtp_end_handler end_handler;
-  sixtp_characters_handler characters_handler;
+    /* If you change this, don't forget to modify all the copy/etc. functions */
+    sixtp_start_handler start_handler;
+    sixtp_before_child_handler before_child;
+    sixtp_after_child_handler after_child;
+    sixtp_end_handler end_handler;
+    sixtp_characters_handler characters_handler;
 
-  sixtp_fail_handler fail_handler; 
-  /* called for failures before the close tag */
+    sixtp_fail_handler fail_handler;
+    /* called for failures before the close tag */
 
-  sixtp_result_handler cleanup_result; /* called unless failure */
-  sixtp_result_handler cleanup_chars; /* called unless failure */
+    sixtp_result_handler cleanup_result; /* called unless failure */
+    sixtp_result_handler cleanup_chars; /* called unless failure */
 
-  sixtp_result_handler result_fail_handler;
-  /* called to cleanup results from this node on failure */
+    sixtp_result_handler result_fail_handler;
+    /* called to cleanup results from this node on failure */
 
-  sixtp_result_handler chars_fail_handler;
-  /* called to cleanup character results when cleaning up this node's
-     children. */
+    sixtp_result_handler chars_fail_handler;
+    /* called to cleanup character results when cleaning up this node's
+       children. */
 
-  GHashTable *child_parsers;
+    GHashTable *child_parsers;
 } sixtp;
 
-typedef enum {
+typedef enum
+{
     SIXTP_NO_MORE_HANDLERS,
 
     SIXTP_START_HANDLER_ID,
@@ -136,31 +137,34 @@
 /* completely invalid tag for xml */
 #define SIXTP_MAGIC_CATCHER "&MAGIX&"
 
-typedef enum {
-  SIXTP_CHILD_RESULT_CHARS,
-  SIXTP_CHILD_RESULT_NODE
+typedef enum
+{
+    SIXTP_CHILD_RESULT_CHARS,
+    SIXTP_CHILD_RESULT_NODE
 } sixtp_child_result_type;
 
-struct _sixtp_child_result {
-  sixtp_child_result_type type;
-  gchar *tag; /* NULL for a CHARS node. */
-  gpointer data;
-  gboolean should_cleanup;
-  sixtp_result_handler cleanup_handler;
-  sixtp_result_handler fail_handler;
+struct _sixtp_child_result
+{
+    sixtp_child_result_type type;
+    gchar *tag; /* NULL for a CHARS node. */
+    gpointer data;
+    gboolean should_cleanup;
+    sixtp_result_handler cleanup_handler;
+    sixtp_result_handler fail_handler;
 };
 
-typedef struct sixtp_sax_data {
-  gboolean parsing_ok;
-  GSList *stack;
-  gpointer global_data;
-  xmlParserCtxtPtr saxParserCtxt;
-  sixtp *bad_xml_parser;
+typedef struct sixtp_sax_data
+{
+    gboolean parsing_ok;
+    GSList *stack;
+    gpointer global_data;
+    xmlParserCtxtPtr saxParserCtxt;
+    sixtp *bad_xml_parser;
 } sixtp_sax_data;
 
 
 gboolean is_child_result_from_node_named(sixtp_child_result *cr,
-                                         const char *tag);
+        const char *tag);
 void sixtp_child_free_data(sixtp_child_result *result);
 void sixtp_child_result_destroy(sixtp_child_result *r);
 void sixtp_child_result_print(sixtp_child_result *cr, FILE *f);

Modified: gnucash/trunk/src/backend/xml/test/test-date-converting.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-date-converting.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-date-converting.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -15,41 +15,41 @@
 {
     int i;
 
-    for(i = 0; i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         Timespec *spec1;
         Timespec spec2;
         gchar *sec_str;
         gchar *nsec_str;
-        
+
         spec1 = get_random_timespec();
 
         sec_str = timespec_sec_to_string(spec1);
         nsec_str = timespec_nsec_to_string(spec1);
 
-        if(!string_to_timespec_secs(sec_str, &spec2))
+        if (!string_to_timespec_secs(sec_str, &spec2))
         {
-            failure_args("string_to_timespec_secs", __FILE__, __LINE__, 
+            failure_args("string_to_timespec_secs", __FILE__, __LINE__,
                          "string is %s", sec_str);
         }
 
-        else if(!string_to_timespec_nsecs(nsec_str, &spec2))
+        else if (!string_to_timespec_nsecs(nsec_str, &spec2))
         {
-            failure_args("string_to_timespec_nsecs", __FILE__, __LINE__, 
+            failure_args("string_to_timespec_nsecs", __FILE__, __LINE__,
                          "string is %s", nsec_str);
         }
 
-        else if(spec1->tv_sec != spec2.tv_sec)
+        else if (spec1->tv_sec != spec2.tv_sec)
         {
-            failure_args("timespec_secs", __FILE__, __LINE__, 
+            failure_args("timespec_secs", __FILE__, __LINE__,
                          "not equal ints are %" G_GINT64_FORMAT
                          " and %" G_GINT64_FORMAT "\n",
                          spec1->tv_sec, spec2.tv_sec);
         }
 
-        else if(spec1->tv_nsec != spec2.tv_nsec)
+        else if (spec1->tv_nsec != spec2.tv_nsec)
         {
-            failure_args("timespec_nsecs", __FILE__, __LINE__, 
+            failure_args("timespec_nsecs", __FILE__, __LINE__,
                          "not equal ints are %ld and %ld\n",
                          spec1->tv_nsec, spec2.tv_nsec);
         }

Modified: gnucash/trunk/src/backend/xml/test/test-dom-converters1.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-dom-converters1.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-dom-converters1.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -21,7 +21,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  *  02110-1301, USA.
  */
- 
+
 #include "config.h"
 
 #include <stdlib.h>
@@ -47,7 +47,7 @@
 test_dom_tree_to_commodity_ref(void)
 {
     int i;
-    for(i = 0; i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         gnc_commodity *test_com1;
         gchar *test_str1;
@@ -60,14 +60,14 @@
 
         test_str1 = get_random_string();
         test_str2 = get_random_string();
-        
+
         test_com1 = gnc_commodity_new(book, NULL, test_str1, test_str2, NULL, 0);
         test_node = commodity_ref_to_dom_tree("test-com", test_com1);
 
         test_com2 = dom_tree_to_commodity_ref_no_engine(test_node, book);
 
         do_test(gnc_commodity_equiv(test_com1, test_com2),
-                            "dom_tree_to_commodity_ref_no_engine");
+                "dom_tree_to_commodity_ref_no_engine");
 
         xmlFreeNode(test_node);
         gnc_commodity_destroy(test_com1);
@@ -75,7 +75,7 @@
         g_free(test_str1);
         g_free(test_str2);
 
-	qof_book_destroy (book);
+        qof_book_destroy (book);
     }
 }
 
@@ -84,7 +84,7 @@
 {
     int i;
 
-    for(i = 0; i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         gchar *test_string1;
         gchar *test_string2;
@@ -97,13 +97,13 @@
 
         test_string2 = dom_tree_to_text(test_node);
 
-        if(!test_string2)
+        if (!test_string2)
         {
-            failure_args("dom_tree_to_text", __FILE__, __LINE__, 
+            failure_args("dom_tree_to_text", __FILE__, __LINE__,
                          "null return from dom_tree_to_text");
             xmlElemDump(stdout, NULL, test_node);
         }
-        else if(safe_strcmp(test_string1, test_string2) == 0)
+        else if (safe_strcmp(test_string1, test_string2) == 0)
         {
             success_args("dom_tree_to_text", __FILE__, __LINE__, "with string %s",
                          test_string1);
@@ -116,7 +116,7 @@
 
         xmlFreeNode(test_node);
         g_free(test_string1);
-        if(test_string2) g_free(test_string2);
+        if (test_string2) g_free(test_string2);
     }
 }
 
@@ -125,7 +125,7 @@
 test_dom_tree_to_timespec(void)
 {
     int i;
-    for(i = 0; i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         Timespec *test_spec1;
         Timespec test_spec2;
@@ -137,7 +137,7 @@
 
         test_spec2 = dom_tree_to_timespec(test_node);
 
-	if (!dom_tree_valid_timespec(&test_spec2, (const xmlChar*)"test-spec"))
+        if (!dom_tree_valid_timespec(&test_spec2, (const xmlChar*)"test-spec"))
         {
             failure_args("dom_tree_to_timespec",
                          __FILE__, __LINE__, "NULL return");
@@ -145,8 +145,8 @@
             xmlElemDump(stdout, NULL, test_node);
             printf("\n");
         }
-        
-        else if(timespec_cmp(test_spec1, &test_spec2) == 0)
+
+        else if (timespec_cmp(test_spec1, &test_spec2) == 0)
         {
             success("dom_tree_to_timespec");
         }
@@ -177,35 +177,35 @@
     xmlNodePtr to_gen = NULL;
 
     to_gen = gnc_numeric_to_dom_tree("test-num", &to_test);
-    if(!to_gen)
+    if (!to_gen)
     {
         ret =  "no dom tree created";
     }
     else
     {
         to_compare = dom_tree_to_gnc_numeric(to_gen);
-        if(!to_compare)
+        if (!to_compare)
         {
             ret = "no gnc_numeric parsed";
         }
         else
         {
-            if(!gnc_numeric_equal(to_test, *to_compare))
+            if (!gnc_numeric_equal(to_test, *to_compare))
             {
                 ret = "numerics compared different";
             }
         }
     }
 
-    if(to_compare)
+    if (to_compare)
     {
         g_free(to_compare);
     }
-    if(to_gen)
+    if (to_gen)
     {
         xmlFreeNode(to_gen);
     }
-    
+
     return ret;
 }
 
@@ -214,7 +214,7 @@
 {
     int i;
 
-    for(i = 0; i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         gchar *message = NULL;
 
@@ -228,7 +228,7 @@
         gchar *message = NULL;
 
         message = test_gnc_nums_internal
-          (gnc_numeric_create(18768786810LL, 100000));
+                  (gnc_numeric_create(18768786810LL, 100000));
 
         do_test_args(message == NULL, "gnc_num 18768786810/100000",
                      __FILE__, __LINE__, message);
@@ -240,7 +240,7 @@
 test_dom_tree_to_guid(void)
 {
     int i;
-    for(i = 0;i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         GUID *test_guid1;
         GUID *test_guid2;
@@ -250,14 +250,14 @@
 
         if (!(test_node = guid_to_dom_tree("test-guid", test_guid1)))
         {
-             failure_args("guid_to_dom_tree", __FILE__, __LINE__, 
-                          "conversion to dom tree failed");
+            failure_args("guid_to_dom_tree", __FILE__, __LINE__,
+                         "conversion to dom tree failed");
         }
 
         test_guid2 = dom_tree_to_guid(test_node);
 
         do_test(guid_equal(test_guid1, test_guid2),
-                            "dom_tree_to_guid" );
+                "dom_tree_to_guid" );
 
         xmlFreeNode(test_node);
         g_free(test_guid1);
@@ -268,8 +268,8 @@
 int
 main(int argc, char **argv)
 {
-     qof_init();
-     cashobjects_register();
+    qof_init();
+    cashobjects_register();
     test_dom_tree_to_guid();
     fflush(stdout);
     test_dom_tree_to_commodity_ref();
@@ -281,6 +281,6 @@
     test_dom_tree_to_gnc_numeric();
     fflush(stdout);
     print_test_results();
-     qof_close();
+    qof_close();
     exit(get_rv());
 }

Modified: gnucash/trunk/src/backend/xml/test/test-dom-parser1.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-dom-parser1.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-dom-parser1.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -22,7 +22,7 @@
     ret = sixtp_new();
     g_return_val_if_fail(ret, NULL);
     sixtp_set_chars(ret, allow_and_ignore_only_whitespace);
-    
+
     sixtp_add_sub_parser(ret, "foobar",
                          sixtp_dom_parser_new(print_dom_tree, NULL, NULL));
 

Modified: gnucash/trunk/src/backend/xml/test/test-file-stuff.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-file-stuff.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-file-stuff.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -20,7 +20,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  *  02110-1301, USA.
  */
- 
+
 #include "config.h"
 
 #include <unistd.h>
@@ -68,17 +68,18 @@
         amount_read1 = read(fd1, buf1, 512);
         amount_read2 = read(fd2, buf2, 512);
 
-        if(amount_read1 > amount_read2)
+        if (amount_read1 > amount_read2)
             return files_return(1, "read1 > read2");
-        if(amount_read1 < amount_read2)
+        if (amount_read1 < amount_read2)
             return files_return(-1, "read1 < read2");
 
-        if((memcmp_ret = memcmp(buf1, buf2, amount_read1)) != 0)
+        if ((memcmp_ret = memcmp(buf1, buf2, amount_read1)) != 0)
         {
             return files_return(memcmp_ret, "memcmp return");
         }
 
-    } while(amount_read1 == 512);
+    }
+    while (amount_read1 == 512);
 
     return 0;
 }
@@ -100,7 +101,7 @@
                GSList* sibling_data, gpointer parent_data,
                gpointer global_data, gpointer *result, const gchar *tag)
 {
-    if (parent_data == NULL) 
+    if (parent_data == NULL)
     {
         xmlElemDump((FILE*)global_data, NULL, (xmlNodePtr)data_for_children);
         xmlFreeNode(data_for_children);
@@ -121,7 +122,7 @@
                          FALSE);
 
     verteststr = (char*) node->properties->xmlAttrPropertyValue->content;
-    if(safe_strcmp(verstr, verteststr) == 0)
+    if (safe_strcmp(verstr, verteststr) == 0)
     {
         return TRUE;
     }
@@ -138,19 +139,19 @@
 
     g_return_val_if_fail(node, FALSE);
     g_return_val_if_fail(str, FALSE);
-    
+
     cmp1 = dom_tree_to_text(node);
 
-    if(!cmp1)
+    if (!cmp1)
     {
         return FALSE;
     }
-    else if(safe_strcmp(cmp1, str) == 0)
+    else if (safe_strcmp(cmp1, str) == 0)
     {
         g_free(cmp1);
         return TRUE;
     }
-    else 
+    else
     {
         printf("Differing types: node:`%s' vs string:`%s'\n", cmp1, str);
         g_free(cmp1);
@@ -163,12 +164,12 @@
 {
     gchar *text;
     gint64 test_val;
-    
+
     g_return_val_if_fail(node, FALSE);
 
     text = dom_tree_to_text(node);
 
-    if(!string_to_gint64(text, &test_val))
+    if (!string_to_gint64(text, &test_val))
     {
         g_free(text);
         return FALSE;
@@ -196,8 +197,8 @@
     cmpid = dom_tree_to_guid(node);
 
     g_return_val_if_fail(cmpid, FALSE);
-    
-    if(guid_compare(cmpid, id) == 0)
+
+    if (guid_compare(cmpid, id) == 0)
     {
         g_free(cmpid);
         return TRUE;
@@ -210,7 +211,7 @@
 }
 
 gboolean
-equals_node_val_vs_commodity(xmlNodePtr node, const gnc_commodity *com, 
+equals_node_val_vs_commodity(xmlNodePtr node, const gnc_commodity *com,
                              QofBook *book)
 {
     gnc_commodity *cmpcom;
@@ -222,7 +223,7 @@
 
     g_return_val_if_fail(cmpcom, FALSE);
 
-    if(gnc_commodity_equiv(com, cmpcom))
+    if (gnc_commodity_equiv(com, cmpcom))
     {
         gnc_commodity_destroy(cmpcom);
         return TRUE;
@@ -246,7 +247,7 @@
 
     g_return_val_if_fail(cmpfrm, FALSE);
 
-    if(kvp_frame_compare(frm, cmpfrm) == 0)
+    if (kvp_frame_compare(frm, cmpfrm) == 0)
     {
         kvp_frame_delete(cmpfrm);
         return TRUE;
@@ -263,7 +264,7 @@
 
         g_free(frm1str);
         g_free(frm2str);
-        
+
         kvp_frame_delete(cmpfrm);
         return FALSE;
     }
@@ -274,7 +275,7 @@
 {
     Timespec tm_test = dom_tree_to_timespec(node);
 
-    if(tm_test.tv_sec == tm.tv_sec && tm_test.tv_nsec == tm.tv_nsec)
+    if (tm_test.tv_sec == tm.tv_sec && tm_test.tv_nsec == tm.tv_nsec)
     {
         return TRUE;
     }
@@ -295,18 +296,18 @@
     xmlNodePtr tree = (xmlNodePtr)data_for_children;
     xmlNodePtr *globaldata = (xmlNodePtr*)global_data;
 
-    if(parent_data)
+    if (parent_data)
     {
         return TRUE;
     }
 
     /* OK.  For some messed up reason this is getting called again with a
        NULL tag.  So we ignore those cases */
-    if(!tag)
+    if (!tag)
     {
         return TRUE;
     }
-    
+
     g_return_val_if_fail(tree, FALSE);
 
     *globaldata = tree;
@@ -320,20 +321,20 @@
     sixtp *parser;
     xmlNodePtr ret;
     gpointer parse_result = NULL;
-    
+
     parser = sixtp_dom_parser_new(just_dom_tree_end_handler, NULL, NULL);
 
     sixtp_parse_file(parser, filename, NULL, &ret, &parse_result);
 
     return ret;
 }
-    
+
 static void
-test_load_file(const char *filename, gxpf_callback cb, sixtp *top_parser, 
+test_load_file(const char *filename, gxpf_callback cb, sixtp *top_parser,
                QofBook *book)
 {
     xmlNodePtr node;
-    
+
     node = grab_file_doc(filename);
 
     if (!node)
@@ -351,7 +352,7 @@
 
     xmlFreeNode(node);
 }
-    
+
 void
 test_files_in_dir(int argc, char **argv, gxpf_callback cb,
                   sixtp *parser, const char *parser_tag,
@@ -368,24 +369,24 @@
     if (!sixtp_add_some_sub_parsers(top_parser, TRUE, "gnc-v2", main_parser,
                                     NULL, NULL))
         return;
-    
+
     if (!sixtp_add_some_sub_parsers(main_parser, TRUE, parser_tag, parser,
                                     NULL, NULL))
         return;
 
 
-    for(count = 1; count < argc; count++)
+    for (count = 1; count < argc; count++)
     {
         struct stat file_info;
         const char *to_open = argv[count];
-        if(g_stat(to_open, &file_info) != 0)
+        if (g_stat(to_open, &file_info) != 0)
         {
             printf("cannot stat %s.\n", to_open);
             failure("unable to stat file");
         }
         else
         {
-            if(!S_ISDIR(file_info.st_mode))
+            if (!S_ISDIR(file_info.st_mode))
             {
 #if 0
                 printf( "testing load of file \"%s\":\n", argv[count] );
@@ -394,6 +395,6 @@
             }
         }
     }
-    
+
     sixtp_destroy(top_parser);
 }

Modified: gnucash/trunk/src/backend/xml/test/test-kvp-frames.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-kvp-frames.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-kvp-frames.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -19,7 +19,7 @@
 {
     const kvp_value *test_val2;
     test_val2 = kvp_frame_get_slot(test_frame1, test_key);
-    if(kvp_value_compare(test_val1, test_val2) == 0)
+    if (kvp_value_compare(test_val1, test_val2) == 0)
     {
         success_args("kvp_frame_get_slot", __FILE__, __LINE__, "run=%d", run);
     }
@@ -45,10 +45,10 @@
     do_test_args(test_frame2 != NULL, "kvp_frame_copy",
                  __FILE__, __LINE__, "run=%d", run);
 
-    if(kvp_frame_compare(test_frame1, test_frame2) == 0)
+    if (kvp_frame_compare(test_frame1, test_frame2) == 0)
     {
         success_args("kvp_frame_copy->kvp_frame_compare",
-                     __FILE__, __LINE__, "run=%d",run);
+                     __FILE__, __LINE__, "run=%d", run);
     }
     else
     {
@@ -76,7 +76,7 @@
 
     test_frame2 = kvp_frame_copy(test_frame1);
     test_val2 = kvp_frame_get_slot(test_frame2, test_key);
-    if(kvp_value_compare(test_val1, test_val2) == 0)
+    if (kvp_value_compare(test_val1, test_val2) == 0)
     {
         success_args("kvp_frame_copy->kvp_frame_get_slot",
                      __FILE__, __LINE__, "run=%d", run);
@@ -93,17 +93,17 @@
         printf("Frame2 is %s\n", tmp);
         g_free(tmp);
     }
-    kvp_frame_delete(test_frame2); 
+    kvp_frame_delete(test_frame2);
 }
 
 static void
 test_kvp_create_delete(void)
 {
     kvp_frame *test_frame;
-    
+
     test_frame = kvp_frame_new();
 
-    if(test_frame != NULL)
+    if (test_frame != NULL)
     {
         kvp_frame_delete(test_frame);
         test_frame = NULL;
@@ -119,8 +119,8 @@
 test_kvp_frames1(void)
 {
     int i;
-    
-    for(i = 0; i < 20; i++)
+
+    for (i = 0; i < 20; i++)
     {
         kvp_frame *test_frame1;
         gchar *test_key;
@@ -147,11 +147,11 @@
 test_kvp_printing(void)
 {
     int i;
-    for(i = 0; i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         kvp_frame *ran_frame;
         gchar *char_rep;
-        
+
         ran_frame = get_random_kvp_frame();
         char_rep = kvp_frame_to_string(ran_frame);
 
@@ -167,7 +167,7 @@
 test_kvp_xml_stuff(void)
 {
     int i;
-    for(i = 0; i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         kvp_frame *test_frame1;
         kvp_frame *test_frame2;
@@ -177,16 +177,16 @@
 
         test_node = kvp_frame_to_dom_tree("test-kvp", test_frame1);
 
-        if(!test_node)
+        if (!test_node)
         {
-            failure_args("xml stuff",__FILE__, __LINE__, 
+            failure_args("xml stuff", __FILE__, __LINE__,
                          "kvp_frame_to_dom_tree produced NULL");
         }
         else
         {
             test_frame2 = dom_tree_to_kvp_frame(test_node);
 
-            if(kvp_frame_compare(test_frame1, test_frame2) == 0)
+            if (kvp_frame_compare(test_frame1, test_frame2) == 0)
             {
                 success("xml stuff");
             }
@@ -207,7 +207,7 @@
             kvp_frame_delete(test_frame2);
             xmlFreeNode(test_node);
         }
-        
+
         kvp_frame_delete(test_frame1);
     }
 }

Modified: gnucash/trunk/src/backend/xml/test/test-load-backend.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-load-backend.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-load-backend.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -24,7 +24,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  *  02110-1301, USA.
  */
- 
+
 #include "config.h"
 #include "qof.h"
 #include "cashobjects.h"

Modified: gnucash/trunk/src/backend/xml/test/test-load-example-account.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-load-example-account.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-load-example-account.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -20,7 +20,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  *  02110-1301, USA.
  */
- 
+
 #include "config.h"
 #include <glib.h>
 #include <libguile.h>
@@ -51,7 +51,7 @@
 
     gea = gnc_read_example_account(filename);
 
-    if(gea != NULL)
+    if (gea != NULL)
     {
         success("example account load");
         gnc_destroy_example_account(gea);
@@ -78,7 +78,7 @@
     gnc_module_system_init();
     gnc_module_load("gnucash/engine", 0);
 
-    if((ea_dir = g_dir_open(location, 0, NULL)) == NULL)
+    if ((ea_dir = g_dir_open(location, 0, NULL)) == NULL)
     {
         failure("unable to open ea directory");
     }
@@ -86,9 +86,9 @@
     {
         const gchar *entry;
 
-        while((entry = g_dir_read_name(ea_dir)) != NULL)
+        while ((entry = g_dir_read_name(ea_dir)) != NULL)
         {
-            if(g_str_has_suffix(entry, da_ending))
+            if (g_str_has_suffix(entry, da_ending))
             {
                 gchar *to_open = g_build_filename(location, entry, (gchar*)NULL);
                 if (!g_file_test(to_open, G_FILE_TEST_IS_DIR))
@@ -100,16 +100,16 @@
         }
     }
     g_dir_close(ea_dir);
-    
+
     {
         list = gnc_load_example_account_list(location);
 
         do_test(list != NULL, "gnc_load_example_account_list");
-        
+
         gnc_free_example_account_list(list);
     }
-    
-    
+
+
     print_test_results();
     exit(get_rv());
 }
@@ -117,6 +117,6 @@
 int
 main (int argc, char ** argv)
 {
-  scm_boot_guile (argc, argv, guile_main, NULL);
-  exit(get_rv());
+    scm_boot_guile (argc, argv, guile_main, NULL);
+    exit(get_rv());
 }

Modified: gnucash/trunk/src/backend/xml/test/test-load-xml2.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-load-xml2.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-load-xml2.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -21,7 +21,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  *  02110-1301, USA.
  */
- 
+
 /* @file test-load-xml2.c
  * @brief test the loading of a version-2 gnucash XML file
  */
@@ -59,16 +59,16 @@
 {
     struct stat buf;
     char *to_remove;
-    
+
     {
         to_remove = g_strdup_printf("%s.LCK", filename);
-        if(g_stat(to_remove, &buf) != -1)
+        if (g_stat(to_remove, &buf) != -1)
         {
             g_unlink(to_remove);
         }
         g_free(to_remove);
     }
-    
+
     remove_files_pattern(filename, ".LCK");
 }
 
@@ -95,7 +95,7 @@
              "book and root account don't match");
 
     do_test_args(qof_session_get_error(session) == ERR_BACKEND_NO_ERR,
-                 "session load xml2", __FILE__, __LINE__, 
+                 "session load xml2", __FILE__, __LINE__,
                  "qof error=%d for file [%s]",
                  qof_session_get_error(session), filename);
 
@@ -120,8 +120,8 @@
     }
 
     xaccLogDisable();
-    
-    if((xml2_dir = g_dir_open(location, 0, NULL)) == NULL)
+
+    if ((xml2_dir = g_dir_open(location, 0, NULL)) == NULL)
     {
         failure("unable to open xml2 directory");
     }
@@ -129,12 +129,12 @@
     {
         const gchar *entry;
 
-        while((entry = g_dir_read_name(xml2_dir)) != NULL)
+        while ((entry = g_dir_read_name(xml2_dir)) != NULL)
         {
-            if(g_str_has_suffix(entry, ".gml2"))
+            if (g_str_has_suffix(entry, ".gml2"))
             {
                 gchar *to_open = g_build_filename(location, entry, (gchar*)NULL);
-                if(!g_file_test(to_open, G_FILE_TEST_IS_DIR))
+                if (!g_file_test(to_open, G_FILE_TEST_IS_DIR))
                 {
                     test_load_file(to_open);
                 }

Modified: gnucash/trunk/src/backend/xml/test/test-save-in-lang.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-save-in-lang.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-save-in-lang.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -18,7 +18,8 @@
 
 #include "io-gncxml-v2.h"
 
-const char *possible_envs[] = {
+const char *possible_envs[] =
+{
     "C", "af", "ar", "az", "be", "bg", "bg_BG.cp1251", "br", "ca", "cs",
     "cy", "cz", "da", "de", "de_AT", "el", "en", "en_AU", "en_CA", "en_GB",
     "eo", "es", "es_DO", "es_ES", "es_GT", "es_HN", "es_MX", "es_PA",
@@ -33,7 +34,8 @@
     NULL
 };
 
-const char *possible_vars[] = {
+const char *possible_vars[] =
+{
     "LANG", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_NUMERIC",
     "LC_MONETARY", "LC_MESSAGES",
     NULL
@@ -67,14 +69,14 @@
 {
     int i;
 
-    for(i = 0; possible_envs[i] != NULL; i++)
+    for (i = 0; possible_envs[i] != NULL; i++)
     {
         QofBackendError err;
         QofSession *session;
         char *cmd;
         char *new_file = gen_new_file_name(filename, possible_envs[i]);
         QofSession *new_session;
-        
+
         session = qof_session_new();
 
         qof_session_begin(session, filename, TRUE, FALSE);
@@ -87,20 +89,20 @@
 
         qof_session_load(session, NULL);
         err = qof_session_pop_error (session);
-        if(err)
+        if (err)
         {
             qof_session_destroy(session);
             return g_strdup_printf("qof_session_load errorid %d", err);
         }
 
         if (!g_setenv("LANG", possible_envs[i], TRUE))
-          return g_strdup("setenv for LANG");
+            return g_strdup("setenv for LANG");
 
         new_session = qof_session_new();
-        
+
         qof_session_begin(new_session, new_file, FALSE, FALSE);
         err = qof_session_pop_error (new_session);
-        if(err)
+        if (err)
         {
             g_free(new_file);
             qof_session_destroy(session);
@@ -113,7 +115,7 @@
 
         cmd = g_strdup_printf(diff_command, filename, new_file);
 
-        if(run_command_get_return(cmd) != 0)
+        if (run_command_get_return(cmd) != 0)
         {
             g_free(cmd);
             g_free(new_file);
@@ -139,8 +141,8 @@
 
     gnc_engine_init(argc, argv);
     xaccLogDisable();
-    
-    if((adir = g_dir_open(test_dir, 0, NULL)) == NULL)
+
+    if ((adir = g_dir_open(test_dir, 0, NULL)) == NULL)
     {
         failure_args("g_dir_open", __FILE__, __LINE__,
                      "couldn't open dir %s", test_dir);
@@ -149,14 +151,14 @@
     {
         const gchar *next_file;
 
-        while((next_file = g_dir_read_name(adir)) != NULL)
+        while ((next_file = g_dir_read_name(adir)) != NULL)
         {
             struct stat file_info;
             char* filename;
 
             filename = g_build_filename(test_dir, next_file, (gchar*) NULL);
 
-            if(g_stat(filename, &file_info) != 0)
+            if (g_stat(filename, &file_info) != 0)
             {
                 failure_args("stat", __FILE__, __LINE__,
                              "couldn't stat file %s: %s", filename,
@@ -167,17 +169,17 @@
 
             if (!g_setenv("LANG", base_env, TRUE))
             {
-              failure_args("setenv", __FILE__, __LINE__,
-                           "setenv of LANG failed");
-              g_free(filename);
-              break;
+                failure_args("setenv", __FILE__, __LINE__,
+                             "setenv of LANG failed");
+                g_free(filename);
+                break;
             }
 
-            if(!S_ISDIR(file_info.st_mode))
+            if (!S_ISDIR(file_info.st_mode))
             {
                 char *msg = test_file(filename);
-                
-                if(msg != NULL)
+
+                if (msg != NULL)
                 {
                     failure_args("test_file", __FILE__, __LINE__,
                                  "failure testing file %s with msg %s",
@@ -190,7 +192,7 @@
         }
         g_dir_close(adir);
     }
-    
+
     print_test_results();
     exit(get_rv());
 }

Modified: gnucash/trunk/src/backend/xml/test/test-string-converters.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-string-converters.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-string-converters.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -15,49 +15,49 @@
 test_binary()
 {
     int i;
-    for(i = 0; i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         bin_data *test_data1;
         void *test_data2;
         guint64 test_data2_len;
         gchar *converted;
-        
+
         test_data1 = get_random_binary_data();
 
         converted = binary_to_string(test_data1->data, test_data1->len);
 
-        if(!converted)
+        if (!converted)
         {
             failure_args("binary_data", __FILE__, __LINE__, "binary_to_string returned NULL");
             continue;
         }
 
-        if(!string_to_binary(converted, &test_data2, &test_data2_len))
+        if (!string_to_binary(converted, &test_data2, &test_data2_len))
         {
-            failure_args("binary_data", __FILE__, __LINE__, 
+            failure_args("binary_data", __FILE__, __LINE__,
                          "string_to_binary returned FALSE with data:\n%s\n",
                          converted);
             continue;
         }
 
-        if(test_data2_len != test_data1->len)
+        if (test_data2_len != test_data1->len)
         {
-            failure_args("binary_data", __FILE__, __LINE__, 
+            failure_args("binary_data", __FILE__, __LINE__,
                          "lengths don't match: %" G_GINT64_FORMAT " vs %d",
                          test_data2_len, test_data1->len);
             continue;
         }
-        
+
         {
             int j;
             guchar *d1 = test_data1->data;
             guchar *d2 = (guchar*)test_data2;
-            
-            for(j = 0; j < test_data2_len; j++)
+
+            for (j = 0; j < test_data2_len; j++)
             {
-                if(d1[j] != d2[j])
+                if (d1[j] != d2[j])
                 {
-                    failure_args("binary_data", __FILE__, __LINE__, 
+                    failure_args("binary_data", __FILE__, __LINE__,
                                  "data doesn't match at point %d.\n%d vs %d",
                                  i, d1[j], d2[j]);
                     continue;
@@ -70,7 +70,8 @@
 }
 
 
-static char *test_strings[] = {
+static char *test_strings[] =
+{
     "FooBar",
     "<Ugly crap>",
     "Something with a & in it",
@@ -84,8 +85,8 @@
 {
     char *mark;
     int i;
-    
-    for(i = 0, mark = test_strings[i]; mark; i++, mark = test_strings[i])
+
+    for (i = 0, mark = test_strings[i]; mark; i++, mark = test_strings[i])
     {
         xmlNodePtr test_node;
         gchar *backout;

Modified: gnucash/trunk/src/backend/xml/test/test-xml-account.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-xml-account.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-xml-account.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -21,7 +21,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  *  02110-1301, USA.
  */
- 
+
 #include "config.h"
 
 #include <glib.h>
@@ -51,56 +51,56 @@
     xmlNodePtr mark;
 
     while (safe_strcmp ((char*)node->name, "text") == 0)
-	{
-      node = node->next;
-	}
+    {
+        node = node->next;
+    }
 
-    if(!check_dom_tree_version(node, "2.0.0"))
+    if (!check_dom_tree_version(node, "2.0.0"))
     {
         return g_strdup("version wrong.  Not 2.0.0 or not there");
     }
 
-    if(!node->name || safe_strcmp((char*)node->name, "gnc:account"))
+    if (!node->name || safe_strcmp((char*)node->name, "gnc:account"))
     {
         return g_strdup("Name of toplevel node is bad");
     }
 
-    for(mark = node->xmlChildrenNode; mark; mark = mark->next)
+    for (mark = node->xmlChildrenNode; mark; mark = mark->next)
     {
-        if(safe_strcmp((char*)mark->name, "text") == 0)
+        if (safe_strcmp((char*)mark->name, "text") == 0)
         {
         }
-        else if(safe_strcmp((char*)mark->name, "act:name") == 0)
+        else if (safe_strcmp((char*)mark->name, "act:name") == 0)
         {
-            if(!equals_node_val_vs_string(mark, xaccAccountGetName(act)))
+            if (!equals_node_val_vs_string(mark, xaccAccountGetName(act)))
             {
                 return g_strdup("names differ");
             }
         }
-        else if(safe_strcmp((char*)mark->name, "act:id") == 0)
+        else if (safe_strcmp((char*)mark->name, "act:id") == 0)
         {
-            if(!equals_node_val_vs_guid(mark, xaccAccountGetGUID(act)))
+            if (!equals_node_val_vs_guid(mark, xaccAccountGetGUID(act)))
             {
                 return g_strdup("ids differ");
             }
         }
-        else if(safe_strcmp((char*)mark->name, "act:type") == 0)
+        else if (safe_strcmp((char*)mark->name, "act:type") == 0)
         {
             gchar *txt;
             int type;
-            
+
             txt = dom_tree_to_text(mark);
 
-            if(!txt)
+            if (!txt)
             {
                 return g_strdup("couldn't get type string");
             }
-            else if(!xaccAccountStringToType(txt, &type))
+            else if (!xaccAccountStringToType(txt, &type))
             {
                 g_free(txt);
                 return g_strdup("couldn't convert type string to int");
             }
-            else if(type != xaccAccountGetType(act))
+            else if (type != xaccAccountGetType(act))
             {
                 g_free(txt);
                 return g_strdup("types differ");
@@ -110,68 +110,68 @@
                 g_free(txt);
             }
         }
-        else if(safe_strcmp((char*)mark->name, "act:commodity") == 0)
+        else if (safe_strcmp((char*)mark->name, "act:commodity") == 0)
         {
-            if(!equals_node_val_vs_commodity(
-                   mark, xaccAccountGetCommodity(act),
-                   gnc_account_get_book(act)))
+            if (!equals_node_val_vs_commodity(
+                        mark, xaccAccountGetCommodity(act),
+                        gnc_account_get_book(act)))
             {
                 return g_strdup("commodities differ");
             }
         }
-        else if(safe_strcmp((char*)mark->name, "act:code") == 0)
+        else if (safe_strcmp((char*)mark->name, "act:code") == 0)
         {
-            if(!equals_node_val_vs_string(mark, xaccAccountGetCode(act)))
+            if (!equals_node_val_vs_string(mark, xaccAccountGetCode(act)))
             {
                 return g_strdup("codes differ");
             }
         }
-        else if(safe_strcmp((char*)mark->name, "act:description") == 0)
+        else if (safe_strcmp((char*)mark->name, "act:description") == 0)
         {
-            if(!equals_node_val_vs_string(
-                   mark, xaccAccountGetDescription(act)))
+            if (!equals_node_val_vs_string(
+                        mark, xaccAccountGetDescription(act)))
             {
                 return g_strdup("descriptions differ");
             }
         }
-        else if(safe_strcmp((char*)mark->name, "act:slots") == 0)
+        else if (safe_strcmp((char*)mark->name, "act:slots") == 0)
         {
             /* xaccAccountDeleteOldData (act); */
 
-            if(!equals_node_val_vs_kvp_frame(mark, xaccAccountGetSlots(act)))
+            if (!equals_node_val_vs_kvp_frame(mark, xaccAccountGetSlots(act)))
             {
                 return g_strdup("slots differ");
             }
         }
-        else if(safe_strcmp((char*)mark->name, "act:parent") == 0)
+        else if (safe_strcmp((char*)mark->name, "act:parent") == 0)
         {
-            if(!equals_node_val_vs_guid(
-                   mark, xaccAccountGetGUID(gnc_account_get_parent(act))))
+            if (!equals_node_val_vs_guid(
+                        mark, xaccAccountGetGUID(gnc_account_get_parent(act))))
             {
                 return g_strdup("parent ids differ");
             }
         }
-        else if(safe_strcmp((char*)mark->name, "act:commodity-scu") == 0)
+        else if (safe_strcmp((char*)mark->name, "act:commodity-scu") == 0)
         {
-            if(!equals_node_val_vs_int(mark, xaccAccountGetCommoditySCU(act)))
+            if (!equals_node_val_vs_int(mark, xaccAccountGetCommoditySCU(act)))
             {
                 return g_strdup("commodity scus differ");
             }
         }
-		else if (safe_strcmp((char*)mark->name, "act:hidden") == 0)
-		{
-			if(!equals_node_val_vs_boolean(mark, xaccAccountGetHidden(act)))
-			{
-		    	return g_strdup("Hidden flags differ");
-			}
-		}
-		else if (safe_strcmp((char*)mark->name, "act:placeholder") == 0)
-		{
-			if(!equals_node_val_vs_boolean(mark, xaccAccountGetPlaceholder(act)))
-			{
-		    	return g_strdup("Placeholder flags differ");
-			}
-		}
+        else if (safe_strcmp((char*)mark->name, "act:hidden") == 0)
+        {
+            if (!equals_node_val_vs_boolean(mark, xaccAccountGetHidden(act)))
+            {
+                return g_strdup("Hidden flags differ");
+            }
+        }
+        else if (safe_strcmp((char*)mark->name, "act:placeholder") == 0)
+        {
+            if (!equals_node_val_vs_boolean(mark, xaccAccountGetPlaceholder(act)))
+            {
+                return g_strdup("Placeholder flags differ");
+            }
+        }
         else if (safe_strcmp((char*)mark->name, "act:security") == 0)
         {
             return NULL; // This tag is ignored.
@@ -181,7 +181,7 @@
             return g_strdup_printf("unknown node in dom tree: %s", mark->name);
         }
     }
-    
+
     return NULL;
 }
 
@@ -216,11 +216,14 @@
                                           gnc_commodity_get_namespace (com),
                                           gnc_commodity_get_mnemonic (com));
 
-    if (new_com) { xaccAccountSetCommodity (account, new_com); }
+    if (new_com)
+    {
+        xaccAccountSetCommodity (account, new_com);
+    }
 
     do_test_args(xaccAccountEqual((Account*)account, (Account*)(gdata->act),
                                   TRUE),
-                        "gnc_account_sixtp_parser_create", 
+                 "gnc_account_sixtp_parser_create",
                  __FILE__, __LINE__, "%d", gdata->value );
 
     return TRUE;
@@ -236,16 +239,16 @@
 
     test_node = gnc_account_dom_tree_create(test_act, FALSE, TRUE);
 
-    if(!test_node)
+    if (!test_node)
     {
-        failure_args("account_xml", __FILE__, __LINE__, 
+        failure_args("account_xml", __FILE__, __LINE__,
                      "gnc_account_dom_tree_create returned NULL");
         return;
     }
 
-    if((compare_msg = node_and_account_equal(test_node, test_act)) != NULL)
+    if ((compare_msg = node_and_account_equal(test_node, test_act)) != NULL)
     {
-        failure_args("account_xml", __FILE__, __LINE__, 
+        failure_args("account_xml", __FILE__, __LINE__,
                      "node and account were not equal: %s", compare_msg);
         xmlElemDump(stdout, NULL, test_node);
         fprintf(stdout, "\n");
@@ -257,11 +260,11 @@
     {
         success("account_xml");
     }
-        
+
     filename1 = g_strdup_printf("test_file_XXXXXX");
-        
+
     fd = g_mkstemp(filename1);
-        
+
     write_dom_node_to_file(test_node, fd);
 
     close(fd);
@@ -274,9 +277,9 @@
         data.value = i;
 
         parser = gnc_account_sixtp_parser_create();
-            
-        if(!gnc_xml_parse_file(parser, filename1, test_add_account,
-                               &data, sixbook))
+
+        if (!gnc_xml_parse_file(parser, filename1, test_add_account,
+                                &data, sixbook))
         {
             failure_args("gnc_xml_parse_file returned FALSE",
                          __FILE__, __LINE__, "%d", i);
@@ -285,8 +288,8 @@
         /* no handling of circular data structures.  We'll do that later */
         /* sixtp_destroy(parser); */
     }
-        
 
+
     g_unlink(filename1);
     g_free(filename1);
     xmlFreeNode(test_node);
@@ -297,7 +300,7 @@
 {
     int i;
 
-    for(i = 0; i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         Account *ran_act;
 
@@ -307,7 +310,7 @@
 
         delete_random_account(ran_act);
     }
-    
+
     {
         /* empty some things. */
         Account *act;
@@ -322,23 +325,23 @@
 
         delete_random_account(act);
     }
-    
-/*     { */
-/*         Account *act1; */
-/*         Account *act2; */
 
-/*         act1 = get_random_account(); */
-/*         act2 = get_random_account(); */
+    /*     { */
+    /*         Account *act1; */
+    /*         Account *act2; */
 
-/*         gnc_account_append_child(act1, act2); */
+    /*         act1 = get_random_account(); */
+    /*         act2 = get_random_account(); */
 
-/*         test_account(-1, act2); */
-/*         test_account(-1, act1); */
+    /*         gnc_account_append_child(act1, act2); */
 
-/*         delete_random_account(act2); */
-/*         delete_random_account(act1); */
-/*     } */
-    
+    /*         test_account(-1, act2); */
+    /*         test_account(-1, act1); */
+
+    /*         delete_random_account(act2); */
+    /*         delete_random_account(act1); */
+    /*     } */
+
 }
 
 static gboolean
@@ -347,7 +350,7 @@
     char *msg;
     Account *act = (Account*)data;
 
-    if(!gnc_account_get_parent(act))
+    if (!gnc_account_get_parent(act))
     {
         gnc_account_append_child(gnc_book_get_root_account(sixbook), act);
     }
@@ -369,9 +372,9 @@
     cashobjects_register();
     session = qof_session_new();
     sixbook = qof_session_get_book (session);
-    if(argc > 1)
+    if (argc > 1)
     {
-        test_files_in_dir(argc, argv, test_real_account, 
+        test_files_in_dir(argc, argv, test_real_account,
                           gnc_account_sixtp_parser_create(),
                           "gnc:account", sixbook);
     }
@@ -379,8 +382,8 @@
     {
         test_generation();
     }
-    
-    qof_session_destroy(session);        
+
+    qof_session_destroy(session);
     print_test_results();
     qof_close();
     exit(get_rv());

Modified: gnucash/trunk/src/backend/xml/test/test-xml-commodity.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-xml-commodity.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-xml-commodity.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -32,73 +32,73 @@
     xmlNodePtr mark;
 
     while (safe_strcmp ((char*)node->name, "text") == 0)
-      node = node->next;
+        node = node->next;
 
-    if(!check_dom_tree_version(node, "2.0.0"))
+    if (!check_dom_tree_version(node, "2.0.0"))
     {
         return "version wrong.  Not 2.0.0 or not there";
     }
 
-    if(!node->name || safe_strcmp((char*)node->name, "gnc:commodity"))
+    if (!node->name || safe_strcmp((char*)node->name, "gnc:commodity"))
     {
         return "Name of toplevel node is bad";
     }
 
-    for(mark = node->xmlChildrenNode; mark; mark = mark->next)
+    for (mark = node->xmlChildrenNode; mark; mark = mark->next)
     {
-        if(safe_strcmp((char*)mark->name, "text") == 0)
+        if (safe_strcmp((char*)mark->name, "text") == 0)
         {
         }
-        else if(safe_strcmp((char*)mark->name, "cmdty:space") == 0)
+        else if (safe_strcmp((char*)mark->name, "cmdty:space") == 0)
         {
-            if(!equals_node_val_vs_string(
-                   mark, gnc_commodity_get_namespace(com)))
+            if (!equals_node_val_vs_string(
+                        mark, gnc_commodity_get_namespace(com)))
             {
                 return "namespaces differ";
             }
         }
-        else if(safe_strcmp((char*)mark->name, "cmdty:id") == 0)
+        else if (safe_strcmp((char*)mark->name, "cmdty:id") == 0)
         {
-            if(!equals_node_val_vs_string(
-                   mark, gnc_commodity_get_mnemonic(com)))
+            if (!equals_node_val_vs_string(
+                        mark, gnc_commodity_get_mnemonic(com)))
             {
                 return "mnemonic differ";
             }
         }
-        else if(safe_strcmp((char*)mark->name, "cmdty:name") == 0)
+        else if (safe_strcmp((char*)mark->name, "cmdty:name") == 0)
         {
-            if(!equals_node_val_vs_string(
-                   mark, gnc_commodity_get_fullname(com)))
+            if (!equals_node_val_vs_string(
+                        mark, gnc_commodity_get_fullname(com)))
             {
                 return "names differ";
             }
         }
-        else if(safe_strcmp((char*)mark->name, "cmdty:xcode") == 0)
+        else if (safe_strcmp((char*)mark->name, "cmdty:xcode") == 0)
         {
-            if(!equals_node_val_vs_string(
-                   mark, gnc_commodity_get_cusip(com)))
+            if (!equals_node_val_vs_string(
+                        mark, gnc_commodity_get_cusip(com)))
             {
                 return "exchange codes differ";
             }
         }
-        else if(safe_strcmp((char*)mark->name, "cmdty:fraction") == 0)
+        else if (safe_strcmp((char*)mark->name, "cmdty:fraction") == 0)
         {
             gchar *txt;
             gint64 type;
-            
+
             txt = dom_tree_to_text(mark);
 
-            if(!txt)
+            if (!txt)
             {
                 return "couldn't get fraction string";
             }
 
-            else if(!string_to_gint64(txt, &type))
+            else if (!string_to_gint64(txt, &type))
             {
                 g_free(txt);
                 return "couldn't convert fraction string to int";
             }
-            else if(type != gnc_commodity_get_fraction(com))
+            else if (type != gnc_commodity_get_fraction(com))
             {
                 g_free(txt);
                 return "fractions differ";
@@ -113,7 +113,7 @@
             return "unknown node";
         }
     }
-    
+
     return NULL;
 }
 
@@ -128,32 +128,32 @@
 test_add_commodity(const char *tag, gpointer globaldata, gpointer data)
 {
     com_data *gdata = (com_data*)globaldata;
-    
+
     do_test_args(gnc_commodity_equiv((gnc_commodity*)data, gdata->com),
-            "gnc_commodity_sixtp_parser_create",
-            __FILE__, __LINE__, "%d", gdata->value );
+                 "gnc_commodity_sixtp_parser_create",
+                 __FILE__, __LINE__, "%d", gdata->value );
     gnc_commodity_destroy((gnc_commodity*)data);
-    
+
     return TRUE;
-    
+
 }
 
 static void
 test_generation(void)
 {
     int i;
-    for(i = 0; i < 20; i++)
+    for (i = 0; i < 20; i++)
     {
         gnc_commodity *ran_com;
         xmlNodePtr test_node;
         gchar *filename1;
         int fd;
         gchar *compare_msg;
-        
+
         ran_com = get_random_commodity(book);
 
         test_node = gnc_commodity_dom_tree_create(ran_com);
-        if(!test_node)
+        if (!test_node)
         {
             failure_args("commodity_xml", __FILE__, __LINE__,
                          "gnc_commodity_dom_tree_create returned NULL");
@@ -161,8 +161,8 @@
             continue;
         }
 
-        if((compare_msg = node_and_commodity_equal(test_node, ran_com)) !=
-           NULL)
+        if ((compare_msg = node_and_commodity_equal(test_node, ran_com)) !=
+                NULL)
         {
             failure_args("commodity_xml", __FILE__, __LINE__,
                          "node and commodity were not equal: %s", compare_msg);
@@ -171,32 +171,32 @@
             gnc_commodity_destroy(ran_com);
             continue;
         }
-        else 
+        else
         {
             success_args("commodity_xml", __FILE__, __LINE__, "%d", i);
         }
-        
+
         filename1 = g_strdup_printf("test_file_XXXXXX");
-        
+
         fd = g_mkstemp(filename1);
-        
+
         write_dom_node_to_file(test_node, fd);
 
         close(fd);
-        
+
         {
             sixtp *parser;
             com_data data;
 
             data.com = ran_com;
             data.value = i;
-            
+
             parser = gnc_commodity_sixtp_parser_create();
-            
-            if(!gnc_xml_parse_file(parser, filename1, test_add_commodity,
-                                   (gpointer)&data, book))
+
+            if (!gnc_xml_parse_file(parser, filename1, test_add_commodity,
+                                    (gpointer)&data, book))
             {
-                failure_args("gnc_xml_parse_file returned FALSE",  
+                failure_args("gnc_xml_parse_file returned FALSE",
                              __FILE__, __LINE__, "%d", i);
             }
 
@@ -215,7 +215,7 @@
 test_real_commodity(const char *tag, gpointer globaldata, gpointer data)
 {
     const char *msg = node_and_commodity_equal((xmlNodePtr)globaldata,
-                                               (gnc_commodity*)data);
+                      (gnc_commodity*)data);
     do_test_args(msg == NULL, "test_real_commodity",
                  __FILE__, __LINE__, msg);
     gnc_commodity_destroy((gnc_commodity*)data);
@@ -229,7 +229,7 @@
 
     book = qof_book_new ();
 
-    if(argc > 1)
+    if (argc > 1)
     {
         test_files_in_dir(argc, argv, test_real_commodity,
                           gnc_commodity_sixtp_parser_create(),

Modified: gnucash/trunk/src/backend/xml/test/test-xml-pricedb.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-xml-pricedb.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-xml-pricedb.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -21,7 +21,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  *  02110-1301, USA.
  */
- 
+
 #include "config.h"
 
 #include <glib.h>
@@ -46,116 +46,117 @@
 
 struct pricedb_data_struct
 {
-  GNCPriceDB *db;
-  int value;
+    GNCPriceDB *db;
+    int value;
 };
 typedef struct pricedb_data_struct pricedb_data;
 
 static gboolean
 test_add_pricedb (const char *tag, gpointer globaldata, gpointer data)
 {
-  pricedb_data *gdata = globaldata;
+    pricedb_data *gdata = globaldata;
 
-  do_test_args (gnc_pricedb_equal(data, gdata->db),
-                "gnc_pricedb_sixtp_parser_create", 
-                __FILE__, __LINE__, "%d", gdata->value);
+    do_test_args (gnc_pricedb_equal(data, gdata->db),
+                  "gnc_pricedb_sixtp_parser_create",
+                  __FILE__, __LINE__, "%d", gdata->value);
 
-  return TRUE;
+    return TRUE;
 }
 
 static void
 test_db (int i, GNCPriceDB *db)
 {
-  xmlNodePtr test_node;
-  gchar *filename1;
-  int fd;
+    xmlNodePtr test_node;
+    gchar *filename1;
+    int fd;
 
-  test_node = gnc_pricedb_dom_tree_create (db);
+    test_node = gnc_pricedb_dom_tree_create (db);
 
-  if (!test_node && db)
-  {
-    failure_args ("pricedb_xml", __FILE__, __LINE__, 
-                  "gnc_pricedb_dom_tree_create returned NULL");
-    return;
-  }
+    if (!test_node && db)
+    {
+        failure_args ("pricedb_xml", __FILE__, __LINE__,
+                      "gnc_pricedb_dom_tree_create returned NULL");
+        return;
+    }
 
-  if (!db)
-    return;
+    if (!db)
+        return;
 
-  filename1 = g_strdup_printf ("test_file_XXXXXX");
-        
-  fd = g_mkstemp (filename1);
-        
-  write_dom_node_to_file (test_node, fd);
+    filename1 = g_strdup_printf ("test_file_XXXXXX");
 
-  close (fd);
+    fd = g_mkstemp (filename1);
 
-  {
-    sixtp *parser;
-    pricedb_data data;
+    write_dom_node_to_file (test_node, fd);
 
-    data.db = db;
-    data.value = i;
+    close (fd);
 
-    parser = sixtp_new ();
+    {
+        sixtp *parser;
+        pricedb_data data;
 
-    if (!sixtp_add_some_sub_parsers
-        (parser, TRUE,
-         "gnc:pricedb", gnc_pricedb_sixtp_parser_create(),
-         NULL, NULL))
-    {
-      failure_args ("sixtp_add_some_sub_parsers failed",
-                    __FILE__, __LINE__, "%d", i);
+        data.db = db;
+        data.value = i;
+
+        parser = sixtp_new ();
+
+        if (!sixtp_add_some_sub_parsers
+                (parser, TRUE,
+                 "gnc:pricedb", gnc_pricedb_sixtp_parser_create(),
+                 NULL, NULL))
+        {
+            failure_args ("sixtp_add_some_sub_parsers failed",
+                          __FILE__, __LINE__, "%d", i);
+        }
+        else if (!gnc_xml_parse_file (parser, filename1, test_add_pricedb,
+                                      (gpointer)&data,
+                                      qof_session_get_book (session)))
+        {
+            failure_args ("gnc_xml_parse_file returned FALSE",
+                          __FILE__, __LINE__, "%d", i);
+        }
     }
-    else if (!gnc_xml_parse_file (parser, filename1, test_add_pricedb,
-                                  (gpointer)&data,
-                                  qof_session_get_book (session)))
-    {
-      failure_args ("gnc_xml_parse_file returned FALSE",
-                    __FILE__, __LINE__, "%d", i);
-    }
-  }
 
-  g_unlink (filename1);
-  g_free (filename1);
-  xmlFreeNode (test_node);
+    g_unlink (filename1);
+    g_free (filename1);
+    xmlFreeNode (test_node);
 }
 
 static void
 test_generation (void)
 {
-  int i;
+    int i;
 
-  for (i = 0; i < 20; i++)
-  {
-    GNCPriceDB *db;
-    g_message("i=%d", i);
-    session = qof_session_new();
-    db = get_random_pricedb (qof_session_get_book (session));
-    if (!db) {
-      failure_args ("gnc_random_price_db returned NULL",
-                    __FILE__, __LINE__, "%d", i);
-      return;
+    for (i = 0; i < 20; i++)
+    {
+        GNCPriceDB *db;
+        g_message("i=%d", i);
+        session = qof_session_new();
+        db = get_random_pricedb (qof_session_get_book (session));
+        if (!db)
+        {
+            failure_args ("gnc_random_price_db returned NULL",
+                          __FILE__, __LINE__, "%d", i);
+            return;
+        }
+        if (gnc_pricedb_get_num_prices (db))
+            test_db (i, db);
+
+        gnc_pricedb_destroy (db);
+        qof_session_end(session);
     }
-    if (gnc_pricedb_get_num_prices (db))
-      test_db (i, db);
-
-    gnc_pricedb_destroy (db);
-    qof_session_end(session);
-  }
 }
 
 int
 main (int argc, char ** argv)
 {
-   qof_init();
-   cashobjects_register();
-   //qof_log_init_filename("/tmp/gnctest.trace");
-   //qof_log_set_default(QOF_LOG_DETAIL);
-   //qof_log_set_level(GNC_MOD_PRICE, QOF_LOG_DETAIL);
-   session = qof_session_new ();
-   test_generation ();
-   print_test_results ();
-   qof_close();
-   exit(get_rv());
+    qof_init();
+    cashobjects_register();
+    //qof_log_init_filename("/tmp/gnctest.trace");
+    //qof_log_set_default(QOF_LOG_DETAIL);
+    //qof_log_set_level(GNC_MOD_PRICE, QOF_LOG_DETAIL);
+    session = qof_session_new ();
+    test_generation ();
+    print_test_results ();
+    qof_close();
+    exit(get_rv());
 }

Modified: gnucash/trunk/src/backend/xml/test/test-xml-transaction.c
===================================================================
--- gnucash/trunk/src/backend/xml/test/test-xml-transaction.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/backend/xml/test/test-xml-transaction.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -21,7 +21,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  *  02110-1301, USA.
  */
- 
+
 #include "config.h"
 
 #include <glib.h>
@@ -60,44 +60,44 @@
 {
     xmlNodePtr mark;
 
-    for(mark = node->xmlChildrenNode; mark; mark = mark->next)
+    for (mark = node->xmlChildrenNode; mark; mark = mark->next)
     {
         gboolean account_guid_good = FALSE;
         gboolean amount_good = FALSE;
         xmlNodePtr mark2;
 
-        for(mark2 = mark->xmlChildrenNode; mark2; mark2 = mark2->next)
+        for (mark2 = mark->xmlChildrenNode; mark2; mark2 = mark2->next)
         {
-            if(safe_strcmp((char*)mark2->name, "split:value") == 0)
+            if (safe_strcmp((char*)mark2->name, "split:value") == 0)
             {
                 gnc_numeric *num = dom_tree_to_gnc_numeric(mark2);
 
-                if(gnc_numeric_equal(*num, xaccSplitGetValue(spl)))
+                if (gnc_numeric_equal(*num, xaccSplitGetValue(spl)))
                 {
                     amount_good = TRUE;
                 }
 
                 g_free(num);
             }
-            else if(safe_strcmp((char*)mark2->name, "split:account") == 0)
+            else if (safe_strcmp((char*)mark2->name, "split:account") == 0)
             {
                 GUID *accid = dom_tree_to_guid(mark2);
                 Account *account = xaccSplitGetAccount (spl);
 
-                if(guid_equal(accid, xaccAccountGetGUID(account)))
+                if (guid_equal(accid, xaccAccountGetGUID(account)))
                 {
                     account_guid_good = TRUE;
                 }
                 g_free(accid);
             }
 
-            if(account_guid_good && amount_good)
+            if (account_guid_good && amount_good)
             {
                 return mark;
             }
         }
     }
-    
+
     return NULL;
 }
 
@@ -105,88 +105,89 @@
 equals_node_val_vs_split_internal(xmlNodePtr node, Split* spl)
 {
     xmlNodePtr mark;
-    
-    for(mark = node->children; mark != NULL; mark = mark->next)
+
+    for (mark = node->children; mark != NULL; mark = mark->next)
     {
-        if(safe_strcmp((char*)mark->name, "split:id") == 0)
+        if (safe_strcmp((char*)mark->name, "split:id") == 0)
         {
             GUID *id = dom_tree_to_guid(mark);
 
-            if(!guid_equal(id, xaccSplitGetGUID(spl)))
+            if (!guid_equal(id, xaccSplitGetGUID(spl)))
             {
                 g_free(id);
                 return "ids differ";
             }
             g_free(id);
         }
-        else if(safe_strcmp((char*)mark->name, "split:memo") == 0)
+        else if (safe_strcmp((char*)mark->name, "split:memo") == 0)
         {
             char *memo = dom_tree_to_text(mark);
 
-            if(safe_strcmp(memo, xaccSplitGetMemo(spl)) != 0)
+            if (safe_strcmp(memo, xaccSplitGetMemo(spl)) != 0)
             {
                 g_free(memo);
                 return "memos differ";
             }
             g_free(memo);
         }
-        else if(safe_strcmp((char*)mark->name, "split:reconciled-state") == 0)
+        else if (safe_strcmp((char*)mark->name, "split:reconciled-state") == 0)
         {
             char *rs = dom_tree_to_text(mark);
 
-            if(rs[0] != xaccSplitGetReconcile(spl))
+            if (rs[0] != xaccSplitGetReconcile(spl))
             {
                 g_free(rs);
                 return "states differ";
             }
             g_free(rs);
         }
-        else if(safe_strcmp((char*)mark->name, "split:value") == 0)
+        else if (safe_strcmp((char*)mark->name, "split:value") == 0)
         {
             gnc_numeric *num = dom_tree_to_gnc_numeric(mark);
             gnc_numeric val = xaccSplitGetValue(spl);
 
-            if(!gnc_numeric_equal(*num, val))
+            if (!gnc_numeric_equal(*num, val))
             {
                 g_free(num);
                 return g_strdup_printf ("values differ: %" G_GINT64_FORMAT "/%"
-					G_GINT64_FORMAT " v %" G_GINT64_FORMAT
-					"/%" G_GINT64_FORMAT,
+                                        G_GINT64_FORMAT " v %" G_GINT64_FORMAT
+                                        "/%" G_GINT64_FORMAT,
                                         (*num).num, (*num).denom,
                                         val.num, val.denom);
             }
             g_free(num);
         }
-        else if(safe_strcmp((char*)mark->name, "split:quantity") == 0)
+        else if (safe_strcmp((char*)mark->name, "split:quantity") == 0)
         {
             gnc_numeric *num = dom_tree_to_gnc_numeric(mark);
             gnc_numeric val = xaccSplitGetAmount(spl);
 
-            if (!gnc_numeric_equal(*num, val)) {
-              return g_strdup_printf( "quantities differ under _equal: %"
-				      G_GINT64_FORMAT "/%" G_GINT64_FORMAT
-				      " v %" G_GINT64_FORMAT "/%"
-				      G_GINT64_FORMAT,
-                                      (*num).num, (*num).denom,
-                                      val.num, val.denom );
+            if (!gnc_numeric_equal(*num, val))
+            {
+                return g_strdup_printf( "quantities differ under _equal: %"
+                                        G_GINT64_FORMAT "/%" G_GINT64_FORMAT
+                                        " v %" G_GINT64_FORMAT "/%"
+                                        G_GINT64_FORMAT,
+                                        (*num).num, (*num).denom,
+                                        val.num, val.denom );
             }
-            if(!gnc_numeric_equal(*num, val))
+            if (!gnc_numeric_equal(*num, val))
             {
                 g_free(num);
                 return g_strdup_printf ("quantities differ: %" G_GINT64_FORMAT
-					"/%" G_GINT64_FORMAT " v %"
-					G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
+                                        "/%" G_GINT64_FORMAT " v %"
+                                        G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
                                         (*num).num, (*num).denom,
                                         val.num, val.denom);
             }
             g_free(num);
         }
-        else if(safe_strcmp((char*)mark->name, "split:account") == 0)
+        else if (safe_strcmp((char*)mark->name, "split:account") == 0)
         {
             GUID *id = dom_tree_to_guid(mark);
             Account *account = xaccSplitGetAccount (spl);
 
-            if(!guid_equal(id, xaccAccountGetGUID(account)))
+            if (!guid_equal(id, xaccAccountGetGUID(account)))
             {
                 g_free(id);
                 return "accounts differ";
@@ -207,25 +208,25 @@
 
     g_return_val_if_fail(node, FALSE);
     g_return_val_if_fail(node->xmlChildrenNode, FALSE);
-    
-    for(i = 0, spl_mark = xaccTransGetSplit((Transaction*)trn, i);
-        spl_mark;
-        i++, spl_mark = xaccTransGetSplit((Transaction*)trn, i))
+
+    for (i = 0, spl_mark = xaccTransGetSplit((Transaction*)trn, i);
+            spl_mark;
+            i++, spl_mark = xaccTransGetSplit((Transaction*)trn, i))
     {
         spl_node = find_appropriate_node(node, spl_mark);
 
-        if(!spl_node)
+        if (!spl_node)
         {
             return "no matching split found";
         }
 
         msg = equals_node_val_vs_split_internal(spl_node, spl_mark);
-        if(msg != NULL)
+        if (msg != NULL)
         {
             return msg;
         }
     }
-    
+
     return NULL;
 }
 
@@ -233,79 +234,79 @@
 node_and_transaction_equal(xmlNodePtr node, Transaction *trn)
 {
     xmlNodePtr mark;
-    
+
     while (safe_strcmp ((char*)node->name, "text") == 0)
-      node = node->next;
+        node = node->next;
 
-    if(!check_dom_tree_version(node, "2.0.0"))
+    if (!check_dom_tree_version(node, "2.0.0"))
     {
         return "version wrong.  Not 2.0.0 or not there";
     }
 
-    if(!node->name || safe_strcmp((char*)node->name, "gnc:transaction"))
+    if (!node->name || safe_strcmp((char*)node->name, "gnc:transaction"))
     {
         return "Name of toplevel node is bad";
     }
 
-    for(mark = node->xmlChildrenNode; mark; mark = mark->next)
+    for (mark = node->xmlChildrenNode; mark; mark = mark->next)
     {
-        if(safe_strcmp((char*)mark->name, "text") == 0)
+        if (safe_strcmp((char*)mark->name, "text") == 0)
         {
         }
-        else if(safe_strcmp((char*)mark->name, "trn:id") == 0)
+        else if (safe_strcmp((char*)mark->name, "trn:id") == 0)
         {
-            if(!equals_node_val_vs_guid(mark, xaccTransGetGUID(trn)))
+            if (!equals_node_val_vs_guid(mark, xaccTransGetGUID(trn)))
             {
                 return "ids differ";
             }
         }
-        else if(safe_strcmp((char*)mark->name, "trn:currency") == 0)
+        else if (safe_strcmp((char*)mark->name, "trn:currency") == 0)
         {
-            if(!equals_node_val_vs_commodity(
-                   mark, xaccTransGetCurrency(trn), xaccTransGetBook(trn)))
+            if (!equals_node_val_vs_commodity(
+                        mark, xaccTransGetCurrency(trn), xaccTransGetBook(trn)))
             {
                 return g_strdup("currencies differ");
             }
         }
-        else if(safe_strcmp((char*)mark->name, "trn:num") == 0)
+        else if (safe_strcmp((char*)mark->name, "trn:num") == 0)
         {
-            if(!equals_node_val_vs_string(mark, xaccTransGetNum(trn)))
+            if (!equals_node_val_vs_string(mark, xaccTransGetNum(trn)))
             {
                 return "nums differ";
             }
         }
-        else if(safe_strcmp((char*)mark->name, "trn:date-posted") == 0)
+        else if (safe_strcmp((char*)mark->name, "trn:date-posted") == 0)
         {
-            if(!equals_node_val_vs_date(mark, xaccTransRetDatePostedTS(trn)))
+            if (!equals_node_val_vs_date(mark, xaccTransRetDatePostedTS(trn)))
             {
                 return "posted dates differ";
             }
         }
-        else if(safe_strcmp((char*)mark->name, "trn:date-entered") == 0)
+        else if (safe_strcmp((char*)mark->name, "trn:date-entered") == 0)
         {
-            if(!equals_node_val_vs_date(mark, xaccTransRetDateEnteredTS(trn)))
+            if (!equals_node_val_vs_date(mark, xaccTransRetDateEnteredTS(trn)))
             {
                 return "entered dates differ";
             }
         }
-        else if(safe_strcmp((char*)mark->name, "trn:description") == 0)
+        else if (safe_strcmp((char*)mark->name, "trn:description") == 0)
         {
-            if(!equals_node_val_vs_string(mark, xaccTransGetDescription(trn)))
+            if (!equals_node_val_vs_string(mark, xaccTransGetDescription(trn)))
             {
                 return "descriptions differ";
             }
         }
-        else if(safe_strcmp((char*)mark->name, "trn:slots") == 0)
+        else if (safe_strcmp((char*)mark->name, "trn:slots") == 0)
         {
-            if(!equals_node_val_vs_kvp_frame(mark, xaccTransGetSlots(trn)))
+            if (!equals_node_val_vs_kvp_frame(mark, xaccTransGetSlots(trn)))
             {
                 return "slots differ";
             }
         }
-        else if(safe_strcmp((char*)mark->name, "trn:splits") == 0)
+        else if (safe_strcmp((char*)mark->name, "trn:splits") == 0)
         {
             char *msg = equals_node_val_vs_splits (mark, trn);
-            if(msg != NULL)
+            if (msg != NULL)
             {
                 return msg;
             }
@@ -315,7 +316,7 @@
             return "unknown node";
         }
     }
-    
+
     return NULL;
 }
 
@@ -350,7 +351,7 @@
                       "gnc_transaction_sixtp_parser_create",
                       __FILE__, __LINE__,
                       "%d", gdata->value))
-      return FALSE;
+        return FALSE;
 
     gdata->new_trn = trans;
 
@@ -362,7 +363,7 @@
 {
     int i;
 
-    for(i = 0; i < 50; i++)
+    for (i = 0; i < 50; i++)
     {
         Transaction *ran_trn;
         Account *root;
@@ -372,38 +373,38 @@
         gchar *filename1;
         int fd;
 
-	/* The next line exists for its side effect of creating the
-	 * account tree. */
-	root = get_random_account_tree(book);
+        /* The next line exists for its side effect of creating the
+         * account tree. */
+        root = get_random_account_tree(book);
         ran_trn = get_random_transaction(book);
-        if(!ran_trn)
+        if (!ran_trn)
         {
             failure_args("transaction_xml", __FILE__, __LINE__,
                          "get_random_transaction returned NULL");
             return;
-       }
+        }
 
         {
-          /* xaccAccountInsertSplit can reorder the splits. */
-          GList * list = g_list_copy(xaccTransGetSplitList (ran_trn));
-          GList * node = list;
-          for ( ; node; node = node->next)
-          {
-            Split * s = node->data;
-            Account * a = xaccMallocAccount(book);
+            /* xaccAccountInsertSplit can reorder the splits. */
+            GList * list = g_list_copy(xaccTransGetSplitList (ran_trn));
+            GList * node = list;
+            for ( ; node; node = node->next)
+            {
+                Split * s = node->data;
+                Account * a = xaccMallocAccount(book);
 
-            xaccAccountBeginEdit (a);
-            xaccAccountSetCommoditySCU (a, xaccSplitGetAmount (s).denom);
-            xaccAccountInsertSplit (a, s);
-            xaccAccountCommitEdit (a);
-          }
-          g_list_free(list);
+                xaccAccountBeginEdit (a);
+                xaccAccountSetCommoditySCU (a, xaccSplitGetAmount (s).denom);
+                xaccAccountInsertSplit (a, s);
+                xaccAccountCommitEdit (a);
+            }
+            g_list_free(list);
         }
 
         com = xaccTransGetCurrency (ran_trn);
 
         test_node = gnc_transaction_dom_tree_create(ran_trn);
-        if(!test_node)
+        if (!test_node)
         {
             failure_args("transaction_xml", __FILE__, __LINE__,
                          "gnc_transaction_dom_tree_create returned NULL");
@@ -411,8 +412,8 @@
             continue;
         }
 
-        if((compare_msg = node_and_transaction_equal(test_node, ran_trn)) !=
-           NULL)
+        if ((compare_msg = node_and_transaction_equal(test_node, ran_trn)) !=
+                NULL)
         {
             failure_args("transaction_xml", __FILE__, __LINE__,
                          "node and transaction were not equal: %s",
@@ -428,28 +429,28 @@
         {
             success_args("transaction_xml", __FILE__, __LINE__, "%d", i );
         }
-        
+
         filename1 = g_strdup_printf("test_file_XXXXXX");
-        
+
         fd = g_mkstemp(filename1);
-        
+
         write_dom_node_to_file(test_node, fd);
 
         close(fd);
-        
+
         {
-          GList * node = xaccTransGetSplitList (ran_trn);
-          for ( ; node; node = node->next)
-          {
-            Split * s = node->data;
-            Account * a1 = xaccSplitGetAccount(s);
-            Account * a2 = xaccMallocAccount(book);
+            GList * node = xaccTransGetSplitList (ran_trn);
+            for ( ; node; node = node->next)
+            {
+                Split * s = node->data;
+                Account * a1 = xaccSplitGetAccount(s);
+                Account * a2 = xaccMallocAccount(book);
 
-            xaccAccountBeginEdit (a2);
-            xaccAccountSetCommoditySCU (a2, xaccAccountGetCommoditySCU (a1));
-            xaccAccountSetGUID (a2, xaccAccountGetGUID (a1));
-            xaccAccountCommitEdit (a2);
-          }
+                xaccAccountBeginEdit (a2);
+                xaccAccountSetCommoditySCU (a2, xaccAccountGetCommoditySCU (a1));
+                xaccAccountSetGUID (a2, xaccAccountGetGUID (a1));
+                xaccAccountCommitEdit (a2);
+            }
         }
 
         {
@@ -461,15 +462,15 @@
             data.value = i;
 
             parser = gnc_transaction_sixtp_parser_create();
-            
-            if(!gnc_xml_parse_file(parser, filename1, test_add_transaction,
-                                   (gpointer)&data, book))
+
+            if (!gnc_xml_parse_file(parser, filename1, test_add_transaction,
+                                    (gpointer)&data, book))
             {
-                failure_args("gnc_xml_parse_file returned FALSE", 
+                failure_args("gnc_xml_parse_file returned FALSE",
                              __FILE__, __LINE__, "%d", i);
             }
             else
-              really_get_rid_of_transaction (data.new_trn);
+                really_get_rid_of_transaction (data.new_trn);
 
             /* no handling of circular data structures.  We'll do that later */
             /* sixtp_destroy(parser); */
@@ -506,7 +507,7 @@
 
     book = qof_book_new ();
 
-    if(argc > 1)
+    if (argc > 1)
     {
         test_files_in_dir(argc, argv, test_real_transaction,
                           gnc_transaction_sixtp_parser_create(),

Modified: gnucash/trunk/src/calculation/amort_opt.c
===================================================================
--- gnucash/trunk/src/calculation/amort_opt.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/amort_opt.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -31,8 +31,8 @@
 #include "fin_spl_protos.h"
 
 amort_sched_ptr  amort_opt(
-amort_sched_ptr  amortsched,
-void            *parse_env)
+    amort_sched_ptr  amortsched,
+    void            *parse_env)
 {
     char            buffer[200], *errp;
     unsigned long   ii;
@@ -40,10 +40,10 @@
     var_store       value;
     numeric_ptr     nval;
     struct tm      *times_E,
-                   *times_I;
+                *times_I;
 
     /* print amortization options */
-    times_E = (struct tm *)calloc(1,sizeof(struct tm));
+    times_E = (struct tm *)calloc(1, sizeof(struct tm));
     ii = amortsched->Eff_Date_jdn;
     times_E->tm_mday = amortsched->day_E;
     times_E->tm_mon  = amortsched->month_E - 1;
@@ -51,7 +51,7 @@
     times_E->tm_wday = (ii + 1) % 7;
     times_E->tm_yday = amortsched->yday_E;
 
-    times_I = (struct tm *)calloc(1,sizeof(struct tm));
+    times_I = (struct tm *)calloc(1, sizeof(struct tm));
     ii = amortsched->Init_Date_jdn;
     times_I->tm_mday = amortsched->day_I;
     times_I->tm_mon  = amortsched->month_I - 1;
@@ -60,78 +60,92 @@
     times_I->tm_yday = amortsched->yday_I;
 
     printf("\n******************************");
-    qof_strftime(buffer,(size_t)50,"%c",times_E);
-    printf("\nEffective       Date: %s\n",buffer);
-    qof_strftime(buffer,(size_t)50,"%c",times_I);
-    printf("Initial Payment Date: %s\n",buffer);
+    qof_strftime(buffer, (size_t)50, "%c", times_E);
+    printf("\nEffective       Date: %s\n", buffer);
+    qof_strftime(buffer, (size_t)50, "%c", times_I);
+    printf("Initial Payment Date: %s\n", buffer);
     free(times_E);
     free(times_I);
-    printf("The Original Present Value (pv)        is: %.*f\n",(int)prec,amortsched->pv);
-    printf("The Original Periodic Payment (pmt)    is: %.*f\n",(int)prec,amortsched->pmt);
-    printf("The Original Future  Value (fv)        is: %.*f\n",(int)prec,amortsched->fv);
+    printf("The Original Present Value (pv)        is: %.*f\n", (int)prec, amortsched->pv);
+    printf("The Original Periodic Payment (pmt)    is: %.*f\n", (int)prec, amortsched->pmt);
+    printf("The Original Future  Value (fv)        is: %.*f\n", (int)prec, amortsched->fv);
 
-    printf("The Delayed Present Value (pve)        is:  %.*f\n",(int)prec,amortsched->pve);
-    printf("The New Periodic Payment (pmt) for pve is:  %.*f\n\n",(int)prec,amortsched->new_pmt);
+    printf("The Delayed Present Value (pve)        is:  %.*f\n", (int)prec, amortsched->pve);
+    printf("The New Periodic Payment (pmt) for pve is:  %.*f\n\n", (int)prec, amortsched->new_pmt);
 
     printf("The amortization options are:\n");
-    printf("1 -- Amortize with Original Amount and Constant Payment to Principal: %.*f\n",(int) prec,amortsched->cpmt1);
-    printf("    and final payment: %.*f\n",(int)prec,amortsched->final_pmt_opt_1);
-    printf("2 -- Amortize with Delayed Amount and Constant Payment to Principal: %.*f\n",(int)prec,amortsched->cpmt2);
-    printf("    and final payment: %.*f\n",(int)prec,amortsched->final_pmt_opt_2);
+    printf("1 -- Amortize with Original Amount and Constant Payment to Principal: %.*f\n", (int) prec, amortsched->cpmt1);
+    printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_1);
+    printf("2 -- Amortize with Delayed Amount and Constant Payment to Principal: %.*f\n", (int)prec, amortsched->cpmt2);
+    printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_2);
     printf("3 -- Amortize with Original Transaction Values\n");
-    printf("    and final payment: %.*f\n",(int)prec,amortsched->final_pmt_opt_3);
+    printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_3);
     printf("4 -- Amortize with Delayed Amount, Original Periodic Payment\n");
-    printf("    and final payment: %.*f\n",(int)prec,amortsched->final_pmt_opt_4);
+    printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_4);
     printf("5 -- Amortize with Delayed Amount, New Periodic Payment\n");
-    printf("    and final payment: %.*f\n",(int)prec,amortsched->final_pmt_opt_5);
-    if ( amortsched->new_n ) {
-    	printf("6 -- Amortize with Original Amount, Original Periodic Payment,\n");
-    	printf("    new number of total payments (n): %u\n",amortsched->new_n);
-    	printf("    and final payment: %.*f\n",(int)prec,amortsched->final_pmt_opt_6);
+    printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_5);
+    if ( amortsched->new_n )
+{
+        printf("6 -- Amortize with Original Amount, Original Periodic Payment,\n");
+        printf("    new number of total payments (n): %u\n", amortsched->new_n);
+        printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_6);
     } /* endif */
     printf("Enter choice 1, 2, 3, 4, 5 or 6: ");
-    fgets(buffer,190,stdin);
+    fgets(buffer, 190, stdin);
     amortsched->option = buffer[0] - '0';
 
     printf("Amortization Schedule:\n");
     printf("y -- Yearly Summary\n");
     printf("p -- Periodic Payment\n");
-    if ( amortsched->option < 3 ) {
-    	printf("Enter Choice y or p: ");
-      } else {
-		printf("f -- Fixed Advanced Payment\n");
-    	printf("a -- Variable Advanced Payment\n");
-        	printf("Enter Choice y, p, f or a: ");
+    if ( amortsched->option < 3 )
+    {
+        printf("Enter Choice y or p: ");
+    }
+    else
+    {
+        printf("f -- Fixed Advanced Payment\n");
+        printf("a -- Variable Advanced Payment\n");
+        printf("Enter Choice y, p, f or a: ");
     } /* endif */
-    fgets(buffer,190,stdin);
+    fgets(buffer, 190, stdin);
     amortsched->summary = buffer[0];
 
-    if ( amortsched->summary == 'f' ) {
-        if ( amortsched->fixed_pmt != 0.0 ) {
-            printf("Current Fixed Prepayment: %.*f\nChange Fixed Prepayment? (y/n): ",(int)prec,amortsched->fixed_pmt);
-            fgets(buffer,190,stdin);
-          } else { buffer[0] = 'y';
+    if ( amortsched->summary == 'f' )
+    {
+        if ( amortsched->fixed_pmt != 0.0 )
+        {
+            printf("Current Fixed Prepayment: %.*f\nChange Fixed Prepayment? (y/n): ", (int)prec, amortsched->fixed_pmt);
+            fgets(buffer, 190, stdin);
+        }
+        else
+        {
+            buffer[0] = 'y';
         } /* endif */
 
-        if ( buffer[0] == 'y' ) {
-        	printf("Enter Fixed Prepayment Amount: ");
-    	    fgets(buffer,190,stdin);
-        	if ( (errp = parse_string(&value,buffer,parse_env)) == NULL ) {
-        		nval = (numeric_ptr)(value.value);
-    	    	switch ( nval->type ) {
-        			case INT_TYPE:
-            			amortsched->fixed_pmt = (double)(nval->value.int_value);
-    	        		break;
-        		    case DBL_TYPE:
-        			    amortsched->fixed_pmt = nval->value.dbl_value;
-    	    			break;
-			    } /* endswitch */
-    			if ( !value.variable_name ) free_numeric(value.value);
-	      	  } else {
-	  	    	parse_error(get_parse_error(parse_env),buffer,errp);
-        	} /* endif */
+        if ( buffer[0] == 'y' )
+        {
+            printf("Enter Fixed Prepayment Amount: ");
+            fgets(buffer, 190, stdin);
+            if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
+            {
+                nval = (numeric_ptr)(value.value);
+                switch ( nval->type )
+                {
+                case INT_TYPE:
+                    amortsched->fixed_pmt = (double)(nval->value.int_value);
+                    break;
+                case DBL_TYPE:
+                    amortsched->fixed_pmt = nval->value.dbl_value;
+                    break;
+                } /* endswitch */
+                if ( !value.variable_name ) free_numeric(value.value);
+            }
+            else
+            {
+                parse_error(get_parse_error(parse_env), buffer, errp);
+            } /* endif */
         } /* endif */
     } /* endif */
 
-	return amortsched;
+    return amortsched;
 } /* amort_opt */

Modified: gnucash/trunk/src/calculation/amort_prt.c
===================================================================
--- gnucash/trunk/src/calculation/amort_prt.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/amort_prt.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -33,244 +33,275 @@
 
 
 void             prt_amortization_schedule(
-amort_sched_ptr  amortsched,  /* amortization schedule to print           */
-FILE            *ofile)      /* output file                               */
+    amort_sched_ptr  amortsched,  /* amortization schedule to print           */
+    FILE            *ofile)      /* output file                               */
 {
-	unsigned            j,
-	                    jj,
-	                    prec = amortsched->prec,
-	                    option = amortsched->option,
-	                    fv_case = amortsched->fv_case;
+    unsigned            j,
+    jj,
+    prec = amortsched->prec,
+           option = amortsched->option,
+                    fv_case = amortsched->fv_case;
     unsigned char       datel[100],
-                        summary = amortsched->summary;
+    summary = amortsched->summary;
     struct tm          *times_E,
-    				   *times_I;
-	amort_sched_yr_ptr  amortyr,
-	                    prst_yr;
-	sched_pmt_ptr       pmtsched = NULL;
-	yearly_summary_ptr  annual_summary;
+                *times_I;
+    amort_sched_yr_ptr  amortyr,
+    prst_yr;
+    sched_pmt_ptr       pmtsched = NULL;
+    yearly_summary_ptr  annual_summary;
 
-    times_E = (struct tm *)calloc(1,sizeof(struct tm));
+    times_E = (struct tm *)calloc(1, sizeof(struct tm));
     times_E->tm_mday = amortsched->day_E;
     times_E->tm_mon  = amortsched->month_E - 1;
     times_E->tm_year = amortsched->year_E - 1900;
     times_E->tm_wday = (amortsched->Eff_Date_jdn + 1) % 7;
     times_E->tm_yday = amortsched->yday_E;
 
-    times_I = (struct tm *)calloc(1,sizeof(struct tm));
+    times_I = (struct tm *)calloc(1, sizeof(struct tm));
     times_I->tm_mday = amortsched->day_I;
     times_I->tm_mon  = amortsched->month_I - 1;
     times_I->tm_year = amortsched->year_I - 1900;
     times_I->tm_wday = (amortsched->Init_Date_jdn + 1) % 7;
     times_I->tm_yday = amortsched->yday_I;
 
-    fprintf(ofile,"Amortization Table\n");
-    qof_strftime(datel,(size_t)100,"%c",times_E);
-    fprintf(ofile,"Effective       Date: %s\n",datel);
-    qof_strftime(datel,(size_t)100,"%c",times_I);
-    fprintf(ofile,"Initial Payment Date: %s\n",datel);
-    fprintf(ofile,"Compounding Frequency per year: %u\n",amortsched->CF);
-    fprintf(ofile,"Payment     Frequency per year: %u\n",amortsched->PF);
-    fprintf(ofile,"Compounding: %s\n",(amortsched->disc ? "Discrete" : "Continuous"));
-    fprintf(ofile,"Payments: %s\n",(amortsched->bep ? "Beginning of Period" : "End of Period"));
-    fprintf(ofile,"Payments (%u): %.*f\n",amortsched->n - 1,(int)prec,(option < 3) ? amortsched->cpmt : (option == 5) ? amortsched->new_pmt : amortsched->pmt);
-    fprintf(ofile,"Final payment (%u): %.*f\n",amortsched->n,(int)prec,amortsched->final_pmt);
-    if ( (amortsched->CF == 1) && (amortsched->PF == 1) ) fprintf(ofile,"Nominal Interest per Payment Period: %g\t(Annualized: %g)\n",amortsched->nint,amortsched->nint * 12);
-      else fprintf(ofile,"Nominal Annual Interest Rate: %g\n",amortsched->nint);
-    fprintf(ofile,"  Effective Interest Rate Per Payment Period: %g\n",amortsched->eint);
-    fprintf(ofile,"Present Value: %.*f\n",(int)prec,amortsched->pv);
-    if ( (amortsched->option == 2) || (amortsched->option > 3) ) {
-        fprintf(ofile,"Interest due to Delayed Intial Payment: %.*f\n",(int)prec,amortsched->delayed_int);
+    fprintf(ofile, "Amortization Table\n");
+    qof_strftime(datel, (size_t)100, "%c", times_E);
+    fprintf(ofile, "Effective       Date: %s\n", datel);
+    qof_strftime(datel, (size_t)100, "%c", times_I);
+    fprintf(ofile, "Initial Payment Date: %s\n", datel);
+    fprintf(ofile, "Compounding Frequency per year: %u\n", amortsched->CF);
+    fprintf(ofile, "Payment     Frequency per year: %u\n", amortsched->PF);
+    fprintf(ofile, "Compounding: %s\n", (amortsched->disc ? "Discrete" : "Continuous"));
+    fprintf(ofile, "Payments: %s\n", (amortsched->bep ? "Beginning of Period" : "End of Period"));
+    fprintf(ofile, "Payments (%u): %.*f\n", amortsched->n - 1, (int)prec, (option < 3) ? amortsched->cpmt : (option == 5) ? amortsched->new_pmt : amortsched->pmt);
+    fprintf(ofile, "Final payment (%u): %.*f\n", amortsched->n, (int)prec, amortsched->final_pmt);
+    if ( (amortsched->CF == 1) && (amortsched->PF == 1) ) fprintf(ofile, "Nominal Interest per Payment Period: %g\t(Annualized: %g)\n", amortsched->nint, amortsched->nint * 12);
+    else fprintf(ofile, "Nominal Annual Interest Rate: %g\n", amortsched->nint);
+    fprintf(ofile, "  Effective Interest Rate Per Payment Period: %g\n", amortsched->eint);
+    fprintf(ofile, "Present Value: %.*f\n", (int)prec, amortsched->pv);
+    if ( (amortsched->option == 2) || (amortsched->option > 3) )
+{
+        fprintf(ofile, "Interest due to Delayed Intial Payment: %.*f\n", (int)prec, amortsched->delayed_int);
     } /* endif */
 
     free(times_E);
     free(times_I);
 
-    if ( amortsched->option < 3 ) {
-    	summary = (summary == 'y') ? 'x' : 'o';
+    if ( amortsched->option < 3 )
+    {
+        summary = (summary == 'y') ? 'x' : 'o';
     } /* endif */
 
-    switch ( summary ) {
-        case 'a':
-        	/* variable prepayment schedule
-        	 */
-            fprintf(ofile,"Advanced Prepayment Amortization - Variable Prepayment\n");
-			amortyr = amortsched->schedule.first_yr;
-			for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- ) {
-				if ( !jj ) {
-                    fprintf(ofile,"Pmt *     Interest    Principal       Prepay    Total Pmt      Balance\n");
-					pmtsched = amortyr->payments;
-					jj = amortyr->num_periods;
-				} /* endif */
+    switch ( summary )
+    {
+    case 'a':
+        /* variable prepayment schedule
+         */
+        fprintf(ofile, "Advanced Prepayment Amortization - Variable Prepayment\n");
+        amortyr = amortsched->schedule.first_yr;
+        for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- )
+        {
+            if ( !jj )
+            {
+                fprintf(ofile, "Pmt *     Interest    Principal       Prepay    Total Pmt      Balance\n");
+                pmtsched = amortyr->payments;
+                jj = amortyr->num_periods;
+            } /* endif */
 
-                fprintf(ofile,"%4u  %12.*f %12.*f %12.*f %12.*f %12.*f\n",
-                               pmtsched->period_num,
-                               (int)prec,pmtsched->interest,
-                               (int)prec,pmtsched->principal,
-                               (int)prec,pmtsched->advanced_pmt,
-                               (int)prec,pmtsched->total_pmt,
-                               (int)prec,pmtsched->balance);
+            fprintf(ofile, "%4u  %12.*f %12.*f %12.*f %12.*f %12.*f\n",
+                    pmtsched->period_num,
+                    (int)prec, pmtsched->interest,
+                    (int)prec, pmtsched->principal,
+                    (int)prec, pmtsched->advanced_pmt,
+                    (int)prec, pmtsched->total_pmt,
+                    (int)prec, pmtsched->balance);
 
-                if ( !--jj ) {
-                    fprintf(ofile,"Summary for: %u:\n",amortyr->year);
-                    fprintf(ofile,"  Interest  Paid: %.*f\n",(int)prec,amortyr->interest_pd);
-                    fprintf(ofile,"  Principal Paid: %.*f\n",(int)prec,amortyr->principal_pd);
-                    fprintf(ofile,"  Year Ending Balance: %.*f\n",(int)prec,amortyr->yr_end_balance);
-                    fprintf(ofile,"  Sum of Interest Paid: %.*f\n",(int)prec,amortyr->total_interest_pd);
-                    prst_yr = amortyr;
-                    amortyr = amortyr->next_yr;
-                  } else {
-                  	pmtsched++;
-                } /* endif */
-    		} /* endfor */
-			break;
-		case 'f':
-			/* fixed prepayment schedule
-			 */
-            fprintf(ofile,"Advanced Prepayment Amortization - Fixed Prepayment: %.*f\n",(int)prec,amortsched->fixed_pmt);
-			amortyr = amortsched->schedule.first_yr;
-			for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- ) {
-				if ( !jj ) {
-                    fprintf(ofile,"Pmt *     Interest    Principal       Prepay    Total Pmt      Balance\n");
-					pmtsched = amortyr->payments;
-					jj = amortyr->num_periods;
-				} /* endif */
+            if ( !--jj )
+            {
+                fprintf(ofile, "Summary for: %u:\n", amortyr->year);
+                fprintf(ofile, "  Interest  Paid: %.*f\n", (int)prec, amortyr->interest_pd);
+                fprintf(ofile, "  Principal Paid: %.*f\n", (int)prec, amortyr->principal_pd);
+                fprintf(ofile, "  Year Ending Balance: %.*f\n", (int)prec, amortyr->yr_end_balance);
+                fprintf(ofile, "  Sum of Interest Paid: %.*f\n", (int)prec, amortyr->total_interest_pd);
+                prst_yr = amortyr;
+                amortyr = amortyr->next_yr;
+            }
+            else
+            {
+                pmtsched++;
+            } /* endif */
+        } /* endfor */
+        break;
+    case 'f':
+        /* fixed prepayment schedule
+         */
+        fprintf(ofile, "Advanced Prepayment Amortization - Fixed Prepayment: %.*f\n", (int)prec, amortsched->fixed_pmt);
+        amortyr = amortsched->schedule.first_yr;
+        for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- )
+        {
+            if ( !jj )
+            {
+                fprintf(ofile, "Pmt *     Interest    Principal       Prepay    Total Pmt      Balance\n");
+                pmtsched = amortyr->payments;
+                jj = amortyr->num_periods;
+            } /* endif */
 
-                fprintf(ofile,"%4u  %12.*f %12.*f %12.*f %12.*f %12.*f\n",
-                               pmtsched->period_num,
-                               (int)prec,pmtsched->interest,
-                	       (int)prec,pmtsched->principal,
-                               (int)prec,pmtsched->advanced_pmt,
-                               (int)prec,pmtsched->total_pmt,
-                               (int)prec,pmtsched->balance);
+            fprintf(ofile, "%4u  %12.*f %12.*f %12.*f %12.*f %12.*f\n",
+                    pmtsched->period_num,
+                    (int)prec, pmtsched->interest,
+                    (int)prec, pmtsched->principal,
+                    (int)prec, pmtsched->advanced_pmt,
+                    (int)prec, pmtsched->total_pmt,
+                    (int)prec, pmtsched->balance);
 
-                if ( !--jj ) {
-                    fprintf(ofile,"Summary for: %u:\n",amortyr->year);
-                    fprintf(ofile,"  Interest  Paid: %.*f\n",(int)prec,amortyr->interest_pd);
-                    fprintf(ofile,"  Principal Paid: %.*f\n",(int)prec,amortyr->principal_pd);
-                    fprintf(ofile,"  Year Ending Balance: %.*f\n",(int)prec,amortyr->yr_end_balance);
-                    fprintf(ofile,"  Sum of Interest Paid: %.*f\n",(int)prec,amortyr->total_interest_pd);
-                    prst_yr = amortyr;
-                    amortyr = amortyr->next_yr;
-                  } else {
-                  	pmtsched++;
-                } /* endif */
-    		} /* endfor */
-			break;
-		case 'o':
-			/* constant payment to principal
-			 */
-            fprintf(ofile,"Constant Payment to Principal: %.*f\n",(int)prec,amortsched->cpmt);
-			amortyr = amortsched->schedule.first_yr;
-			for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- ) {
-				if ( !jj ) {
-                    fprintf(ofile,"Pmt#       Interest  Total Payment        Balance\n");
-					pmtsched = amortyr->payments;
-					jj = amortyr->num_periods;
-				} /* endif */
+            if ( !--jj )
+            {
+                fprintf(ofile, "Summary for: %u:\n", amortyr->year);
+                fprintf(ofile, "  Interest  Paid: %.*f\n", (int)prec, amortyr->interest_pd);
+                fprintf(ofile, "  Principal Paid: %.*f\n", (int)prec, amortyr->principal_pd);
+                fprintf(ofile, "  Year Ending Balance: %.*f\n", (int)prec, amortyr->yr_end_balance);
+                fprintf(ofile, "  Sum of Interest Paid: %.*f\n", (int)prec, amortyr->total_interest_pd);
+                prst_yr = amortyr;
+                amortyr = amortyr->next_yr;
+            }
+            else
+            {
+                pmtsched++;
+            } /* endif */
+        } /* endfor */
+        break;
+    case 'o':
+        /* constant payment to principal
+         */
+        fprintf(ofile, "Constant Payment to Principal: %.*f\n", (int)prec, amortsched->cpmt);
+        amortyr = amortsched->schedule.first_yr;
+        for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- )
+        {
+            if ( !jj )
+            {
+                fprintf(ofile, "Pmt#       Interest  Total Payment        Balance\n");
+                pmtsched = amortyr->payments;
+                jj = amortyr->num_periods;
+            } /* endif */
 
-                fprintf(ofile,"%4u   %12.*f   %12.*f   %12.*f\n",
-                               pmtsched->period_num,
-                               (int)prec,pmtsched->interest,
-                               (int)prec,pmtsched->total_pmt,
-                               (int)prec,pmtsched->balance);
+            fprintf(ofile, "%4u   %12.*f   %12.*f   %12.*f\n",
+                    pmtsched->period_num,
+                    (int)prec, pmtsched->interest,
+                    (int)prec, pmtsched->total_pmt,
+                    (int)prec, pmtsched->balance);
 
-                if ( !--jj ) {
-                    fprintf(ofile,"Summary for: %u:\n",amortyr->year);
-                    fprintf(ofile,"  Interest  Paid: %.*f\n",(int)prec,amortyr->interest_pd);
-                    fprintf(ofile,"  Principal Paid: %.*f\n",(int)prec,amortyr->principal_pd);
-                    fprintf(ofile,"  Year Ending Balance: %.*f\n",(int)prec,amortyr->yr_end_balance);
-                    fprintf(ofile,"  Sum of Interest Paid: %.*f\n",(int)prec,amortyr->total_interest_pd);
-                    prst_yr = amortyr;
-                    amortyr = amortyr->next_yr;
-                  } else {
-                  	pmtsched++;
-                } /* endif */
-    		} /* endfor */			
-			break;
-		case 'p':
-			/* normal payment schedule
-			 */
-			fprintf(ofile,"Normal Amortization Schedule\n");
-			amortyr = amortsched->schedule.first_yr;
-			for ( j = amortsched->total_periods - 1 , jj = 0 ; j && amortyr ; j-- ) {
-				if ( !jj ) {
-                    fprintf(ofile,amortsched->fv_case ? "Pmt *       Interest        Balance\n" : "Pmt *       Interest      Principal        Balance\n");
-					pmtsched = amortyr->payments;
-					jj = amortyr->num_periods;
-				} /* endif */
+            if ( !--jj )
+            {
+                fprintf(ofile, "Summary for: %u:\n", amortyr->year);
+                fprintf(ofile, "  Interest  Paid: %.*f\n", (int)prec, amortyr->interest_pd);
+                fprintf(ofile, "  Principal Paid: %.*f\n", (int)prec, amortyr->principal_pd);
+                fprintf(ofile, "  Year Ending Balance: %.*f\n", (int)prec, amortyr->yr_end_balance);
+                fprintf(ofile, "  Sum of Interest Paid: %.*f\n", (int)prec, amortyr->total_interest_pd);
+                prst_yr = amortyr;
+                amortyr = amortyr->next_yr;
+            }
+            else
+            {
+                pmtsched++;
+            } /* endif */
+        } /* endfor */
+        break;
+    case 'p':
+        /* normal payment schedule
+         */
+        fprintf(ofile, "Normal Amortization Schedule\n");
+        amortyr = amortsched->schedule.first_yr;
+        for ( j = amortsched->total_periods - 1 , jj = 0 ; j && amortyr ; j-- )
+        {
+            if ( !jj )
+            {
+                fprintf(ofile, amortsched->fv_case ? "Pmt *       Interest        Balance\n" : "Pmt *       Interest      Principal        Balance\n");
+                pmtsched = amortyr->payments;
+                jj = amortyr->num_periods;
+            } /* endif */
 
-				if ( fv_case ) {
-					fprintf(ofile,"%4u   %12.*f   %12.*f\n",
-                                  pmtsched->period_num,
-                              	  (int)prec,pmtsched->interest,
-                              	  (int)prec,pmtsched->balance);
-				  } else {
-                    fprintf(ofile,"%4u    %12.*f   %12.*f   %12.*f\n",
-                                  pmtsched->period_num,
-                    		  (int)prec,pmtsched->interest,
-	                          (int)prec,pmtsched->principal,
-    	                          (int)prec,pmtsched->balance);					
-				} /* endif */
+            if ( fv_case )
+            {
+                fprintf(ofile, "%4u   %12.*f   %12.*f\n",
+                        pmtsched->period_num,
+                        (int)prec, pmtsched->interest,
+                        (int)prec, pmtsched->balance);
+            }
+            else
+            {
+                fprintf(ofile, "%4u    %12.*f   %12.*f   %12.*f\n",
+                        pmtsched->period_num,
+                        (int)prec, pmtsched->interest,
+                        (int)prec, pmtsched->principal,
+                        (int)prec, pmtsched->balance);
+            } /* endif */
 
-                if ( !--jj ) {
-                    fprintf(ofile,"Summary for: %u:\n",amortyr->year);
-                    fprintf(ofile,"  Interest  Paid: %.*f\n",(int)prec,amortyr->interest_pd);
-                    if ( !fv_case ) fprintf(ofile,"  Principal Paid: %.*f\n",(int)prec,amortyr->principal_pd);
-                    fprintf(ofile,"  Year Ending Balance: %.*f\n",(int)prec,amortyr->yr_end_balance);
-                    fprintf(ofile,"  Sum of Interest Paid: %.*f\n",(int)prec,amortyr->total_interest_pd);
-                    prst_yr = amortyr;
-                    amortyr = amortyr->next_yr;
-                  } else {
-                  	pmtsched++;
-                } /* endif */
-    		} /* endfor */
-    		
-    		if ( !jj ) {
-      			fprintf(ofile,amortsched->fv_case ? "Pmt *       Interest        Balance\n" : "Pmt *       Interest      Principal        Balance\n");
-				pmtsched = amortyr->payments;
-			} /* endif */
-			
-			fprintf(ofile,"Final Payment: %.*f\n",(int)prec,amortyr->final_pmt);
-			
-			if ( fv_case ) {
-				fprintf(ofile,"%4u   %12.*f   %12.*f\n",
-    					   pmtsched->period_num,
-             				   (int)prec,pmtsched->interest,
-                                        (int)prec,pmtsched->balance);
-			  } else {
-                fprintf(ofile,"%4u    %12.*f   %12.*f   %12.*f\n",
-                               pmtsched->period_num,
-                               (int)prec,pmtsched->interest,
-	                           (int)prec,pmtsched->principal,
-    	                       (int)prec,pmtsched->balance);
-    	    } /* endif */
-			
-			fprintf(ofile,"Summary for: %u:\n",amortyr->year);
-            fprintf(ofile,"  Interest  Paid: %.*f\n",(int)prec,amortyr->interest_pd);
-            if ( !fv_case ) fprintf(ofile,"  Principal Paid: %.*f\n",(int)prec,amortyr->principal_pd);
-            fprintf(ofile,"  Year Ending Balance: %.*f\n",(int)prec,amortyr->yr_end_balance);
-            fprintf(ofile,"  Sum of Interest Paid: %.*f\n",(int)prec,amortyr->total_interest_pd);
-			break;
-		case 'x':
-			/* constant payment to principal - annual summary
-			 */
-		case 'y':
-			/* normal payment - annual summary
-			 */
-			if ( summary == 'x' ) fprintf(ofile,"Annual Summary - Constant Payment to Principal: %.*f\n",(int)prec,amortsched->cpmt);
-			  else fprintf(ofile,"Annual Summary - Normal Amortization\n");
-			fprintf(ofile,"Year      Interest   Ending Balance\n");
-			annual_summary = amortsched->schedule.summary;
-			for ( j = amortsched->total_periods , jj = 0 ; j ; j-- , jj++ ) {
-				fprintf(ofile,"%4u  %12.*f   %12.*f\n",
-                               annual_summary[jj].year,
-                               (int)prec,annual_summary[jj].interest,
-                               (int)prec,annual_summary[jj].end_balance);
-			} /* endfor */
-			break;
-	} /* endswitch */
-	
-    fprintf(ofile,"\nTotal Interest: %.*f\n",(int)prec,amortsched->total_interest);
+            if ( !--jj )
+            {
+                fprintf(ofile, "Summary for: %u:\n", amortyr->year);
+                fprintf(ofile, "  Interest  Paid: %.*f\n", (int)prec, amortyr->interest_pd);
+                if ( !fv_case ) fprintf(ofile, "  Principal Paid: %.*f\n", (int)prec, amortyr->principal_pd);
+                fprintf(ofile, "  Year Ending Balance: %.*f\n", (int)prec, amortyr->yr_end_balance);
+                fprintf(ofile, "  Sum of Interest Paid: %.*f\n", (int)prec, amortyr->total_interest_pd);
+                prst_yr = amortyr;
+                amortyr = amortyr->next_yr;
+            }
+            else
+            {
+                pmtsched++;
+            } /* endif */
+        } /* endfor */
 
+        if ( !jj )
+        {
+            fprintf(ofile, amortsched->fv_case ? "Pmt *       Interest        Balance\n" : "Pmt *       Interest      Principal        Balance\n");
+            pmtsched = amortyr->payments;
+        } /* endif */
+
+        fprintf(ofile, "Final Payment: %.*f\n", (int)prec, amortyr->final_pmt);
+
+        if ( fv_case )
+        {
+            fprintf(ofile, "%4u   %12.*f   %12.*f\n",
+                    pmtsched->period_num,
+                    (int)prec, pmtsched->interest,
+                    (int)prec, pmtsched->balance);
+        }
+        else
+        {
+            fprintf(ofile, "%4u    %12.*f   %12.*f   %12.*f\n",
+                    pmtsched->period_num,
+                    (int)prec, pmtsched->interest,
+                    (int)prec, pmtsched->principal,
+                    (int)prec, pmtsched->balance);
+        } /* endif */
+
+        fprintf(ofile, "Summary for: %u:\n", amortyr->year);
+        fprintf(ofile, "  Interest  Paid: %.*f\n", (int)prec, amortyr->interest_pd);
+        if ( !fv_case ) fprintf(ofile, "  Principal Paid: %.*f\n", (int)prec, amortyr->principal_pd);
+        fprintf(ofile, "  Year Ending Balance: %.*f\n", (int)prec, amortyr->yr_end_balance);
+        fprintf(ofile, "  Sum of Interest Paid: %.*f\n", (int)prec, amortyr->total_interest_pd);
+        break;
+    case 'x':
+        /* constant payment to principal - annual summary
+         */
+    case 'y':
+        /* normal payment - annual summary
+         */
+        if ( summary == 'x' ) fprintf(ofile, "Annual Summary - Constant Payment to Principal: %.*f\n", (int)prec, amortsched->cpmt);
+        else fprintf(ofile, "Annual Summary - Normal Amortization\n");
+        fprintf(ofile, "Year      Interest   Ending Balance\n");
+        annual_summary = amortsched->schedule.summary;
+        for ( j = amortsched->total_periods , jj = 0 ; j ; j-- , jj++ )
+        {
+            fprintf(ofile, "%4u  %12.*f   %12.*f\n",
+                    annual_summary[jj].year,
+                    (int)prec, annual_summary[jj].interest,
+                    (int)prec, annual_summary[jj].end_balance);
+        } /* endfor */
+        break;
+    } /* endswitch */
+
+    fprintf(ofile, "\nTotal Interest: %.*f\n", (int)prec, amortsched->total_interest);
+
 } /* prt_amortization_schedule */

Modified: gnucash/trunk/src/calculation/expression_parser.c
===================================================================
--- gnucash/trunk/src/calculation/expression_parser.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/expression_parser.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -399,34 +399,34 @@
  * each caller */
 typedef struct parser_env
 {
-  unsigned stack_cnt;
-  unsigned stack_size;
-  var_store_ptr *stack;
-  var_store_ptr predefined_vars;
-  var_store_ptr named_vars;
-  var_store_ptr unnamed_vars;
+    unsigned stack_cnt;
+    unsigned stack_size;
+    var_store_ptr *stack;
+    var_store_ptr predefined_vars;
+    var_store_ptr named_vars;
+    var_store_ptr unnamed_vars;
 
-  const char *parse_str;
-  gchar *radix_point;
-  gchar *group_char;
-  char name[128];
+    const char *parse_str;
+    gchar *radix_point;
+    gchar *group_char;
+    char name[128];
 
-  char Token;
-  char asn_op;
+    char Token;
+    char asn_op;
 
-  char *tokens;
-  char *token_tail;
+    char *tokens;
+    char *token_tail;
 
-  ParseError error_code;
+    ParseError error_code;
 
-  void *numeric_value;
+    void *numeric_value;
 
-  void *(*trans_numeric) (const char *digit_str,
-			  gchar *radix_point, gchar *group_char, char **rstr);
-  void *(*numeric_ops) (char op_sym, void *left_value, void *right_value);
-  void *(*negate_numeric) (void *value);
-  void (*free_numeric) (void *numeric_value);
-  void *(*func_op)( const char *fname, int argc, void **argv );
+    void *(*trans_numeric) (const char *digit_str,
+                            gchar *radix_point, gchar *group_char, char **rstr);
+    void *(*numeric_ops) (char op_sym, void *left_value, void *right_value);
+    void *(*negate_numeric) (void *value);
+    void (*free_numeric) (void *numeric_value);
+    void *(*func_op)( const char *fname, int argc, void **argv );
 }
 parser_env;
 
@@ -450,94 +450,94 @@
 
 parser_env_ptr
 init_parser (var_store_ptr predefined_vars,
-	     gchar *radix_point,
-	     gchar *group_char,
-	     void *trans_numeric (const char *digit_str,
-				  gchar *radix_point,
-				  gchar *group_char,
-				  char **rstr),
-	     void *numeric_ops (char op_sym,
-				void *left_value,
-				void *right_value),
-	     void *negate_numeric (void *value),
-	     void free_numeric (void *numeric_value),
+             gchar *radix_point,
+             gchar *group_char,
+             void *trans_numeric (const char *digit_str,
+                                  gchar *radix_point,
+                                  gchar *group_char,
+                                  char **rstr),
+             void *numeric_ops (char op_sym,
+                                void *left_value,
+                                void *right_value),
+             void *negate_numeric (void *value),
+             void free_numeric (void *numeric_value),
              void *func_op( const char *fname,
                             int argc, void **argv ))
 {
-  parser_env_ptr pe = g_new0 (parser_env, 1);
+    parser_env_ptr pe = g_new0 (parser_env, 1);
 
-  pe->predefined_vars = predefined_vars;
+    pe->predefined_vars = predefined_vars;
 
-  pe->stack = g_new0 (var_store_ptr, STACK_INIT);
-  pe->stack_size = STACK_INIT;
+    pe->stack = g_new0 (var_store_ptr, STACK_INIT);
+    pe->stack_size = STACK_INIT;
 
-  pe->radix_point = radix_point;
-  pe->group_char = group_char;
+    pe->radix_point = radix_point;
+    pe->group_char = group_char;
 
-  pe->numeric_value = NULL;
+    pe->numeric_value = NULL;
 
-  pe->trans_numeric = trans_numeric;
-  pe->numeric_ops = numeric_ops;
-  pe->negate_numeric = negate_numeric;
-  pe->free_numeric = free_numeric;
-  pe->func_op = func_op;
+    pe->trans_numeric = trans_numeric;
+    pe->numeric_ops = numeric_ops;
+    pe->negate_numeric = negate_numeric;
+    pe->free_numeric = free_numeric;
+    pe->func_op = func_op;
 
-  return pe;
+    return pe;
 }				/* init_parser */
 
 void
 exit_parser (parser_env_ptr pe)
 {
-  var_store_ptr vars, bv;
+    var_store_ptr vars, bv;
 
-  if (pe == NULL)
-    return;
+    if (pe == NULL)
+        return;
 
-  for (vars = pe->named_vars; vars; vars = bv)
-  {
-    g_free (vars->variable_name);
-    vars->variable_name = NULL;
+    for (vars = pe->named_vars; vars; vars = bv)
+    {
+        g_free (vars->variable_name);
+        vars->variable_name = NULL;
 
-    if (vars->value)
-      pe->free_numeric (vars->value);
-    vars->value = NULL;
+        if (vars->value)
+            pe->free_numeric (vars->value);
+        vars->value = NULL;
 
-    bv = vars->next_var;
-    g_free (vars);
-  }				/* endfor */
+        bv = vars->next_var;
+        g_free (vars);
+    }				/* endfor */
 
-  pe->named_vars = NULL;
+    pe->named_vars = NULL;
 
-  g_free (pe->stack);
-  pe->stack = NULL;
+    g_free (pe->stack);
+    pe->stack = NULL;
 
-  g_free (pe->tokens);
-  pe->tokens = NULL;
-  pe->token_tail = NULL;
+    g_free (pe->tokens);
+    pe->tokens = NULL;
+    pe->token_tail = NULL;
 
-  if (pe->numeric_value)
-    pe->free_numeric (pe->numeric_value);
-  pe->numeric_value = NULL;
+    if (pe->numeric_value)
+        pe->free_numeric (pe->numeric_value);
+    pe->numeric_value = NULL;
 
-  g_free (pe);
+    g_free (pe);
 }				/* exit_parser */
 
 /* return parser error code */
 ParseError get_parse_error (parser_env_ptr pe)
 {
-  if (pe == NULL)
-    return PARSER_NO_ERROR;
+    if (pe == NULL)
+        return PARSER_NO_ERROR;
 
-  return pe->error_code;
+    return pe->error_code;
 }				/* get_parse_error */
 
 /* return linked list of named variables which have been defined */
 var_store_ptr parser_get_vars (parser_env_ptr pe)
 {
-  if (pe == NULL)
-    return NULL;
+    if (pe == NULL)
+        return NULL;
 
-  return pe->named_vars;
+    return pe->named_vars;
 }				/* get_vars */
 
 /* function to delete variable with specified name from named variables
@@ -545,35 +545,35 @@
 unsigned
 delete_var (char *var_name, parser_env_ptr pe)
 {
-  unsigned ret = FALSE;
-  var_store_ptr nv, tv;
+    unsigned ret = FALSE;
+    var_store_ptr nv, tv;
 
-  if (pe == NULL)
-    return FALSE;
+    if (pe == NULL)
+        return FALSE;
 
-  for (nv = pe->named_vars, tv = NULL; nv; tv = nv, nv = nv->next_var)
-  {
-    if (strcmp (nv->variable_name, var_name) == 0)
+    for (nv = pe->named_vars, tv = NULL; nv; tv = nv, nv = nv->next_var)
     {
-      if (tv)
-	tv->next_var = nv->next_var;
-      else
-	pe->named_vars = nv->next_var;
+        if (strcmp (nv->variable_name, var_name) == 0)
+        {
+            if (tv)
+                tv->next_var = nv->next_var;
+            else
+                pe->named_vars = nv->next_var;
 
-      g_free (nv->variable_name);
-      nv->variable_name = NULL;
+            g_free (nv->variable_name);
+            nv->variable_name = NULL;
 
-      pe->free_numeric (nv->value);
-      nv->value = NULL;
+            pe->free_numeric (nv->value);
+            nv->value = NULL;
 
-      g_free (nv);
+            g_free (nv);
 
-      ret = TRUE;
-      break;
-    }				/* endif */
-  }				/* endfor */
+            ret = TRUE;
+            break;
+        }				/* endif */
+    }				/* endfor */
 
-  return ret;
+    return ret;
 }				/* delete_var */
 
 /* parse string passed using parser environment passed return
@@ -583,89 +583,89 @@
 char *
 parse_string (var_store_ptr value, const char *string, parser_env_ptr pe)
 {
-  var_store_ptr retv;
-  var_store unnamed_vars[UNNAMED_VARS];
+    var_store_ptr retv;
+    var_store unnamed_vars[UNNAMED_VARS];
 
-  if (!pe || !string)
-    return NULL;
+    if (!pe || !string)
+        return NULL;
 
-  pe->unnamed_vars = unnamed_vars;
-  memset (unnamed_vars, 0, UNNAMED_VARS * sizeof (var_store));
+    pe->unnamed_vars = unnamed_vars;
+    memset (unnamed_vars, 0, UNNAMED_VARS * sizeof (var_store));
 
-  pe->parse_str = string;
-  pe->error_code = PARSER_NO_ERROR;
+    pe->parse_str = string;
+    pe->error_code = PARSER_NO_ERROR;
 
-  g_free (pe->tokens);
-  pe->tokens = g_new0(char, strlen (string) + 1);
-  pe->token_tail = pe->tokens;
+    g_free (pe->tokens);
+    pe->tokens = g_new0(char, strlen (string) + 1);
+    pe->token_tail = pe->tokens;
 
-  next_token (pe);
+    next_token (pe);
 
-  if (!pe->error_code)
-    assignment_op (pe);
+    if (!pe->error_code)
+        assignment_op (pe);
 
-  if (!pe->error_code)
-  {
-    /* interpret (num) as -num */
-    if (strcmp (pe->tokens, "(I)") == 0)
+    if (!pe->error_code)
     {
-      var_store_ptr val;
+        /* interpret (num) as -num */
+        if (strcmp (pe->tokens, "(I)") == 0)
+        {
+            var_store_ptr val;
 
-      val = pop (pe);
-      pe->negate_numeric (val->value);
-      push (val, pe);
+            val = pop (pe);
+            pe->negate_numeric (val->value);
+            push (val, pe);
+        }
     }
-  }
 
-  if (pe->Token == EOS)
-  {
-    if ((pe->stack_cnt) && (retv = pop (pe)))
+    if (pe->Token == EOS)
     {
-      if (value != NULL)
-	*value = *retv;
-      pe->parse_str = NULL;
+        if ((pe->stack_cnt) && (retv = pop (pe)))
+        {
+            if (value != NULL)
+                *value = *retv;
+            pe->parse_str = NULL;
+        }
+        else
+            pe->error_code = STACK_UNDERFLOW;
     }
-    else
-      pe->error_code = STACK_UNDERFLOW;
-  }
 
-  pe->stack_cnt = 0;
-  pe->unnamed_vars = NULL;
+    pe->stack_cnt = 0;
+    pe->unnamed_vars = NULL;
 
-  return (char *) pe->parse_str;
+    return (char *) pe->parse_str;
 }				/* expression */
 
 /* pop value off value stack */
 static var_store_ptr
 pop (parser_env_ptr pe)
 {
-  var_store_ptr val;
+    var_store_ptr val;
 
-  if (pe->stack_cnt)
-    val = pe->stack[--(pe->stack_cnt)];
-  else
-  {
-    val = NULL;
-    pe->error_code = STACK_UNDERFLOW;
-  }				/* endif */
+    if (pe->stack_cnt)
+        val = pe->stack[--(pe->stack_cnt)];
+    else
+    {
+        val = NULL;
+        pe->error_code = STACK_UNDERFLOW;
+    }				/* endif */
 
-  return val;
+    return val;
 }				/* pop */
 
 /* push value onto value stack */
 static var_store_ptr
 push (var_store_ptr push_value, parser_env_ptr pe)
 {
-  if (pe->stack_cnt > pe->stack_size)
-  {
-    pe->stack_size += STACK_INIT;
-    pe->stack = g_realloc (pe->stack,
-			   pe->stack_size * sizeof (var_store_ptr));
-  }				/* endif */
+    if (pe->stack_cnt > pe->stack_size)
+    {
+        pe->stack_size += STACK_INIT;
+        pe->stack = g_realloc (pe->stack,
+                               pe->stack_size * sizeof (var_store_ptr));
+    }				/* endif */
 
-  pe->stack[(pe->stack_cnt)++] = push_value;
+    pe->stack[(pe->stack_cnt)++] = push_value;
 
-  return push_value;
+    return push_value;
 }				/* push */
 
 /* get/set variable with specified name - nothing fancy just scan each
@@ -674,86 +674,87 @@
 static var_store_ptr
 get_named_var (parser_env_ptr pe)
 {
-  var_store_ptr retp = NULL, bv;
+    var_store_ptr retp = NULL, bv;
 
-  for (retp = pe->predefined_vars, bv = NULL; retp; retp = retp->next_var)
-    if (strcmp (retp->variable_name, pe->name) == 0)
-      break;
+    for (retp = pe->predefined_vars, bv = NULL; retp; retp = retp->next_var)
+        if (strcmp (retp->variable_name, pe->name) == 0)
+            break;
 
-  if (!retp && pe->named_vars)
-    for (retp = pe->named_vars; retp; bv = retp, retp = retp->next_var)
-      if (strcmp (retp->variable_name, pe->name) == 0)
-	break;
+    if (!retp && pe->named_vars)
+        for (retp = pe->named_vars; retp; bv = retp, retp = retp->next_var)
+            if (strcmp (retp->variable_name, pe->name) == 0)
+                break;
 
-  if (!retp)
-  {
-    retp = g_new0 (var_store, 1);
-    if (!pe->named_vars)
-      pe->named_vars = retp;
-    else
-      bv->next_var = retp;
-    retp->variable_name = g_strdup (pe->name);
-    retp->type = VST_NUMERIC;
-    retp->value =
-      pe->trans_numeric ("0", pe->radix_point, pe->group_char, NULL);
-  }
+    if (!retp)
+    {
+        retp = g_new0 (var_store, 1);
+        if (!pe->named_vars)
+            pe->named_vars = retp;
+        else
+            bv->next_var = retp;
+        retp->variable_name = g_strdup (pe->name);
+        retp->type = VST_NUMERIC;
+        retp->value =
+            pe->trans_numeric ("0", pe->radix_point, pe->group_char, NULL);
+    }
 
-  return retp;
+    return retp;
 }				/* get_var */
 
 /* get un-named temporary variable */
 static var_store_ptr
 get_unnamed_var (parser_env_ptr pe)
 {
-  var_store_ptr retp = NULL;
-  unsigned cntr;
+    var_store_ptr retp = NULL;
+    unsigned cntr;
 
-  for (cntr = 0; cntr < UNNAMED_VARS; cntr++)
-    if (pe->unnamed_vars[cntr].use_flag == UNUSED_VAR)
-    {
-      retp = &(pe->unnamed_vars[cntr]);
-      retp->variable_name = NULL;
-      retp->use_flag = USED_VAR;
-      retp->type = VST_NUMERIC;
-      if (retp->value)
-      {
-	pe->free_numeric (retp->value);
-        retp->value = NULL;
-      }				/* endif */
-      break;
-    }				/* endif */
+    for (cntr = 0; cntr < UNNAMED_VARS; cntr++)
+        if (pe->unnamed_vars[cntr].use_flag == UNUSED_VAR)
+        {
+            retp = &(pe->unnamed_vars[cntr]);
+            retp->variable_name = NULL;
+            retp->use_flag = USED_VAR;
+            retp->type = VST_NUMERIC;
+            if (retp->value)
+            {
+                pe->free_numeric (retp->value);
+                retp->value = NULL;
+            }				/* endif */
+            break;
+        }				/* endif */
 
-  if (retp == NULL)
-    pe->error_code = PARSER_OUT_OF_MEMORY;
+    if (retp == NULL)
+        pe->error_code = PARSER_OUT_OF_MEMORY;
 
-  return retp;
+    return retp;
 }				/* get_unnamed_var */
 
 /* mark un-named temporary variable unused */
 static void
 free_var (var_store_ptr value, parser_env_ptr pe)
 {
-  if (value == NULL)
-    return;
+    if (value == NULL)
+        return;
 
-  /* first check that not a named variable */
-  if (value->variable_name != NULL)
-    return;
+    /* first check that not a named variable */
+    if (value->variable_name != NULL)
+        return;
 
-  value->use_flag = UNUSED_VAR;
+    value->use_flag = UNUSED_VAR;
 
-  if (value->value)
-  {
-    pe->free_numeric (value->value);
-    value->value = NULL;
-  }
+    if (value->value)
+    {
+        pe->free_numeric (value->value);
+        value->value = NULL;
+    }
 }				/* free_var */
 
 static void
 add_token (parser_env_ptr pe, char token)
 {
     pe->Token = token;
-    if ((token != EOS) || (*pe->token_tail != EOS)) {
+    if ((token != EOS) || (*pe->token_tail != EOS))
+    {
         *pe->token_tail = token;
         pe->token_tail++;
     }
@@ -763,98 +764,105 @@
 static void
 next_token (parser_env_ptr pe)
 {
-  char *nstr;
-  const char *str_parse = pe->parse_str;
-  void *number;
+    char *nstr;
+    const char *str_parse = pe->parse_str;
+    void *number;
 
-  while (isspace (*str_parse))
-    str_parse++;
+    while (isspace (*str_parse))
+        str_parse++;
 
-  pe->asn_op = EOS;
+    pe->asn_op = EOS;
 
-  /* test for end of string */
-  if (!*str_parse)
-  {
-    add_token (pe, EOS);
-  }
-  /* test for possible operator */
-  else if (strchr (allowed_operators, *str_parse))
-  {
-    add_token (pe, *str_parse++);
-    if (*str_parse == ASN_OP)
+    /* test for end of string */
+    if (!*str_parse)
     {
-      /* BUG/FIXME: this seems to allow '(=' and ')=' [?], neither of which
-       * make sense. */
-      if (pe->Token != ASN_OP)
-      {
-        str_parse++;
-        pe->asn_op = pe->Token;
-        add_token (pe, ASN_OP);
-      }
-      else
-        pe->error_code = UNDEFINED_CHARACTER;
-    }				/* endif */
-  }
-  /* test for string */
-  else if ( *str_parse == '"' ) { 
-    nstr = pe->name;
-    /* skip over the '"'. */
-    str_parse++;
-    do {
-      *nstr++ = *str_parse++;
-    } while ( *str_parse != '"' );
-    *nstr = EOS;
-    str_parse++;
-    add_token( pe, STR_TOKEN );
-  }
-  /* test for name */
-  else if (isalpha (*str_parse)
-           || (*str_parse == '_'))
-  {
-    int funcFlag = 0;
-    
-    /* Check for variable or function */
-    /* If variable: add token. */
-    /* If function: parse args, build struct, add token. */
-    nstr = pe->name;
-    do
+        add_token (pe, EOS);
+    }
+    /* test for possible operator */
+    else if (strchr (allowed_operators, *str_parse))
     {
-      if ( *str_parse == '(' ) {
-        funcFlag = 1;
+        add_token (pe, *str_parse++);
+        if (*str_parse == ASN_OP)
+        {
+            /* BUG/FIXME: this seems to allow '(=' and ')=' [?], neither of which
+             * make sense. */
+            if (pe->Token != ASN_OP)
+            {
+                str_parse++;
+                pe->asn_op = pe->Token;
+                add_token (pe, ASN_OP);
+            }
+            else
+                pe->error_code = UNDEFINED_CHARACTER;
+        }				/* endif */
+    }
+    /* test for string */
+    else if ( *str_parse == '"' )
+    {
+        nstr = pe->name;
+        /* skip over the '"'. */
         str_parse++;
-        break;
-      }
-      *nstr++ = *str_parse++;
+        do
+        {
+            *nstr++ = *str_parse++;
+        }
+        while ( *str_parse != '"' );
+        *nstr = EOS;
+        str_parse++;
+        add_token( pe, STR_TOKEN );
     }
-    while ((*str_parse == '_')
-           || (*str_parse == '(')
-           || isalpha (*str_parse)
-           || isdigit (*str_parse));
+    /* test for name */
+    else if (isalpha (*str_parse)
+             || (*str_parse == '_'))
+    {
+        int funcFlag = 0;
 
-    *nstr = EOS;
-    if ( funcFlag ) {
-      add_token(pe, FN_TOKEN);
-    } else {
-      add_token(pe, VAR_TOKEN);
+        /* Check for variable or function */
+        /* If variable: add token. */
+        /* If function: parse args, build struct, add token. */
+        nstr = pe->name;
+        do
+        {
+            if ( *str_parse == '(' )
+            {
+                funcFlag = 1;
+                str_parse++;
+                break;
+            }
+            *nstr++ = *str_parse++;
+        }
+        while ((*str_parse == '_')
+                || (*str_parse == '(')
+                || isalpha (*str_parse)
+                || isdigit (*str_parse));
+
+        *nstr = EOS;
+        if ( funcFlag )
+        {
+            add_token(pe, FN_TOKEN);
+        }
+        else
+        {
+            add_token(pe, VAR_TOKEN);
+        }
+
     }
+    /* test for numeric token */
+    else if ((number = pe->trans_numeric (str_parse, pe->radix_point,
+                                          pe->group_char, &nstr)))
+    {
+        add_token (pe, NUM_TOKEN);
+        pe->numeric_value = number;
+        str_parse = nstr;
+    }
+    /* unrecognized character - error */
+    else
+    {
+        add_token (pe, *str_parse);
+        pe->error_code = UNDEFINED_CHARACTER;
+    }				/* endif */
 
-  }
-  /* test for numeric token */
-  else if ((number = pe->trans_numeric (str_parse, pe->radix_point,
-                                        pe->group_char, &nstr)))
-  {
-    add_token (pe, NUM_TOKEN);
-    pe->numeric_value = number;
-    str_parse = nstr;
-  }
-  /* unrecognized character - error */
-  else
-  {
-    add_token (pe, *str_parse);
-    pe->error_code = UNDEFINED_CHARACTER;
-  }				/* endif */
-
-  pe->parse_str = str_parse;
+    pe->parse_str = str_parse;
 }				/* next_token */
 
 /* evaluate assignment operators,
@@ -868,79 +876,80 @@
 static void
 assignment_op (parser_env_ptr pe)
 {
-  var_store_ptr vl;		/* left value       */
-  var_store_ptr vr;		/* right value      */
-  char ao;
+    var_store_ptr vl;		/* left value       */
+    var_store_ptr vr;		/* right value      */
+    char ao;
 
-  add_sub_op (pe);
-  if (pe->error_code)
-    return;
-
-  while (pe->Token == ASN_OP)
-  {
-    vl = pop (pe);
+    add_sub_op (pe);
     if (pe->error_code)
-      return;
+        return;
 
-    ao = pe->asn_op;
-
-    if (vl->variable_name)
+    while (pe->Token == ASN_OP)
     {
-      next_token (pe);
-      if (pe->error_code)
-      {
-        free_var (vl, pe);
-        return;
-      }
+        vl = pop (pe);
+        if (pe->error_code)
+            return;
 
-      assignment_op (pe);
-      if (pe->error_code)
-      {
-        free_var (vl, pe);
-        return;
-      }
+        ao = pe->asn_op;
 
-      vr = pop (pe);
-      if (pe->error_code)
-      {
-        free_var (vl, pe);
-        return;
-      }
+        if (vl->variable_name)
+        {
+            next_token (pe);
+            if (pe->error_code)
+            {
+                free_var (vl, pe);
+                return;
+            }
 
-      vl->assign_flag = ASSIGNED_TO;
+            assignment_op (pe);
+            if (pe->error_code)
+            {
+                free_var (vl, pe);
+                return;
+            }
 
-      if (ao)
-      {
-        void *temp;
+            vr = pop (pe);
+            if (pe->error_code)
+            {
+                free_var (vl, pe);
+                return;
+            }
 
-	temp = vl->value;
-	vl->value = pe->numeric_ops (ao, vl->value, vr->value);
-	pe->free_numeric (temp);
-      }
-      else if (vl != vr)
-      {
-	if (!vr->variable_name)
-	{
-	  pe->free_numeric (vl->value);
-	  vl->value = vr->value;
-	  vr->value = NULL;
-	}
-	else {
-	  pe->numeric_ops (ASN_OP, vl->value, vr->value);
-        }
+            vl->assign_flag = ASSIGNED_TO;
 
-	free_var (vr, pe);
-      }				/* endif */
+            if (ao)
+            {
+                void *temp;
 
-      push (vl, pe);
-    }
-    else
-    {
-      add_token (pe, EOS);	/* error !!!!!!!!!! */
-      pe->error_code = NOT_A_VARIABLE;
-      free_var (vl, pe);
-    }				/* endif */
-  }				/* endwhile */
+                temp = vl->value;
+                vl->value = pe->numeric_ops (ao, vl->value, vr->value);
+                pe->free_numeric (temp);
+            }
+            else if (vl != vr)
+            {
+                if (!vr->variable_name)
+                {
+                    pe->free_numeric (vl->value);
+                    vl->value = vr->value;
+                    vr->value = NULL;
+                }
+                else
+                {
+                    pe->numeric_ops (ASN_OP, vl->value, vr->value);
+                }
+
+                free_var (vr, pe);
+            }				/* endif */
+
+            push (vl, pe);
+        }
+        else
+        {
+            add_token (pe, EOS);	/* error !!!!!!!!!! */
+            pe->error_code = NOT_A_VARIABLE;
+            free_var (vl, pe);
+        }				/* endif */
+    }				/* endwhile */
 }				/* assignment_op */
 
 /* evaluate addition, subtraction operators */
@@ -948,59 +957,59 @@
 static void
 add_sub_op (parser_env_ptr pe)
 {
-  var_store_ptr vl;	/* left value   */
-  var_store_ptr vr;	/* right value  */
-  var_store_ptr rslt;   /* result       */
-  char op;
+    var_store_ptr vl;	/* left value   */
+    var_store_ptr vr;	/* right value  */
+    var_store_ptr rslt;   /* result       */
+    char op;
 
-  multiply_divide_op (pe);
-  if (pe->error_code)
-    return;
-
-  while ((pe->Token == ADD_OP) || (pe->Token == SUB_OP))
-  {
-    op = pe->Token;
-
-    vl = pop (pe);
+    multiply_divide_op (pe);
     if (pe->error_code)
-      return;
+        return;
 
-    next_token (pe);
-    if (pe->error_code)
+    while ((pe->Token == ADD_OP) || (pe->Token == SUB_OP))
     {
-      free_var (vl, pe);
-      return;
-    }
+        op = pe->Token;
 
-    multiply_divide_op (pe);
-    if (pe->error_code)
-    {
-      free_var (vl, pe);
-      return;
-    }
+        vl = pop (pe);
+        if (pe->error_code)
+            return;
 
-    vr = pop (pe);
-    if (pe->error_code)
-    {
-      free_var (vl, pe);
-      return;
-    }
+        next_token (pe);
+        if (pe->error_code)
+        {
+            free_var (vl, pe);
+            return;
+        }
 
-    rslt = get_unnamed_var (pe);
-    if (pe->error_code)
-    {
-      free_var (vl, pe);
-      free_var (vr, pe);
-      return;
-    }
+        multiply_divide_op (pe);
+        if (pe->error_code)
+        {
+            free_var (vl, pe);
+            return;
+        }
 
-    rslt->value = pe->numeric_ops (op, vl->value, vr->value);
+        vr = pop (pe);
+        if (pe->error_code)
+        {
+            free_var (vl, pe);
+            return;
+        }
 
-    free_var (vl, pe);
-    free_var (vr, pe);
+        rslt = get_unnamed_var (pe);
+        if (pe->error_code)
+        {
+            free_var (vl, pe);
+            free_var (vr, pe);
+            return;
+        }
 
-    push (rslt, pe);
-  }				/* endwhile */
+        rslt->value = pe->numeric_ops (op, vl->value, vr->value);
+
+        free_var (vl, pe);
+        free_var (vr, pe);
+
+        push (rslt, pe);
+    }				/* endwhile */
 }				/* add_sub_op */
 
 /* evaluate multiplication, division operators */
@@ -1008,59 +1017,59 @@
 static void
 multiply_divide_op (parser_env_ptr pe)
 {
-  var_store_ptr vl;	/* left value   */
-  var_store_ptr vr;	/* right value  */
-  var_store_ptr rslt;   /* result       */
-  char op;
+    var_store_ptr vl;	/* left value   */
+    var_store_ptr vr;	/* right value  */
+    var_store_ptr rslt;   /* result       */
+    char op;
 
-  primary_exp (pe);
-  if (pe->error_code)
-    return;
-
-  while ((pe->Token == MUL_OP) || (pe->Token == DIV_OP))
-  {
-    op = pe->Token;
-
-    vl = pop (pe);
+    primary_exp (pe);
     if (pe->error_code)
-      return;
+        return;
 
-    next_token (pe);
-    if (pe->error_code)
+    while ((pe->Token == MUL_OP) || (pe->Token == DIV_OP))
     {
-      free_var (vl, pe);
-      return;
-    }
+        op = pe->Token;
 
-    primary_exp (pe);
-    if (pe->error_code)
-    {
-      free_var (vl, pe);
-      return;
-    }
+        vl = pop (pe);
+        if (pe->error_code)
+            return;
 
-    vr = pop (pe);
-    if (pe->error_code)
-    {
-      free_var (vl, pe);
-      return;
-    }
+        next_token (pe);
+        if (pe->error_code)
+        {
+            free_var (vl, pe);
+            return;
+        }
 
-    rslt = get_unnamed_var (pe);
-    if (pe->error_code)
-    {
-      free_var (vl, pe);
-      free_var (vr, pe);
-      return;
-    }
+        primary_exp (pe);
+        if (pe->error_code)
+        {
+            free_var (vl, pe);
+            return;
+        }
 
-    rslt->value = pe->numeric_ops (op, vl->value, vr->value);
+        vr = pop (pe);
+        if (pe->error_code)
+        {
+            free_var (vl, pe);
+            return;
+        }
 
-    free_var (vl, pe);
-    free_var (vr, pe);
+        rslt = get_unnamed_var (pe);
+        if (pe->error_code)
+        {
+            free_var (vl, pe);
+            free_var (vr, pe);
+            return;
+        }
 
-    push (rslt, pe);
-  }				/* endwhile */
+        rslt->value = pe->numeric_ops (op, vl->value, vr->value);
+
+        free_var (vl, pe);
+        free_var (vr, pe);
+
+        push (rslt, pe);
+    }				/* endwhile */
 }				/* multiply_divide_op */
 
 /**
@@ -1071,16 +1080,16 @@
 static int
 check_expression_grammar_error(parser_env_ptr pe)
 {
-  if (pe->Token == VAR_TOKEN
-      || pe->Token == STR_TOKEN
-      || pe->Token == NUM_TOKEN
-      || pe->Token == FN_TOKEN)
-  {
-    add_token(pe, EOS);
-    pe->error_code = EXPRESSION_ERROR;
-    return TRUE;
-  }
-  return FALSE;
+    if (pe->Token == VAR_TOKEN
+            || pe->Token == STR_TOKEN
+            || pe->Token == NUM_TOKEN
+            || pe->Token == FN_TOKEN)
+    {
+        add_token(pe, EOS);
+        pe->error_code = EXPRESSION_ERROR;
+        return TRUE;
+    }
+    return FALSE;
 }
 
 /* evaluate:
@@ -1094,156 +1103,165 @@
 static void
 primary_exp (parser_env_ptr pe)
 {
-  var_store_ptr rslt = NULL;
-  char *ident = NULL;
-  int funcArgCount;
-  char LToken = pe->Token;
+    var_store_ptr rslt = NULL;
+    char *ident = NULL;
+    int funcArgCount;
+    char LToken = pe->Token;
 
-  /* If we are in a state where the non-stacked 'pe->name' is valuable, then
-   * save it before we process the next token. */
-  switch ( LToken ) {
-  case FN_TOKEN:
-  case STR_TOKEN:
-    ident = g_strdup( pe->name );
-    break;
-  }
+    /* If we are in a state where the non-stacked 'pe->name' is valuable, then
+     * save it before we process the next token. */
+    switch ( LToken )
+    {
+    case FN_TOKEN:
+    case STR_TOKEN:
+        ident = g_strdup( pe->name );
+        break;
+    }
 
-  next_token (pe);
-  if (pe->error_code)
-    return;
+    next_token (pe);
+    if (pe->error_code)
+        return;
 
-  switch (LToken)
-  {
+    switch (LToken)
+    {
     case '(':
-      assignment_op (pe);
-      if (pe->error_code)
-        return;
-
-      if (pe->Token == ')')
-      {
-        rslt = pop (pe);
+        assignment_op (pe);
         if (pe->error_code)
-          return;
+            return;
 
-        next_token (pe);
-        if (pe->error_code)
-          return;
-      }
-      else
-      {
-        add_token (pe, EOS);	/* error here */
-        pe->error_code = UNBALANCED_PARENS;
-      }				/* endif */
+        if (pe->Token == ')')
+        {
+            rslt = pop (pe);
+            if (pe->error_code)
+                return;
 
-      break;
+            next_token (pe);
+            if (pe->error_code)
+                return;
+        }
+        else
+        {
+            add_token (pe, EOS);	/* error here */
+            pe->error_code = UNBALANCED_PARENS;
+        }				/* endif */
 
+        break;
+
     case ADD_OP:
     case SUB_OP:
-      primary_exp (pe);
-      if (pe->error_code)
-        return;
+        primary_exp (pe);
+        if (pe->error_code)
+            return;
 
-      rslt = pop (pe);
-      if (pe->error_code)
-        return;
+        rslt = pop (pe);
+        if (pe->error_code)
+            return;
 
-      if (LToken == SUB_OP)
-        pe->negate_numeric (rslt->value);
+        if (LToken == SUB_OP)
+            pe->negate_numeric (rslt->value);
 
-      break;
+        break;
 
     case NUM_TOKEN:
-      rslt = get_unnamed_var (pe);
-      if (pe->error_code)
-        return;
+        rslt = get_unnamed_var (pe);
+        if (pe->error_code)
+            return;
 
-      if (check_expression_grammar_error(pe))
-        return;
+        if (check_expression_grammar_error(pe))
+            return;
 
-      rslt->value = pe->numeric_value;
-      pe->numeric_value = NULL;
-      break;
+        rslt->value = pe->numeric_value;
+        pe->numeric_value = NULL;
+        break;
 
     case FN_TOKEN:
-      funcArgCount = 0;
+        funcArgCount = 0;
 
-      if (pe->Token && pe->Token != ')') {
-        do {
-          assignment_op(pe);
-          if ( pe->error_code )
-            return;
-          funcArgCount++;
-          if (!pe->Token || pe->Token == ')') {
-            break;
-          }
-          next_token(pe);
-        } while (pe->Token != ARG_TOKEN);
-      }
+        if (pe->Token && pe->Token != ')')
+        {
+            do
+            {
+                assignment_op(pe);
+                if ( pe->error_code )
+                    return;
+                funcArgCount++;
+                if (!pe->Token || pe->Token == ')')
+                {
+                    break;
+                }
+                next_token(pe);
+            }
+            while (pe->Token != ARG_TOKEN);
+        }
 
-      if ( pe->Token != ')' ) {
-        add_token( pe, EOS );
-        pe->error_code = UNBALANCED_PARENS;
-      }
+        if ( pe->Token != ')' )
+        {
+            add_token( pe, EOS );
+            pe->error_code = UNBALANCED_PARENS;
+        }
 
-      {
-        int i;
-        var_store_ptr val;
-        void **argv;
+        {
+            int i;
+            var_store_ptr val;
+            void **argv;
 
-        argv = g_new0( void*, funcArgCount );
-        for ( i=0; i<funcArgCount; i++ ) {
-          /* fill, in back-to-front order, the funcArgCount tokens we just
-           * parsed out of the expression into a argument list to hand back
-           * to the caller's func_op callback. */
-          val = pop(pe);
-          argv[funcArgCount - i - 1] = val;
-        }
+            argv = g_new0( void*, funcArgCount );
+            for ( i = 0; i < funcArgCount; i++ )
+            {
+                /* fill, in back-to-front order, the funcArgCount tokens we just
+                 * parsed out of the expression into a argument list to hand back
+                 * to the caller's func_op callback. */
+                val = pop(pe);
+                argv[funcArgCount - i - 1] = val;
+            }
 
-        rslt = get_unnamed_var(pe);
-        rslt->value = (*pe->func_op)( ident, funcArgCount, argv );
+            rslt = get_unnamed_var(pe);
+            rslt->value = (*pe->func_op)( ident, funcArgCount, argv );
 
-        for ( i=0; i<funcArgCount; i++ ) {
-          free_var( argv[i], pe );
-        }
-        g_free( argv );
-        g_free( ident );
+            for ( i = 0; i < funcArgCount; i++ )
+            {
+                free_var( argv[i], pe );
+            }
+            g_free( argv );
+            g_free( ident );
 
-        if ( rslt->value == NULL ) {
-          pe->error_code = NOT_A_FUNC;
-          add_token( pe, EOS );
-          return;
+            if ( rslt->value == NULL )
+            {
+                pe->error_code = NOT_A_FUNC;
+                add_token( pe, EOS );
+                return;
+            }
         }
-      }
 
-      next_token(pe);
+        next_token(pe);
 
-      if (check_expression_grammar_error(pe))
-        return;
+        if (check_expression_grammar_error(pe))
+            return;
 
-      break;
+        break;
 
     case VAR_TOKEN:
-      if (check_expression_grammar_error(pe))
-        return;
+        if (check_expression_grammar_error(pe))
+            return;
 
-      rslt = get_named_var (pe);
-      break;
+        rslt = get_named_var (pe);
+        break;
     case STR_TOKEN:
-      if (!(pe->Token == ')'
-            || pe->Token == ARG_TOKEN))
-      {
-        add_token(pe, EOS);
-        pe->error_code = EXPRESSION_ERROR;
-        return;
-      }
+        if (!(pe->Token == ')'
+                || pe->Token == ARG_TOKEN))
+        {
+            add_token(pe, EOS);
+            pe->error_code = EXPRESSION_ERROR;
+            return;
+        }
 
-      rslt = get_unnamed_var( pe );
-      rslt->type = VST_STRING;
-      rslt->value = ident;
-      break;
-  }				/* endswitch */
+        rslt = get_unnamed_var( pe );
+        rslt->type = VST_STRING;
+        rslt->value = ident;
+        break;
+    }				/* endswitch */
 
-  if (rslt != NULL)
-    push (rslt, pe);
+    if (rslt != NULL)
+        push (rslt, pe);
 
 }				/* primary_exp */

Modified: gnucash/trunk/src/calculation/fin-interactive.c
===================================================================
--- gnucash/trunk/src/calculation/fin-interactive.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/fin-interactive.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -32,14 +32,14 @@
 #include "numeric_ops.h"
 
 static void  prt_status(
-fi_ptr       fi,
-FILE        *ofile);
+    fi_ptr       fi,
+    FILE        *ofile);
 
 static void set_fin_vars(
-            void);
+    void);
 
 static void unset_fin_vars(
-            void);
+    void);
 
 #define PREDEFINED_FIN_VARS 9
 
@@ -66,35 +66,38 @@
 
 /* declare array of finacial varibale names used by user to access financial variables
  */
-static char *fin_var_names[] = {
-	"n",
-	"i",
-	"pv",
-	"pmt",
-	"fv",
-	"CF",
-	"PF",
-	"disc",
-	"bep",
+static char *fin_var_names[] =
+{
+    "n",
+    "i",
+    "pv",
+    "pmt",
+    "fv",
+    "CF",
+    "PF",
+    "disc",
+    "bep",
 };
 
 /* declare array of financial variables
  */
-static void *fin_vars[] = {
-	(void *)&npp,
-	(void *)&ir,
-	(void *)&pv,
-	(void *)&pmt,
-	(void *)&fv,
-	(void *)&CF,
-	(void *)&PF,
-	(void *)&disc,
-	(void *)&bep,
+static void *fin_vars[] =
+{
+    (void *)&npp,
+    (void *)&ir,
+    (void *)&pv,
+    (void *)&pmt,
+    (void *)&fv,
+    (void *)&CF,
+    (void *)&PF,
+    (void *)&disc,
+    (void *)&bep,
 };
 
 /* declare array of financial variable basic numeric types
  */
-static char fin_type[] = {
+static char fin_type[] =
+{
     INT_TYPE,
     DBL_TYPE,
     DBL_TYPE,
@@ -112,23 +115,25 @@
  * as pre-defined variables
  */
 static void set_fin_vars(
-void)
+    void)
 {
     unsigned    cntr;
     numeric_ptr value;
 
-    for ( cntr = 0 ; cntr < PREDEFINED_FIN_VARS ; cntr++ ) {
-    	predefined_fin_vars[cntr].variable_name = fin_var_names[cntr];
-    	predefined_fin_vars[cntr].assign_flag = EOS;
-    	predefined_fin_vars[cntr].value = value = (numeric_ptr)calloc(1,sizeof(numeric));
-    	predefined_fin_vars[cntr].next_var = &predefined_fin_vars[cntr + 1];
-        switch ( value->type = fin_type[cntr] ) {
-            case INT_TYPE:
-                value->value.int_value = *(unsigned *)(fin_vars[cntr]);
-                break;
-            case DBL_TYPE:
-                value->value.dbl_value = *(double *)(fin_vars[cntr]);
-                break;
+    for ( cntr = 0 ; cntr < PREDEFINED_FIN_VARS ; cntr++ )
+    {
+        predefined_fin_vars[cntr].variable_name = fin_var_names[cntr];
+        predefined_fin_vars[cntr].assign_flag = EOS;
+        predefined_fin_vars[cntr].value = value = (numeric_ptr)calloc(1, sizeof(numeric));
+        predefined_fin_vars[cntr].next_var = &predefined_fin_vars[cntr + 1];
+        switch ( value->type = fin_type[cntr] )
+        {
+        case INT_TYPE:
+            value->value.int_value = *(unsigned *)(fin_vars[cntr]);
+            break;
+        case DBL_TYPE:
+            value->value.dbl_value = *(double *)(fin_vars[cntr]);
+            break;
         } /* endswitch */
     } /* endfor */
     predefined_fin_vars[PREDEFINED_FIN_VARS - 1].next_var = NULL;
@@ -137,14 +142,15 @@
 /* free storage used by local financial variables
  */
 static void unset_fin_vars(
-void)
+    void)
 {
     unsigned    cntr;
     numeric_ptr value;
 
-    for ( cntr = 0 ; cntr < PREDEFINED_FIN_VARS ; cntr++ ) {
-    	free(predefined_fin_vars[cntr].value);
-    } /* endfor */	
+    for ( cntr = 0 ; cntr < PREDEFINED_FIN_VARS ; cntr++ )
+    {
+        free(predefined_fin_vars[cntr].value);
+    } /* endfor */
 } /* unset_fin_vars */
 
 /* check variable set by expression parser against local financial variables
@@ -152,43 +158,48 @@
  * to reflect the native type of the local variable
  */
 void            chk_vars(
-var_store_ptr   predefined_vars,
-void          **var_array,
-char           *var_type,
-unsigned        var_cnt)
+    var_store_ptr   predefined_vars,
+    void          **var_array,
+    char           *var_type,
+    unsigned        var_cnt)
 {
     unsigned    cntr;
     numeric_ptr value;
 
-    for ( cntr = 0 ; cntr < var_cnt ; cntr++ ) {
-        if ( predefined_vars[cntr].assign_flag == ASSIGNED_TO ) {
+    for ( cntr = 0 ; cntr < var_cnt ; cntr++ )
+    {
+        if ( predefined_vars[cntr].assign_flag == ASSIGNED_TO )
+        {
             predefined_vars[cntr].assign_flag = EOS;
             value = (numeric_ptr)(predefined_vars[cntr].value);
-            switch ( var_type[cntr] ) {
+            switch ( var_type[cntr] )
+            {
+            case INT_TYPE:
+                switch ( value->type )
+                {
                 case INT_TYPE:
-                    switch ( value->type ) {
-                        case INT_TYPE:
-                            *(int *)(var_array[cntr]) = value->value.int_value;
-                            break;
-                        case DBL_TYPE:
-                            value->value.int_value      =
-                              *(int *)(var_array[cntr]) = (unsigned)(value->value.dbl_value);
-                            value->type = INT_TYPE;
-                            break;
-                    } /* endswitch */
+                    *(int *)(var_array[cntr]) = value->value.int_value;
                     break;
                 case DBL_TYPE:
-                    switch ( value->type ) {
-                        case INT_TYPE:
-                            value->value.dbl_value         =
-                              *(double *)(var_array[cntr]) = (double)(value->value.int_value);
-                            value->type = DBL_TYPE;
-                            break;
-                        case DBL_TYPE:
-                            *(double *)(var_array[cntr]) = value->value.dbl_value;
-                            break;
-                    } /* endswitch */
+                    value->value.int_value      =
+                        *(int *)(var_array[cntr]) = (unsigned)(value->value.dbl_value);
+                    value->type = INT_TYPE;
                     break;
+                } /* endswitch */
+                break;
+            case DBL_TYPE:
+                switch ( value->type )
+                {
+                case INT_TYPE:
+                    value->value.dbl_value         =
+                        *(double *)(var_array[cntr]) = (double)(value->value.int_value);
+                    value->type = DBL_TYPE;
+                    break;
+                case DBL_TYPE:
+                    *(double *)(var_array[cntr]) = value->value.dbl_value;
+                    break;
+                } /* endswitch */
+                break;
             } /* endswitch */
         } /* endif */
     } /* endfor */
@@ -201,36 +212,37 @@
                            char *buf_start,
                            char *buf_err)
 {
-	char *err_str;
-	unsigned       bc = (unsigned)(buf_err - buf_start);
-	
-	switch ( error_code ) {
-		case UNBALANCED_PARENS:	
-			err_str = "Unbalanced Parenthesis\n";
-			break;
-		case STACK_OVERFLOW:
-			err_str = "Stack Overflow\n";
-			break;
-		case STACK_UNDERFLOW:
-			err_str = "Stack Underflow\n";
-			break;
-		case UNDEFINED_CHARACTER:
-			err_str = "Unrecognized Character\n";
-			break;
-		case NOT_A_VARIABLE:
-			err_str = "Need a Variable on Left side of assignment operator, '='\n";
-			break;
-                case NOT_A_FUNC:
-                  err_str = "Need a valid Function name.\n";
-                  break;
-          
-	} /* endswitch */
-	printf(err_str);
-	printf("%s\n",buf_start);
-	if ( bc ) for ( bc - 1 ; bc ; bc-- ) printf(" ");
-	printf("^");
-/*	printf("%s\n",buf_err + 1);	*/
-	printf("\n");
+    char *err_str;
+    unsigned       bc = (unsigned)(buf_err - buf_start);
+
+    switch ( error_code )
+    {
+    case UNBALANCED_PARENS:
+        err_str = "Unbalanced Parenthesis\n";
+        break;
+    case STACK_OVERFLOW:
+        err_str = "Stack Overflow\n";
+        break;
+    case STACK_UNDERFLOW:
+        err_str = "Stack Underflow\n";
+        break;
+    case UNDEFINED_CHARACTER:
+        err_str = "Unrecognized Character\n";
+        break;
+    case NOT_A_VARIABLE:
+        err_str = "Need a Variable on Left side of assignment operator, '='\n";
+        break;
+    case NOT_A_FUNC:
+        err_str = "Need a valid Function name.\n";
+        break;
+
+    } /* endswitch */
+    printf(err_str);
+    printf("%s\n", buf_start);
+    if ( bc ) for ( bc - 1 ; bc ; bc-- ) printf(" ");
+    printf("^");
+    /*	printf("%s\n",buf_err + 1);	*/
+    printf("\n");
 } /* parse_error */
 
 int             main(int argc, char **argv, char **env)
@@ -242,32 +254,32 @@
     var_store_ptr   value_list;
     numeric_ptr     nval;
     unsigned        compute,
-                    jj,
-    			    yrE,
-    			    monthE,
-    			    dayE,
-    			    yrI,
-    			    monthI,
-    			    dayI;
+    jj,
+    yrE,
+    monthE,
+    dayE,
+    yrI,
+    monthI,
+    dayI;
     struct tm      *times_E,
-                   *times_I;
-	void           *parse_env;
-	amort_sched     amortsched;
-	financial_info  fininfo;
+                *times_I;
+    void           *parse_env;
+    amort_sched     amortsched;
+    financial_info  fininfo;
 
-	/* check dynamic storage allocation
-	 */
-/*  	mtrace();	*/
-   	set_default(&fininfo);
-   	set_fin_vars();
-   	parse_env = init_parser(predefined_fin_vars,
-   	                        '.',
-   	                        ',',
-   	                        trans_numeric,
-   	                        numeric_ops,
-   	                        negate_numeric,
-   	                        free_numeric);
-   	
+    /* check dynamic storage allocation
+     */
+    /*  	mtrace();	*/
+    set_default(&fininfo);
+    set_fin_vars();
+    parse_env = init_parser(predefined_fin_vars,
+                            '.',
+                            ',',
+                            trans_numeric,
+                            numeric_ops,
+                            negate_numeric,
+                            free_numeric);
+
     npp  = fininfo.npp;
     ir   = fininfo.ir;
     pv   = fininfo.pv;
@@ -280,268 +292,309 @@
 
     fininfo.prec = prec;
 
-   	printf("Single Letter Commands:\na -- amortization schedule\nc -- compute financial variable\nd -- delete variable\ns -- output financial variable status\nq -- quit\nv -- list defined variables\n");
-    for (;;) {
-    	printf("<>");
-    	retcnt = strlen(fgets(buffer,190,stdin));
-    	if ( (retcnt == 2) && (strchr(sl_commands,buffer[0]) != NULL) ) {
-    		if ( buffer[0] == 'q' ) break;
-    		amortsched.prec = fininfo.prec;
-    		switch ( buffer[0] ) {
-    			case 'a':
-    			    if ( amortsched.Eff_Date_jdn && amortsched.Init_Date_jdn ) {
-    			        printf("Current Effective  year: %u\nCurrent Effective month: %u\nCurrent Effective   day: %u\nCurrent Initial    year: %u\nCurrent Initial   month: %u\nCurrent Initial     day %u\n",
-    			                    amortsched.year_E,
-    			                    amortsched.month_E,
-    			                    amortsched.day_E,
-    			                    amortsched.year_I,
-    			                    amortsched.month_I,
-    			                    amortsched.day_I);
-    			        printf("Change dates ? (y/n) ");
-    			        fgets(buffer,190,stdin);
-    			      } else {
-    			        buffer[0] = 'y';
-    			    } /* endif */
-    			    if ( buffer[0] == 'y' ) {
-        				printf("Enter Effective Date - year: ");
-        				fgets(buffer,190,stdin);
-    	    			if ( (errp = parse_string(&value,buffer,parse_env)) == NULL ) {
-    		    			nval = (numeric_ptr)(value.value);
-    			    		switch ( nval->type ) {
-                	    		case INT_TYPE:
-        	        	    		amortsched.year_E = nval->value.int_value;
-            	    		    	break;
-                				case DBL_TYPE:
-                    				amortsched.year_E = (unsigned)(nval->value.dbl_value);
-	                    			break;
-		            		} /* endswitch */
-		            		if ( !value.variable_name ) free_numeric(value.value);
-		       		      } else {
-		       		  	    parse_error(get_parse_error(parse_env),buffer,errp);
-        				} /* endif */
-        				printf("Enter Effective Date - month: ");
-    	    			fgets(buffer,190,stdin);
-    		    		if ( (errp = parse_string(&value,buffer,parse_env)) == NULL ) {
-	    		    		nval = (numeric_ptr)(value.value);
-    				    	switch ( nval->type ) {
-                		    	case INT_TYPE:
-        	        		    	amortsched.month_E = nval->value.int_value;
-            	    			    break;
-                				case DBL_TYPE:
-                    				amortsched.month_E = (unsigned)(nval->value.dbl_value);
-	                    			break;
-		            		} /* endswitch */
-		            		if ( !value.variable_name ) free_numeric(value.value);
-		       		      } else {
-		       		  	    parse_error(get_parse_error(parse_env),buffer,errp);
-        				} /* endif */
-        				printf("Enter Effective Date - day: ");
-    	    			fgets(buffer,190,stdin);
-    		    		if ( (errp = parse_string(&value,buffer,parse_env)) == NULL ) {
-    			    		nval = (numeric_ptr)(value.value);
-    				    	switch ( nval->type ) {
-                		    	case INT_TYPE:
-        	        		    	amortsched.day_E = nval->value.int_value;
-            	    			    break;
-                				case DBL_TYPE:
-                    				amortsched.day_E = (unsigned)(nval->value.dbl_value);
-	                    			break;
-		            		} /* endswitch */
-		            		if ( !value.variable_name ) free_numeric(value.value);
-		       		      } else {
-		       		  	    parse_error(get_parse_error(parse_env),buffer,errp);
-        				} /* endif */
-        				printf("Enter Initial Payment Date - year: ");
-    	    			fgets(buffer,190,stdin);
-    		    		if ( (errp = parse_string(&value,buffer,parse_env)) == NULL ) {
-    			    		nval = (numeric_ptr)(value.value);
-    				    	switch ( nval->type ) {
-                		    	case INT_TYPE:
-        	        		    	amortsched.year_I = nval->value.int_value;
-            	    			    break;
-                				case DBL_TYPE:
-                    				amortsched.year_I = (unsigned)(nval->value.dbl_value);
-	                    			break;
-		            		} /* endswitch */
-		            		if ( !value.variable_name ) free_numeric(value.value);
-		       		      } else {
-		       		  	    parse_error(get_parse_error(parse_env),buffer,errp);
-        				} /* endif */
-        				printf("Enter Initial Payment Date - month: ");
-    	    			fgets(buffer,190,stdin);
-    		    		if ( (errp = parse_string(&value,buffer,parse_env)) == NULL ) {
-    			    		nval = (numeric_ptr)(value.value);
-    				    	switch ( nval->type ) {
-                		    	case INT_TYPE:
-        	        		    	amortsched.month_I = nval->value.int_value;
-            	    			    break;
-                				case DBL_TYPE:
-                    				amortsched.month_I = (unsigned)(nval->value.dbl_value);
-	                    			break;
-		            		} /* endswitch */
-		            		if ( !value.variable_name ) free_numeric(value.value);
-		       		      } else {
-		       		  	    parse_error(get_parse_error(parse_env),buffer,errp);
-        				} /* endif */
-        				printf("Enter Initial Payment Date - day: ");
-    	    			fgets(buffer,190,stdin);
-    		    		if ( (errp = parse_string(&value,buffer,parse_env)) == NULL ) {
-    			    		nval = (numeric_ptr)(value.value);
-    				    	switch ( nval->type ) {
-                		    	case INT_TYPE:
-        	        		    	amortsched.day_I = nval->value.int_value;
-            	    			    break;
-                				case DBL_TYPE:
-                    				amortsched.day_I = (unsigned)(nval->value.dbl_value);
-	                    			break;
-		            		} /* endswitch */
-		            		if ( !value.variable_name ) free_numeric(value.value);
-		       		      } else {
-		       		  	    parse_error(get_parse_error(parse_env),buffer,errp);
-        				} /* endif */
-    				} /* endif */
-    				
-    				amortsched.n     = npp;
-                    amortsched.nint  = ir;
-                    amortsched.pv    = pv;
-                    amortsched.pmt   = pmt;
-                    amortsched.fv    = fv;
-                    amortsched.CF    = CF;
-                    amortsched.PF    = PF;
-                    amortsched.disc  = disc;
-                    amortsched.bep   = bep;
-    				
-     				Amortization_init(&amortsched);
-     				amort_opt(&amortsched,parse_env);
-        			
-			        (void)Amortization_Schedule(&amortsched);
-                    prt_amortization_schedule(&amortsched,stdout);
-                    Amortization_free(&amortsched);
-    				break;
-    			case 'c':
-    				
-	    			printf("Compute:\nn   - 1\ni   - 2\npv  - 3\npmt - 4\nfv  - 5\n1, 2, 3, 4 or 5: ");
-					retcnt = strlen(fgets(buffer,190,stdin));
-					compute = buffer[0] - '0';
-	
-	    			switch ( compute-- ) {
-    	    			case 0: /* all values specified nothing to compute */
-        	    			break;
-	        			case 1: /* compute number of periods, npp */
-    	        			printf("Computing numbor of periods\n");
-        	    			npp = fi_calc_num_payments(&fininfo);
-        	    			printf("Number of Periods: %u\n",npp);
-        	    			nval = (numeric_ptr)(predefined_fin_vars[compute].value);
-        	    			nval->value.int_value = npp;
-            				break;
-	       				case 2: /* compute interest, ir */
-    	        			printf("Computing interest rate\n");
-        	    			ir = fi_calc_interest(&fininfo);
-        	    			printf("Nominal Interest Rate: %.*f\n",prec,ir);
-        	    			nval = (numeric_ptr)(predefined_fin_vars[compute].value);
-        	    			nval->value.dbl_value = ir;
-            				break;
-	        			case 3: /* compute present value, pv */
-    	        			printf("Computing Present Value\n");
-        	    			pv = fi_calc_present_value(&fininfo);
-        	    			printf("Present Value: %.*f\n",prec,pv);
-        	    			nval = (numeric_ptr)(predefined_fin_vars[compute].value);
-        	    			nval->value.dbl_value = pv;
-            				break;
-	        			case 4: /* compute periodic payment, pmt */
-    	        			printf("Computing periodic payment\n");
-        	    			pmt = fi_calc_payment(&fininfo);
-        	    			printf("Periodic Payment: %.*f\n",prec,pmt);
-        	    			nval = (numeric_ptr)(predefined_fin_vars[compute].value);
-        	    			nval->value.dbl_value = pmt;
-            				break;
-	        			case 5: /* compute future value, fv */
-    	        			printf("Computing Future Value\n");
-        	    			fv = fi_calc_future_value(&fininfo);
-        	    			printf("Future Value: %.*f\n",prec,fv);
-        	    			nval = (numeric_ptr)(predefined_fin_vars[compute].value);
-        	    			nval->value.dbl_value = fv;
-            				break;
-	        			default:    /* whoops */
-    	        			break;
-	    			} /* endswitch */
-    				break;
-    	        case 'd':
-    	            printf("Enter name of variable to delete: ");
-    	            retcnt = strlen(fgets(buffer,190,stdin));
-    	            buffer[retcnt - 1] = EOS;
-    	            if ( !delete_var(buffer,parse_env) ) {
-    	                printf("Unable to delete specified variable\n");
-    	            } /* endif */
-    	            break;
-    			case 's':
-    				prt_status(&fininfo,
-			        	        stdout);
-    				break;
-    			case 'v':
-    			    for ( value_list = parser_get_vars(parse_env) ; value_list ; value_list = value_list->next_var ) {
-    			        printf("%s: ",value_list->variable_name);
-    			        nval = (numeric_ptr)(value_list->value);
-    			        switch ( nval->type ) {
-    			            case INT_TYPE:
-            			        printf("%i\n",nval->value.int_value);
-            			        break;
-            			    case DBL_TYPE:
-            			        printf("%.*f\n",prec,nval->value.dbl_value);
-            			        break;
-    			        } /* endswitch */
-    			    } /* endfor */
-    			    break;
-    		} /* endswitch */
-    	  } else if ( retcnt > 1 ) {
-    		buffer[retcnt - 1] = EOS;
-			 		
-	        if ( (errp = parse_string(&value,buffer,parse_env)) == NULL ) {
-	            if ( value.variable_name ) printf("Variable: %s\n",value.variable_name);
-	            nval = (numeric_ptr)(value.value);
-    	  		switch ( nval->type ) {
-        	 		case INT_TYPE:
-                		printf("Evaluated Value: %i\n",nval->value.int_value);
-	                 	break;
-	    	     	case DBL_TYPE:
-						printf("Evaluated Value: %.*f\n",prec,nval->value.dbl_value);
-	    	 	        break;
-		        } /* endswitch */
-		        if ( !value.variable_name ) free_numeric(value.value);
-		        chk_vars(predefined_fin_vars,fin_vars,fin_type,PREDEFINED_FIN_VARS);
-		        fininfo.npp = npp;
-		        fininfo.ir = ir;
-		        fininfo.pv = pv;
-		        fininfo.pmt = pmt;
-		        fininfo.fv = fv;
-		        fininfo.CF = CF;
-		        fininfo.PF = PF;
-		        fininfo.disc = disc;
-		        fininfo.bep = bep;
-			  } else {
-				parse_error(get_parse_error(parse_env),buffer,errp);     	
-		    } /* endif */
-    	} /* endif */
-	} /* endfor */
-	exit_parser(parse_env);
-	unset_fin_vars();
+    printf("Single Letter Commands:\na -- amortization schedule\nc -- compute financial variable\nd -- delete variable\ns -- output financial variable status\nq -- quit\nv -- list defined variables\n");
+    for (;;)
+{
+        printf("<>");
+        retcnt = strlen(fgets(buffer, 190, stdin));
+        if ( (retcnt == 2) && (strchr(sl_commands, buffer[0]) != NULL) )
+        {
+            if ( buffer[0] == 'q' ) break;
+            amortsched.prec = fininfo.prec;
+            switch ( buffer[0] )
+            {
+            case 'a':
+                if ( amortsched.Eff_Date_jdn && amortsched.Init_Date_jdn )
+                {
+                    printf("Current Effective  year: %u\nCurrent Effective month: %u\nCurrent Effective   day: %u\nCurrent Initial    year: %u\nCurrent Initial   month: %u\nCurrent Initial     day %u\n",
+                           amortsched.year_E,
+                           amortsched.month_E,
+                           amortsched.day_E,
+                           amortsched.year_I,
+                           amortsched.month_I,
+                           amortsched.day_I);
+                    printf("Change dates ? (y/n) ");
+                    fgets(buffer, 190, stdin);
+                }
+                else
+                {
+                    buffer[0] = 'y';
+                } /* endif */
+                if ( buffer[0] == 'y' )
+                {
+                    printf("Enter Effective Date - year: ");
+                    fgets(buffer, 190, stdin);
+                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
+                    {
+                        nval = (numeric_ptr)(value.value);
+                        switch ( nval->type )
+                        {
+                        case INT_TYPE:
+                            amortsched.year_E = nval->value.int_value;
+                            break;
+                        case DBL_TYPE:
+                            amortsched.year_E = (unsigned)(nval->value.dbl_value);
+                            break;
+                        } /* endswitch */
+                        if ( !value.variable_name ) free_numeric(value.value);
+                    }
+                    else
+                    {
+                        parse_error(get_parse_error(parse_env), buffer, errp);
+                    } /* endif */
+                    printf("Enter Effective Date - month: ");
+                    fgets(buffer, 190, stdin);
+                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
+                    {
+                        nval = (numeric_ptr)(value.value);
+                        switch ( nval->type )
+                        {
+                        case INT_TYPE:
+                            amortsched.month_E = nval->value.int_value;
+                            break;
+                        case DBL_TYPE:
+                            amortsched.month_E = (unsigned)(nval->value.dbl_value);
+                            break;
+                        } /* endswitch */
+                        if ( !value.variable_name ) free_numeric(value.value);
+                    }
+                    else
+                    {
+                        parse_error(get_parse_error(parse_env), buffer, errp);
+                    } /* endif */
+                    printf("Enter Effective Date - day: ");
+                    fgets(buffer, 190, stdin);
+                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
+                    {
+                        nval = (numeric_ptr)(value.value);
+                        switch ( nval->type )
+                        {
+                        case INT_TYPE:
+                            amortsched.day_E = nval->value.int_value;
+                            break;
+                        case DBL_TYPE:
+                            amortsched.day_E = (unsigned)(nval->value.dbl_value);
+                            break;
+                        } /* endswitch */
+                        if ( !value.variable_name ) free_numeric(value.value);
+                    }
+                    else
+                    {
+                        parse_error(get_parse_error(parse_env), buffer, errp);
+                    } /* endif */
+                    printf("Enter Initial Payment Date - year: ");
+                    fgets(buffer, 190, stdin);
+                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
+                    {
+                        nval = (numeric_ptr)(value.value);
+                        switch ( nval->type )
+                        {
+                        case INT_TYPE:
+                            amortsched.year_I = nval->value.int_value;
+                            break;
+                        case DBL_TYPE:
+                            amortsched.year_I = (unsigned)(nval->value.dbl_value);
+                            break;
+                        } /* endswitch */
+                        if ( !value.variable_name ) free_numeric(value.value);
+                    }
+                    else
+                    {
+                        parse_error(get_parse_error(parse_env), buffer, errp);
+                    } /* endif */
+                    printf("Enter Initial Payment Date - month: ");
+                    fgets(buffer, 190, stdin);
+                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
+                    {
+                        nval = (numeric_ptr)(value.value);
+                        switch ( nval->type )
+                        {
+                        case INT_TYPE:
+                            amortsched.month_I = nval->value.int_value;
+                            break;
+                        case DBL_TYPE:
+                            amortsched.month_I = (unsigned)(nval->value.dbl_value);
+                            break;
+                        } /* endswitch */
+                        if ( !value.variable_name ) free_numeric(value.value);
+                    }
+                    else
+                    {
+                        parse_error(get_parse_error(parse_env), buffer, errp);
+                    } /* endif */
+                    printf("Enter Initial Payment Date - day: ");
+                    fgets(buffer, 190, stdin);
+                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
+                    {
+                        nval = (numeric_ptr)(value.value);
+                        switch ( nval->type )
+                        {
+                        case INT_TYPE:
+                            amortsched.day_I = nval->value.int_value;
+                            break;
+                        case DBL_TYPE:
+                            amortsched.day_I = (unsigned)(nval->value.dbl_value);
+                            break;
+                        } /* endswitch */
+                        if ( !value.variable_name ) free_numeric(value.value);
+                    }
+                    else
+                    {
+                        parse_error(get_parse_error(parse_env), buffer, errp);
+                    } /* endif */
+                } /* endif */
+
+                amortsched.n     = npp;
+                amortsched.nint  = ir;
+                amortsched.pv    = pv;
+                amortsched.pmt   = pmt;
+                amortsched.fv    = fv;
+                amortsched.CF    = CF;
+                amortsched.PF    = PF;
+                amortsched.disc  = disc;
+                amortsched.bep   = bep;
+
+                Amortization_init(&amortsched);
+                amort_opt(&amortsched, parse_env);
+
+                (void)Amortization_Schedule(&amortsched);
+                prt_amortization_schedule(&amortsched, stdout);
+                Amortization_free(&amortsched);
+                break;
+            case 'c':
+
+                printf("Compute:\nn   - 1\ni   - 2\npv  - 3\npmt - 4\nfv  - 5\n1, 2, 3, 4 or 5: ");
+                retcnt = strlen(fgets(buffer, 190, stdin));
+                compute = buffer[0] - '0';
+
+                switch ( compute-- )
+                {
+                case 0: /* all values specified nothing to compute */
+                    break;
+                case 1: /* compute number of periods, npp */
+                    printf("Computing numbor of periods\n");
+                    npp = fi_calc_num_payments(&fininfo);
+                    printf("Number of Periods: %u\n", npp);
+                    nval = (numeric_ptr)(predefined_fin_vars[compute].value);
+                    nval->value.int_value = npp;
+                    break;
+                case 2: /* compute interest, ir */
+                    printf("Computing interest rate\n");
+                    ir = fi_calc_interest(&fininfo);
+                    printf("Nominal Interest Rate: %.*f\n", prec, ir);
+                    nval = (numeric_ptr)(predefined_fin_vars[compute].value);
+                    nval->value.dbl_value = ir;
+                    break;
+                case 3: /* compute present value, pv */
+                    printf("Computing Present Value\n");
+                    pv = fi_calc_present_value(&fininfo);
+                    printf("Present Value: %.*f\n", prec, pv);
+                    nval = (numeric_ptr)(predefined_fin_vars[compute].value);
+                    nval->value.dbl_value = pv;
+                    break;
+                case 4: /* compute periodic payment, pmt */
+                    printf("Computing periodic payment\n");
+                    pmt = fi_calc_payment(&fininfo);
+                    printf("Periodic Payment: %.*f\n", prec, pmt);
+                    nval = (numeric_ptr)(predefined_fin_vars[compute].value);
+                    nval->value.dbl_value = pmt;
+                    break;
+                case 5: /* compute future value, fv */
+                    printf("Computing Future Value\n");
+                    fv = fi_calc_future_value(&fininfo);
+                    printf("Future Value: %.*f\n", prec, fv);
+                    nval = (numeric_ptr)(predefined_fin_vars[compute].value);
+                    nval->value.dbl_value = fv;
+                    break;
+                default:    /* whoops */
+                    break;
+                } /* endswitch */
+                break;
+            case 'd':
+                printf("Enter name of variable to delete: ");
+                retcnt = strlen(fgets(buffer, 190, stdin));
+                buffer[retcnt - 1] = EOS;
+                if ( !delete_var(buffer, parse_env) )
+                {
+                    printf("Unable to delete specified variable\n");
+                } /* endif */
+                break;
+            case 's':
+                prt_status(&fininfo,
+                           stdout);
+                break;
+            case 'v':
+                for ( value_list = parser_get_vars(parse_env) ; value_list ; value_list = value_list->next_var )
+                {
+                    printf("%s: ", value_list->variable_name);
+                    nval = (numeric_ptr)(value_list->value);
+                    switch ( nval->type )
+                    {
+                    case INT_TYPE:
+                        printf("%i\n", nval->value.int_value);
+                        break;
+                    case DBL_TYPE:
+                        printf("%.*f\n", prec, nval->value.dbl_value);
+                        break;
+                    } /* endswitch */
+                } /* endfor */
+                break;
+            } /* endswitch */
+        }
+        else if ( retcnt > 1 )
+        {
+            buffer[retcnt - 1] = EOS;
+
+            if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
+            {
+                if ( value.variable_name ) printf("Variable: %s\n", value.variable_name);
+                nval = (numeric_ptr)(value.value);
+                switch ( nval->type )
+                {
+                case INT_TYPE:
+                    printf("Evaluated Value: %i\n", nval->value.int_value);
+                    break;
+                case DBL_TYPE:
+                    printf("Evaluated Value: %.*f\n", prec, nval->value.dbl_value);
+                    break;
+                } /* endswitch */
+                if ( !value.variable_name ) free_numeric(value.value);
+                chk_vars(predefined_fin_vars, fin_vars, fin_type, PREDEFINED_FIN_VARS);
+                fininfo.npp = npp;
+                fininfo.ir = ir;
+                fininfo.pv = pv;
+                fininfo.pmt = pmt;
+                fininfo.fv = fv;
+                fininfo.CF = CF;
+                fininfo.PF = PF;
+                fininfo.disc = disc;
+                fininfo.bep = bep;
+            }
+            else
+            {
+                parse_error(get_parse_error(parse_env), buffer, errp);
+            } /* endif */
+        } /* endif */
+    } /* endfor */
+    exit_parser(parse_env);
+    unset_fin_vars();
 } /* main */
 
 static void  prt_status(
-fi_ptr       fi,
-FILE        *ofile)
+    fi_ptr       fi,
+    FILE        *ofile)
 {
     fprintf(ofile, "<================================>\nCurrent Financial Calculator Status:\n");
-    fprintf(ofile, "Compounding Frequency: (CF) %u\n",fi->CF);
-    fprintf(ofile, "Payment     Frequency: (PF) %u\n",fi->PF);
-    fprintf(ofile, "Compounding: %s\n",fi->disc ? "Discrete (disc = TRUE)" : "Continuous (disc = FALSE)");
-    fprintf(ofile, "Payments: %s\n",fi->bep ? "Beginning of Period (bep = TRUE)" : "End of Period (bep = FALSE)");
-    if ( fi->npp > 12 ) fprintf(ofile, "Number of Payment Periods (n): %u\t\t(Years: %u)\n",fi->npp,fi->npp/fi->PF);
-      else fprintf(ofile, "Number of Payment Periods (n): %u\n",fi->npp);
-    if ((fi->CF == 1) && (fi->PF == 1) ) fprintf(ofile, "Nominal Interest per Payment Period (i): %f\t(Annualized: %.*f\n",fi->ir,fi->prec,fi->ir * 12);
-      else fprintf(ofile, "Nominal Annual Interest Rate (i): %.*f\n",fi->prec,fi->ir);
-/*    fprintf(ofile, "  Effective Interest Rate Per Payment Period: %f\n",eff_int(nint/100.0,CF,PF));   */
-    fprintf(ofile, "Present Value (pv): %.*f\n",fi->prec,fi->pv);
-    fprintf(ofile, "Periodic Payment (pmt): %.*f\n",fi->prec,fi->pmt);
-    fprintf(ofile, "Future Value (fv): %.*f\n<================================>\n",fi->prec,fi->fv);
+    fprintf(ofile, "Compounding Frequency: (CF) %u\n", fi->CF);
+    fprintf(ofile, "Payment     Frequency: (PF) %u\n", fi->PF);
+    fprintf(ofile, "Compounding: %s\n", fi->disc ? "Discrete (disc = TRUE)" : "Continuous (disc = FALSE)");
+    fprintf(ofile, "Payments: %s\n", fi->bep ? "Beginning of Period (bep = TRUE)" : "End of Period (bep = FALSE)");
+    if ( fi->npp > 12 ) fprintf(ofile, "Number of Payment Periods (n): %u\t\t(Years: %u)\n", fi->npp, fi->npp / fi->PF);
+    else fprintf(ofile, "Number of Payment Periods (n): %u\n", fi->npp);
+    if ((fi->CF == 1) && (fi->PF == 1) ) fprintf(ofile, "Nominal Interest per Payment Period (i): %f\t(Annualized: %.*f\n", fi->ir, fi->prec, fi->ir * 12);
+    else fprintf(ofile, "Nominal Annual Interest Rate (i): %.*f\n", fi->prec, fi->ir);
+    /*    fprintf(ofile, "  Effective Interest Rate Per Payment Period: %f\n",eff_int(nint/100.0,CF,PF));   */
+    fprintf(ofile, "Present Value (pv): %.*f\n", fi->prec, fi->pv);
+    fprintf(ofile, "Periodic Payment (pmt): %.*f\n", fi->prec, fi->pmt);
+    fprintf(ofile, "Future Value (fv): %.*f\n<================================>\n", fi->prec, fi->fv);
 }   /* prt_status */

Modified: gnucash/trunk/src/calculation/fin-main.c
===================================================================
--- gnucash/trunk/src/calculation/fin-main.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/fin-main.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -27,13 +27,13 @@
 #include "finproto.h"
 
 static void  prt_status(
-fi_ptr       fi,
-FILE        *ofile);
+    fi_ptr       fi,
+    FILE        *ofile);
 
 int             main(int argc, char **argv, char **env)
 {
-	financial_info  fininfo;
-	amort_sched     amortsched;
+    financial_info  fininfo;
+    amort_sched     amortsched;
 
     set_default(&fininfo);
     fininfo.prec = 2;
@@ -43,7 +43,7 @@
     fininfo.pv = 345725.0;
 
     (void)fi_calc_payment(&fininfo);
-    printf("With npp == %u\n     ir == %.*f\n     pv == %.*f\n",fininfo.npp,fininfo.prec,fininfo.ir,fininfo.prec,fininfo.pv);
+    printf("With npp == %u\n     ir == %.*f\n     pv == %.*f\n", fininfo.npp, fininfo.prec, fininfo.ir, fininfo.prec, fininfo.pv);
     printf("------------>Compute pmt: -2597.32\n");
     prt_status(&fininfo,
                stdout);
@@ -77,84 +77,84 @@
     amortsched.nint = fininfo.ir;
     amortsched.pv = fininfo.pv;
     amortsched.pmt = fininfo.pmt;
-	amortsched.fv = fininfo.fv;
-	amortsched.CF = fininfo.CF;
-	amortsched.PF = fininfo.PF;
-	amortsched.disc = fininfo.disc;
-	amortsched.bep = fininfo.bep;
-	amortsched.prec = fininfo.prec;
-	amortsched.year_E = 1999;
-	amortsched.month_E = 6;
-	amortsched.day_E = 15;
-	amortsched.year_I = 1999;
-	amortsched.month_I = 8;
-	amortsched.day_I = 1;
-	amortsched.fixed_pmt = -400;
-	
+    amortsched.fv = fininfo.fv;
+    amortsched.CF = fininfo.CF;
+    amortsched.PF = fininfo.PF;
+    amortsched.disc = fininfo.disc;
+    amortsched.bep = fininfo.bep;
+    amortsched.prec = fininfo.prec;
+    amortsched.year_E = 1999;
+    amortsched.month_E = 6;
+    amortsched.day_E = 15;
+    amortsched.year_I = 1999;
+    amortsched.month_I = 8;
+    amortsched.day_I = 1;
+    amortsched.fixed_pmt = -400;
+
     (void)Amortization_init(&amortsched);
 
     amortsched.option = 3;
     amortsched.summary = 'y';
     (void)Amortization_Schedule(&amortsched);
-    prt_amortization_schedule(&amortsched,stdout);
+    prt_amortization_schedule(&amortsched, stdout);
 
     printf("\n\nSecond Schedule - ignore delay in first payment and\noutput schedule for each payment\n");
-	amortsched.summary = 'p';
+    amortsched.summary = 'p';
     (void)Amortization_Schedule(&amortsched);
-	prt_amortization_schedule(&amortsched,stdout);
+    prt_amortization_schedule(&amortsched, stdout);
 
 
     printf("\n\nThird Schedule - ignore delay in first payment and\noutput variable advanced prepayment schedule\n");
-	amortsched.summary = 'a';
+    amortsched.summary = 'a';
     (void)Amortization_Schedule(&amortsched);
-    prt_amortization_schedule(&amortsched,stdout);
+    prt_amortization_schedule(&amortsched, stdout);
 
     printf("\n\nFourth Schedule - ignore delay in first payment and\noutput fixed prepayment schedule\n");
-	amortsched.summary = 'f';
+    amortsched.summary = 'f';
     (void)Amortization_Schedule(&amortsched);
-    prt_amortization_schedule(&amortsched,stdout);
+    prt_amortization_schedule(&amortsched, stdout);
 
     printf("\n\nFifth Schedule - use new payments due to delay and\noutput annual summary\n");
     amortsched.option = 5;
-	amortsched.summary = 'y';
+    amortsched.summary = 'y';
     (void)Amortization_Schedule(&amortsched);
-    prt_amortization_schedule(&amortsched,stdout);
+    prt_amortization_schedule(&amortsched, stdout);
 
     printf("\n\nSixth Schedule - use new payments due to delay and\noutput periodic payment schedule\n");
     amortsched.option = 5;
-    amortsched.summary = 'p';	
+    amortsched.summary = 'p';
     (void)Amortization_Schedule(&amortsched);
-    prt_amortization_schedule(&amortsched,stdout);
+    prt_amortization_schedule(&amortsched, stdout);
 
     printf("\n\nSeventh Schedule - use new payments due to delay and\noutput variable prepayment schedule\n");
     amortsched.option = 5;
     amortsched.summary = 'a';
     (void)Amortization_Schedule(&amortsched);
-    prt_amortization_schedule(&amortsched,stdout);
-	
+    prt_amortization_schedule(&amortsched, stdout);
+
     printf("\n\nEighth Schedule - use new payments due to delay and\noutput fixed prepayment schedule\n");
     amortsched.option = 5;
     amortsched.summary = 'f';
     (void)Amortization_Schedule(&amortsched);
-    prt_amortization_schedule(&amortsched,stdout);
+    prt_amortization_schedule(&amortsched, stdout);
     Amortization_free(&amortsched);
 } /* main */
 
 static void  prt_status(
-fi_ptr       fi,
-FILE        *ofile)
+    fi_ptr       fi,
+    FILE        *ofile)
 {
     fprintf(ofile, "<================================>\nCurrent Financial Calculator Status:\n");
-    fprintf(ofile, "Compounding Frequency: (CF) %u\n",fi->CF);
-    fprintf(ofile, "Payment     Frequency: (PF) %u\n",fi->PF);
-    fprintf(ofile, "Compounding: %s\n",fi->disc ? "Discrete (disc = TRUE)" : "Continuous (disc = FALSE)");
-    fprintf(ofile, "Payments: %s\n",fi->bep ? "Beginning of Period (bep = TRUE)" : "End of Period (bep = FALSE)");
-    if ( fi->npp > 12 ) fprintf(ofile, "Number of Payment Periods (n): %u\t\t(Years: %u)\n",fi->npp,fi->npp/fi->PF);
-      else fprintf(ofile, "Number of Payment Periods (n): %u\n",fi->npp);
-    if ((fi->CF == 1) && (fi->PF == 1) ) fprintf(ofile, "Nominal Interest per Payment Period (i): %f\t(Annualized: %.*f\n",fi->ir,fi->prec,fi->ir * 12);
-      else fprintf(ofile, "Nominal Annual Interest Rate (i): %.*f\n",fi->prec,fi->ir);
-/*    fprintf(ofile, "  Effective Interest Rate Per Payment Period: %f\n",eff_int(nint/100.0,CF,PF));   */
-    fprintf(ofile, "Present Value (pv): %.*f\n",fi->prec,fi->pv);
-    fprintf(ofile, "Periodic Payment (pmt): %.*f\n",fi->prec,fi->pmt);
-    fprintf(ofile, "Future Value (fv): %.*f\n",fi->prec,fi->fv);
+    fprintf(ofile, "Compounding Frequency: (CF) %u\n", fi->CF);
+    fprintf(ofile, "Payment     Frequency: (PF) %u\n", fi->PF);
+    fprintf(ofile, "Compounding: %s\n", fi->disc ? "Discrete (disc = TRUE)" : "Continuous (disc = FALSE)");
+    fprintf(ofile, "Payments: %s\n", fi->bep ? "Beginning of Period (bep = TRUE)" : "End of Period (bep = FALSE)");
+    if ( fi->npp > 12 ) fprintf(ofile, "Number of Payment Periods (n): %u\t\t(Years: %u)\n", fi->npp, fi->npp / fi->PF);
+    else fprintf(ofile, "Number of Payment Periods (n): %u\n", fi->npp);
+    if ((fi->CF == 1) && (fi->PF == 1) ) fprintf(ofile, "Nominal Interest per Payment Period (i): %f\t(Annualized: %.*f\n", fi->ir, fi->prec, fi->ir * 12);
+    else fprintf(ofile, "Nominal Annual Interest Rate (i): %.*f\n", fi->prec, fi->ir);
+    /*    fprintf(ofile, "  Effective Interest Rate Per Payment Period: %f\n",eff_int(nint/100.0,CF,PF));   */
+    fprintf(ofile, "Present Value (pv): %.*f\n", fi->prec, fi->pv);
+    fprintf(ofile, "Periodic Payment (pmt): %.*f\n", fi->prec, fi->pmt);
+    fprintf(ofile, "Future Value (fv): %.*f\n", fi->prec, fi->fv);
 }   /* prt_status */

Modified: gnucash/trunk/src/calculation/fin.c
===================================================================
--- gnucash/trunk/src/calculation/fin.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/fin.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -1214,18 +1214,18 @@
 static double
 rnd (double x, unsigned places)
 {
-  double r;
-  char buf[50];			/* make buffer large enough */
+    double r;
+    char buf[50];			/* make buffer large enough */
 
-  if (places >= 0)
-  {
-    sprintf (buf, "%.*f", (int) places, x);
-    r = strtod(buf, NULL);
-  }
-  else
-    r = x;
+    if (places >= 0)
+    {
+        sprintf (buf, "%.*f", (int) places, x);
+        r = strtod(buf, NULL);
+    }
+    else
+        r = x;
 
-  return r;
+    return r;
 }				/* rnd */
 
 /* return absolute value of 'x' this function is provided by a macro
@@ -1233,43 +1233,43 @@
 static double
 dabs (double x)
 {
-  return (x >= 0.0) ? x : -x;
+    return (x >= 0.0) ? x : -x;
 }				/* dabs */
 
 /* Compute constant used in calculations */
 static double
 _A (double eint, unsigned per)
 {
-  return pow ((1.0 + eint), (double) per) - 1.0;
+    return pow ((1.0 + eint), (double) per) - 1.0;
 }				/* _A */
 
 /* Compute constant used in calculations */
 static double
 _B (double eint, unsigned beg)
 {
-  /* if eint == 0.0, all processing _must_ stop or 
-	a recursive loop will start. */
-  g_return_val_if_fail(eint != 0.0, 0.0); 
-  return (1.0 + eint * (double) beg) / eint;
+    /* if eint == 0.0, all processing _must_ stop or
+      a recursive loop will start. */
+    g_return_val_if_fail(eint != 0.0, 0.0);
+    return (1.0 + eint * (double) beg) / eint;
 }				/* _B */
 
 /* Compute constant used in calculations */
 static double
 _C (double eint, double pmt, unsigned beg)
 {
-  g_return_val_if_fail(eint != 0.0, 0.0);
-  return pmt * _B(eint, beg);
+    g_return_val_if_fail(eint != 0.0, 0.0);
+    return pmt * _B(eint, beg);
 }				/* _C */
 
 /* compute Number of Periods from preset data */
 unsigned
 fi_calc_num_payments (fi_ptr fi)
 {
-  return fi->npp =
-    (unsigned)
-    rnd (_fi_calc_num_payments
-	 (fi->ir, fi->pv, fi->pmt, fi->fv, fi->CF, fi->PF, fi->disc, fi->bep),
-	 0);
+    return fi->npp =
+               (unsigned)
+               rnd (_fi_calc_num_payments
+                    (fi->ir, fi->pv, fi->pmt, fi->fv, fi->CF, fi->PF, fi->disc, fi->bep),
+                    0);
 }				/* fi_calc_num_payments */
 
 /* Compute number of periods from:
@@ -1280,29 +1280,29 @@
  */
 double
 _fi_calc_num_payments (double nint,	/* nominal interest rate    */
-		       double pv,	/* present value            */
-		       double pmt,	/* periodic payment         */
-		       double fv,	/* future value             */
-		       unsigned CF,	/* compounding frequency    */
-		       unsigned PF,	/* payment frequency        */
-		       unsigned disc,	/* discrete/continuous compounding */
-		       unsigned bep)	/* beginning/end of period payment */
+                       double pv,	/* present value            */
+                       double pmt,	/* periodic payment         */
+                       double fv,	/* future value             */
+                       unsigned CF,	/* compounding frequency    */
+                       unsigned PF,	/* payment frequency        */
+                       unsigned disc,	/* discrete/continuous compounding */
+                       unsigned bep)	/* beginning/end of period payment */
 {
-  double eint = eff_int (nint / 100.0, CF, PF, disc);
-  double CC = _C (eint, pmt, bep);
-  CC = (CC - fv) / (CC + pv);
-  return (CC > 0.0) ? log (CC) / log (1.0 + eint) : 0.0;
+    double eint = eff_int (nint / 100.0, CF, PF, disc);
+    double CC = _C (eint, pmt, bep);
+    CC = (CC - fv) / (CC + pv);
+    return (CC > 0.0) ? log (CC) / log (1.0 + eint) : 0.0;
 }				/* _fi_calc_num_payments */
 
 /* compute Interest from preset data */
 double
 fi_calc_interest (fi_ptr fi)
 {
-  if (fi->npp)
-    fi->ir = _fi_calc_interest (fi->npp, fi->pv, fi->pmt, fi->fv,
-				fi->CF, fi->PF, fi->disc, fi->bep);
+    if (fi->npp)
+        fi->ir = _fi_calc_interest (fi->npp, fi->pv, fi->pmt, fi->fv,
+                                    fi->CF, fi->PF, fi->disc, fi->bep);
 
-  return fi->ir;
+    return fi->ir;
 }				/* fi_calc_interest */
 
 double ratio = 1e4; /* ratio used in iterative solution for interest */
@@ -1315,68 +1315,68 @@
  */
 double
 _fi_calc_interest (unsigned per,/* number of periods        */
-		   double pv,	/* present value            */
-		   double pmt,	/* periodic payment         */
-		   double fv,	/* future value             */
-		   unsigned CF,	/* compounding frequency    */
-		   unsigned PF,	/* payment frequency        */
-		   unsigned disc, /* discrete/continuous compounding */
-		   unsigned bep)  /* beginning/end of period payment */
+                   double pv,	/* present value            */
+                   double pmt,	/* periodic payment         */
+                   double fv,	/* future value             */
+                   unsigned CF,	/* compounding frequency    */
+                   unsigned PF,	/* payment frequency        */
+                   unsigned disc, /* discrete/continuous compounding */
+                   unsigned bep)  /* beginning/end of period payment */
 {
-  double eint;
-  double a, dik;
-  int ri;
+    double eint;
+    double a, dik;
+    int ri;
 
-  if (pmt == 0.0)
-    eint = pow ((dabs (fv) / dabs (pv)), (1.0 / (double) per)) - 1.0;
-  else
-  {
-    if ((pmt * fv) < 0.0)
-    {
-      if (pv)
-	a = -1.0;
-      else
-	a = 1.0;
-      eint =
-	dabs ((fv + a * (double) per * pmt) /
-	      (3.0 *
-	       (((double) per - 1.0) * ((double) per - 1.0) * pmt + pv -
-		fv)));
-    }
+    if (pmt == 0.0)
+        eint = pow ((dabs (fv) / dabs (pv)), (1.0 / (double) per)) - 1.0;
     else
     {
-      if ((pv * pmt) < 0.0)
-      {
-	eint = dabs (((double) per * pmt + pv + fv) / ((double) per * pv));
-      }
-      else
-      {
-	a = dabs (pmt / (dabs (pv) + dabs (fv)));
-	eint = a + 1.0 / (a * (double) per * (double) per * (double) per);
-      }
-    }
-    do
-    {
-      dik =
-	fi (per, eint, pv, pmt, fv, bep) / fip (per, eint, pv, pmt, fv, bep);
-      eint -= dik;
-      (void) modf (ratio * (dik / eint), &a);
-      ri = (unsigned) a;
-    }
-    while (ri);
-  }				/* endif */
+        if ((pmt * fv) < 0.0)
+        {
+            if (pv)
+                a = -1.0;
+            else
+                a = 1.0;
+            eint =
+                dabs ((fv + a * (double) per * pmt) /
+                      (3.0 *
+                       (((double) per - 1.0) * ((double) per - 1.0) * pmt + pv -
+                        fv)));
+        }
+        else
+        {
+            if ((pv * pmt) < 0.0)
+            {
+                eint = dabs (((double) per * pmt + pv + fv) / ((double) per * pv));
+            }
+            else
+            {
+                a = dabs (pmt / (dabs (pv) + dabs (fv)));
+                eint = a + 1.0 / (a * (double) per * (double) per * (double) per);
+            }
+        }
+        do
+        {
+            dik =
+                fi (per, eint, pv, pmt, fv, bep) / fip (per, eint, pv, pmt, fv, bep);
+            eint -= dik;
+            (void) modf (ratio * (dik / eint), &a);
+            ri = (unsigned) a;
+        }
+        while (ri);
+    }				/* endif */
 
-  return 100.0 * nom_int (eint, CF, PF, disc);
+    return 100.0 * nom_int (eint, CF, PF, disc);
 }				/* _fi_calc_interest */
 
 /* compute Present value from preset data */
 double
 fi_calc_present_value (fi_ptr fi)
 {
-  return fi->pv =
-    rnd (_fi_calc_present_value
-	 (fi->npp, fi->ir, fi->pmt, fi->fv, fi->CF, fi->PF, fi->disc,
-	  fi->bep), fi->prec);
+    return fi->pv =
+               rnd (_fi_calc_present_value
+                    (fi->npp, fi->ir, fi->pmt, fi->fv, fi->CF, fi->PF, fi->disc,
+                     fi->bep), fi->prec);
 }				/* fi_calc_present_value */
 
 /* Compute Present Value from:
@@ -1387,29 +1387,29 @@
  */
 double
 _fi_calc_present_value (unsigned per,	/* number of periods        */
-			double nint,	/* nominal interest rate    */
-			double pmt,	/* periodic payment         */
-			double fv,	/* future value             */
-			unsigned CF,	/* compounding frequency    */
-			unsigned PF,	/* payment frequency        */
-			unsigned disc,	/* discrete/continuous compounding */
-			unsigned bep)	/* beginning/end of period payment */
+                        double nint,	/* nominal interest rate    */
+                        double pmt,	/* periodic payment         */
+                        double fv,	/* future value             */
+                        unsigned CF,	/* compounding frequency    */
+                        unsigned PF,	/* payment frequency        */
+                        unsigned disc,	/* discrete/continuous compounding */
+                        unsigned bep)	/* beginning/end of period payment */
 {
-  double eint = eff_int (nint / 100.0, CF, PF, disc);
-  double AA = _A (eint, per);
-  double CC = _C (eint, pmt, bep);
+    double eint = eff_int (nint / 100.0, CF, PF, disc);
+    double AA = _A (eint, per);
+    double CC = _C (eint, pmt, bep);
 
-  return -(fv + (AA * CC)) / (AA + 1.0);
+    return -(fv + (AA * CC)) / (AA + 1.0);
 }				/* _fi_calc_present_value */
 
 /* compute Periodic Payment from preset data */
 double
 fi_calc_payment (fi_ptr fi)
 {
-  return fi->pmt =
-    rnd (_fi_calc_payment
-	 (fi->npp, fi->ir, fi->pv, fi->fv, fi->CF, fi->PF, fi->disc, fi->bep),
-	 fi->prec);
+    return fi->pmt =
+               rnd (_fi_calc_payment
+                    (fi->npp, fi->ir, fi->pv, fi->fv, fi->CF, fi->PF, fi->disc, fi->bep),
+                    fi->prec);
 }				/* fi_calc_payment */
 
 /* Compute Periodic Payment from:
@@ -1420,30 +1420,30 @@
  */
 double
 _fi_calc_payment (unsigned per,	/* number of periods        */
-		  double nint,	/* nominal interest rate    */
-		  double pv,	/* present value            */
-		  double fv,	/* future value             */
-		  unsigned CF,	/* compounding frequency    */
-		  unsigned PF,	/* payment frequency        */
-		  unsigned disc,/* discrete/continuous compounding */
-		  unsigned bep)	/* beginning/end of period payment */
+                  double nint,	/* nominal interest rate    */
+                  double pv,	/* present value            */
+                  double fv,	/* future value             */
+                  unsigned CF,	/* compounding frequency    */
+                  unsigned PF,	/* payment frequency        */
+                  unsigned disc,/* discrete/continuous compounding */
+                  unsigned bep)	/* beginning/end of period payment */
 {
-  double eint = eff_int (nint / 100.0, CF, PF, disc);
-  double AA = _A (eint, per);
-  double BB = _B (eint, bep);
-  g_return_val_if_fail(BB != 0.0, 0.0);
+    double eint = eff_int (nint / 100.0, CF, PF, disc);
+    double AA = _A (eint, per);
+    double BB = _B (eint, bep);
+    g_return_val_if_fail(BB != 0.0, 0.0);
 
-  return -(fv + pv * (AA + 1.0)) / (AA * BB);
+    return -(fv + pv * (AA + 1.0)) / (AA * BB);
 }				/* _fi_calc_payment */
 
 /* compute Future Value from preset data */
 double
 fi_calc_future_value (fi_ptr fi)
 {
-  return fi->fv =
-    rnd (_fi_calc_future_value
-	 (fi->npp, fi->ir, fi->pv, fi->pmt, fi->CF, fi->PF, fi->disc,
-	  fi->bep), fi->prec);
+    return fi->fv =
+               rnd (_fi_calc_future_value
+                    (fi->npp, fi->ir, fi->pv, fi->pmt, fi->CF, fi->PF, fi->disc,
+                     fi->bep), fi->prec);
 }				/* fi_calc_future_value */
 
 /* Compute Future Value from:
@@ -1454,73 +1454,73 @@
  */
 double
 _fi_calc_future_value (unsigned per,	/* number of periods        */
-		       double nint,	/* nominal interest rate    */
-		       double pv,	/* present value            */
-		       double pmt,	/* periodic payment         */
-		       unsigned CF,	/* compounding frequency    */
-		       unsigned PF,	/* payment frequency        */
-		       unsigned disc,	/* discrete/continuous compounding */
-		       unsigned bep)	/* beginning/end of period payment */
+                       double nint,	/* nominal interest rate    */
+                       double pv,	/* present value            */
+                       double pmt,	/* periodic payment         */
+                       unsigned CF,	/* compounding frequency    */
+                       unsigned PF,	/* payment frequency        */
+                       unsigned disc,	/* discrete/continuous compounding */
+                       unsigned bep)	/* beginning/end of period payment */
 {
-  double eint = eff_int (nint / 100.0, CF, PF, disc);
-  double AA = _A (eint, per);
-  double CC = _C (eint, pmt, bep);
+    double eint = eff_int (nint / 100.0, CF, PF, disc);
+    double AA = _A (eint, per);
+    double CC = _C (eint, pmt, bep);
 
-  return -(pv + AA * (pv + CC));
+    return -(pv + AA * (pv + CC));
 }				/* _fi_calc_future_value */
 
 /* compute Nominal Interest Rate from Effective Interest Rate */
 static double
 nom_int (double eint, unsigned CF, unsigned PF, unsigned disc)
 {
-  double nint;
+    double nint;
 
-  if (disc)
-  {
-    if (CF == PF)
+    if (disc)
     {
-      nint = CF * eint;
+        if (CF == PF)
+        {
+            nint = CF * eint;
+        }
+        else
+        {
+            nint = CF * (pow ((1.0 + eint), ((double) PF / (double) CF)) - 1.0);
+        }				/* * endif   */
     }
     else
-    {
-      nint = CF * (pow ((1.0 + eint), ((double) PF / (double) CF)) - 1.0);
-    }				/* * endif   */
-  }
-  else
-    nint = log (pow (1.0 + eint, PF));
+        nint = log (pow (1.0 + eint, PF));
 
-  return nint;
+    return nint;
 }				/* nom_int */
 
 /* Compute Effective Interest Rate from Nominal Interest Rate */
 static double
 eff_int (double nint, unsigned CF, unsigned PF, unsigned disc)
 {
-  double eint;
+    double eint;
 
-  if (disc)
-  {
-    if (CF == PF)
+    if (disc)
     {
-      eint = nint / (double) CF;
+        if (CF == PF)
+        {
+            eint = nint / (double) CF;
+        }
+        else
+        {
+            eint =
+                pow ((1.0 + nint / (double) CF), ((double) CF / (double) PF)) - 1.0;
+        }				/* endif */
     }
     else
-    {
-      eint =
-	pow ((1.0 + nint / (double) CF), ((double) CF / (double) PF)) - 1.0;
-    }				/* endif */
-  }
-  else
-    eint = exp (nint / (double) PF) - 1.0;
+        eint = exp (nint / (double) PF) - 1.0;
 
-  return eint;
+    return eint;
 }				/* eff_int */
 
 /* calculation used in interest computation */
 static double
 fi (unsigned per, double eint, double pv, double pmt, double fv, unsigned bep)
 {
-  return _A (eint, per) * (pv + _C (eint, pmt, bep)) + pv + fv;
+    return _A (eint, per) * (pv + _C (eint, pmt, bep)) + pv + fv;
 }				/* fi */
 
 /* calculation used in interest computation
@@ -1528,55 +1528,55 @@
 static double
 fip (unsigned per, double eint, double pv, double pmt, double fv, unsigned bep)
 {
-  double AA = _A (eint, per);
-  double CC = _C (eint, pmt, bep);
-  double D = (AA + 1.0) / (1.0 + eint);
-  g_return_val_if_fail(CC != 0.0, 0.0);
-  return (double) per *(pv + CC) * D - (AA * CC) / eint;
+    double AA = _A (eint, per);
+    double CC = _C (eint, pmt, bep);
+    double D = (AA + 1.0) / (1.0 + eint);
+    g_return_val_if_fail(CC != 0.0, 0.0);
+    return (double) per *(pv + CC) * D - (AA * CC) / eint;
 }				/* fip */
 
 void
 set_default (fi_ptr fi)
 {
-  /* flag whether accrueing interest at beginning or end of period
-   * FALSE --> end
-   * TRUE  --> beginning
-   * default to end of period payment s
-   */
-  fi->bep = FALSE;
+    /* flag whether accrueing interest at beginning or end of period
+     * FALSE --> end
+     * TRUE  --> beginning
+     * default to end of period payment s
+     */
+    fi->bep = FALSE;
 
-  /* flag for discrete or continuous interest
-   * TRUE  --> discrete
-   * FALSE --> continuous
-   * default to discrete interest
-   */
-  fi->disc = TRUE;
+    /* flag for discrete or continuous interest
+     * TRUE  --> discrete
+     * FALSE --> continuous
+     * default to discrete interest
+     */
+    fi->disc = TRUE;
 
-  /* set compounding, CF, and payment, PF, frequency per year
-   * default to monthly payments and compounding
-   */
-  fi->CF = fi->PF = 12;
+    /* set compounding, CF, and payment, PF, frequency per year
+     * default to monthly payments and compounding
+     */
+    fi->CF = fi->PF = 12;
 
-  /* standard loan quantities:
-   * number of periods: n
-   */
-  fi->npp = 0;
+    /* standard loan quantities:
+     * number of periods: n
+     */
+    fi->npp = 0;
 
-  /* annual interest: i
-   */
-  fi->ir = 0.0;
+    /* annual interest: i
+     */
+    fi->ir = 0.0;
 
-  /* Present Value: pv
-   */
-  fi->pv = 0.0;
+    /* Present Value: pv
+     */
+    fi->pv = 0.0;
 
-  /* Payment: pmt
-   */
-  fi->pmt = 0.0;
+    /* Payment: pmt
+     */
+    fi->pmt = 0.0;
 
-  /* Future Value: fv
-   */
-  fi->fv = 0.0;
+    /* Future Value: fv
+     */
+    fi->fv = 0.0;
 
 }				/* set_default */
 
@@ -1585,867 +1585,867 @@
 unsigned long
 julian_day_number (unsigned year, unsigned month, unsigned day)
 {
-  /*  Gregorian/Julian Calender Flag.
-   *  TRUE  == Julian
-   *  FALSE == Gregorian
-   */
-  unsigned gregorian = TRUE; /* assume we are dealing with current dates */
-  double yr;
-  double pfac = 0.6;
-  unsigned long ljdn;
+    /*  Gregorian/Julian Calender Flag.
+     *  TRUE  == Julian
+     *  FALSE == Gregorian
+     */
+    unsigned gregorian = TRUE; /* assume we are dealing with current dates */
+    double yr;
+    double pfac = 0.6;
+    unsigned long ljdn;
 
-  yr = year + (month - 3.0) / 12.0;
-  ljdn = (long) (367.0 * yr + pfac) - (2 * (long) (yr)) + (long) (yr / 4.0)
-    + (long) day + 1721117L;
-  if (gregorian)
-    ljdn += -(long) (yr / 100.0) + (long) (yr / 400.0) + 2;
+    yr = year + (month - 3.0) / 12.0;
+    ljdn = (long) (367.0 * yr + pfac) - (2 * (long) (yr)) + (long) (yr / 4.0)
+           + (long) day + 1721117L;
+    if (gregorian)
+        ljdn += -(long) (yr / 100.0) + (long) (yr / 400.0) + 2;
 
-  return ljdn;
+    return ljdn;
 }				/* julian_day_number */
 
 amort_sched_ptr
 Amortization_init (amort_sched_ptr amortsched)
 {
-  unsigned n = amortsched->n;
-  double nint = amortsched->nint;
-  double pv = amortsched->pv;
-  double pmt = amortsched->pmt;
-  double fv = amortsched->fv;
-  double eint;
-  double new_pmt;
-  double pve;
-  unsigned CF = amortsched->CF;
-  unsigned PF = amortsched->PF;
-  unsigned disc = amortsched->disc;
-  unsigned bep = amortsched->bep;
-  unsigned new_n;
-  unsigned prec = amortsched->prec;
-  unsigned long s,
+    unsigned n = amortsched->n;
+    double nint = amortsched->nint;
+    double pv = amortsched->pv;
+    double pmt = amortsched->pmt;
+    double fv = amortsched->fv;
+    double eint;
+    double new_pmt;
+    double pve;
+    unsigned CF = amortsched->CF;
+    unsigned PF = amortsched->PF;
+    unsigned disc = amortsched->disc;
+    unsigned bep = amortsched->bep;
+    unsigned new_n;
+    unsigned prec = amortsched->prec;
+    unsigned long s,
     d,
     days_to_yr_end,
     Eff_Date_jdn =
-    julian_day_number (amortsched->year_E, amortsched->month_E,
-		       amortsched->day_E), Init_Date_jdn =
-    julian_day_number (amortsched->year_I, amortsched->month_I,
-		       amortsched->day_I);
+        julian_day_number (amortsched->year_E, amortsched->month_E,
+                           amortsched->day_E), Init_Date_jdn =
+            julian_day_number (amortsched->year_I, amortsched->month_I,
+                               amortsched->day_I);
 
-  amortsched->Eff_Date_jdn = Eff_Date_jdn;
-  amortsched->Init_Date_jdn = Init_Date_jdn;
-  amortsched->yday_E =
-    Eff_Date_jdn - julian_day_number (amortsched->year_E, 1, 1);
-  amortsched->yday_I =
-    Init_Date_jdn - julian_day_number (amortsched->year_I, 1, 1);
-  amortsched->eint = eint = eff_int (nint / 100.0, CF, PF, disc);
-  amortsched->fv_case = dabs (fv) > dabs (pv);
-  amortsched->bp = bep ? 1.0 : 0.0;
+    amortsched->Eff_Date_jdn = Eff_Date_jdn;
+    amortsched->Init_Date_jdn = Init_Date_jdn;
+    amortsched->yday_E =
+        Eff_Date_jdn - julian_day_number (amortsched->year_E, 1, 1);
+    amortsched->yday_I =
+        Init_Date_jdn - julian_day_number (amortsched->year_I, 1, 1);
+    amortsched->eint = eint = eff_int (nint / 100.0, CF, PF, disc);
+    amortsched->fv_case = dabs (fv) > dabs (pv);
+    amortsched->bp = bep ? 1.0 : 0.0;
 
-  if (PF > 24)
-  {
-    /* Payment frequency per year greater than bi-monthly
-     * use actual number of days
-     */
-    s = Init_Date_jdn - Eff_Date_jdn;
-    days_to_yr_end =
-      julian_day_number (amortsched->year_I + 1, 1, 0) - Init_Date_jdn;
-    d = 366 / PF;
-  }
-  else
-  {
-    /* Payment frequency per year bi-monthly or less
-     * use 30 days/month, 360 days/year
-     */
-    if (Eff_Date_jdn == Init_Date_jdn)
+    if (PF > 24)
     {
-      s = 0;
+        /* Payment frequency per year greater than bi-monthly
+         * use actual number of days
+         */
+        s = Init_Date_jdn - Eff_Date_jdn;
+        days_to_yr_end =
+            julian_day_number (amortsched->year_I + 1, 1, 0) - Init_Date_jdn;
+        d = 366 / PF;
     }
     else
     {
-      s =
-	((amortsched->year_I - amortsched->year_E) * 360) +
-	((amortsched->month_I - amortsched->month_E) * 30) +
-	amortsched->day_I - amortsched->day_E;
+        /* Payment frequency per year bi-monthly or less
+         * use 30 days/month, 360 days/year
+         */
+        if (Eff_Date_jdn == Init_Date_jdn)
+        {
+            s = 0;
+        }
+        else
+        {
+            s =
+                ((amortsched->year_I - amortsched->year_E) * 360) +
+                ((amortsched->month_I - amortsched->month_E) * 30) +
+                amortsched->day_I - amortsched->day_E;
+        }				/* endif */
+        days_to_yr_end = 390 - (amortsched->month_I * 30) - amortsched->day_I;
+        d = 360 / PF;
     }				/* endif */
-    days_to_yr_end = 390 - (amortsched->month_I * 30) - amortsched->day_I;
-    d = 360 / PF;
-  }				/* endif */
 
-  if (!bep)
-  {
-    /* ordinary annuity
-     */
-    s -= d;
-  }				/* endif */
+    if (!bep)
+    {
+        /* ordinary annuity
+         */
+        s -= d;
+    }				/* endif */
 
-  amortsched->yr_pmt = (days_to_yr_end + d) / d;
+    amortsched->yr_pmt = (days_to_yr_end + d) / d;
 
-  if (pmt == 0.0)
-  {
-    s = 0;
-    amortsched->pve = pv;
-  }
-  else
-  {
-    amortsched->pve =
-      rnd (pv * pow ((1.0 + eint), ((double) (s * PF) / (double) (d * CF))),
-	   prec);
-  }				/* endif */
+    if (pmt == 0.0)
+    {
+        s = 0;
+        amortsched->pve = pv;
+    }
+    else
+    {
+        amortsched->pve =
+            rnd (pv * pow ((1.0 + eint), ((double) (s * PF) / (double) (d * CF))),
+                 prec);
+    }				/* endif */
 
-  pve = amortsched->pve;
+    pve = amortsched->pve;
 
-/*   compute new data to fully amortize loan:
- *       new periodic payment, new_pmt
- *
- *   option 1: Amortize with original transaction - ignore interest
- *   due to delayed initial payment
- *
- *   option 2: Amortize with new pv, pve == original pv adjusted for
- *   delayed initial payment, original payment, original fv and
- *   original total number of payments, adjust final payment
- *
- *   option 3: amortize with new pv, pve, and new payments adjusted to
- *   minimize final payment, keep original number of payments and
- *   original fv
- *
- *   option 4: amortize with new pv, pve, original payments and new
- *   number of payments to keep original final fv */
+    /*   compute new data to fully amortize loan:
+     *       new periodic payment, new_pmt
+     *
+     *   option 1: Amortize with original transaction - ignore interest
+     *   due to delayed initial payment
+     *
+     *   option 2: Amortize with new pv, pve == original pv adjusted for
+     *   delayed initial payment, original payment, original fv and
+     *   original total number of payments, adjust final payment
+     *
+     *   option 3: amortize with new pv, pve, and new payments adjusted to
+     *   minimize final payment, keep original number of payments and
+     *   original fv
+     *
+     *   option 4: amortize with new pv, pve, original payments and new
+     *   number of payments to keep original final fv */
 
-/* option 3, compute new periodic payment */
-  amortsched->new_pmt = new_pmt =
-    rnd (_fi_calc_payment (n, nint, pve, fv, CF, PF, disc, bep), prec);
+    /* option 3, compute new periodic payment */
+    amortsched->new_pmt = new_pmt =
+                              rnd (_fi_calc_payment (n, nint, pve, fv, CF, PF, disc, bep), prec);
 
-/* option 4: compute new number of total payments, new_n */
-  amortsched->new_n = new_n =
-    (unsigned)
-    rnd (_fi_calc_num_payments (nint, pve, pmt, fv, CF, PF, disc, bep), 0);
+    /* option 4: compute new number of total payments, new_n */
+    amortsched->new_n = new_n =
+                            (unsigned)
+                            rnd (_fi_calc_num_payments (nint, pve, pmt, fv, CF, PF, disc, bep), 0);
 
-  /* following used in QTAwk to insure integer value, not needed in C */
-  /*    n = int(n); */
+    /* following used in QTAwk to insure integer value, not needed in C */
+    /*    n = int(n); */
 
-  /* compute payment for constant payment to principal loan and final
-   * payment for original loan amount include interest due */
-  amortsched->cpmt1 = rnd (-pv / n, prec);
-  amortsched->final_pmt_opt_1 = -pv - amortsched->cpmt1 * (n - 1);
-  amortsched->final_pmt_opt_1 *= eint + 1;
+    /* compute payment for constant payment to principal loan and final
+     * payment for original loan amount include interest due */
+    amortsched->cpmt1 = rnd (-pv / n, prec);
+    amortsched->final_pmt_opt_1 = -pv - amortsched->cpmt1 * (n - 1);
+    amortsched->final_pmt_opt_1 *= eint + 1;
 
-  /* compute payment for constant payment to principal loan and final
-   * payment for delayed loan amount include interest due */
-  amortsched->cpmt2 = rnd (-pve / n, prec);
-  amortsched->final_pmt_opt_2 = -pve - amortsched->cpmt2 * (n - 1);
-  amortsched->final_pmt_opt_2 *= eint + 1;
+    /* compute payment for constant payment to principal loan and final
+     * payment for delayed loan amount include interest due */
+    amortsched->cpmt2 = rnd (-pve / n, prec);
+    amortsched->final_pmt_opt_2 = -pve - amortsched->cpmt2 * (n - 1);
+    amortsched->final_pmt_opt_2 *= eint + 1;
 
-  if (bep)
-  {
-    amortsched->final_pmt_opt_3 =
-      rnd (_fi_calc_future_value (n - 1, nint, pv, pmt, CF, PF, disc, bep) -
-	   (fv / (1.0 + eint)), prec);
-    amortsched->final_pmt_opt_4 =
-      rnd (_fi_calc_future_value (n - 1, nint, pve, pmt, CF, PF, disc, bep) -
-	   (fv / (1.0 + eint)), prec);
-    amortsched->final_pmt_opt_5 =
-      rnd (_fi_calc_future_value
-	   (n - 1, nint, pve, new_pmt, CF, PF, disc,
-	    bep) - (fv / (1.0 + eint)), prec);
-    if (new_n)
-      amortsched->final_pmt_opt_6 =
-	rnd (_fi_calc_future_value
-	     (new_n - 1, nint, pve, pmt, CF, PF, disc,
-	      bep) - (fv / (1.0 + eint)), prec);
+    if (bep)
+    {
+        amortsched->final_pmt_opt_3 =
+            rnd (_fi_calc_future_value (n - 1, nint, pv, pmt, CF, PF, disc, bep) -
+                 (fv / (1.0 + eint)), prec);
+        amortsched->final_pmt_opt_4 =
+            rnd (_fi_calc_future_value (n - 1, nint, pve, pmt, CF, PF, disc, bep) -
+                 (fv / (1.0 + eint)), prec);
+        amortsched->final_pmt_opt_5 =
+            rnd (_fi_calc_future_value
+                 (n - 1, nint, pve, new_pmt, CF, PF, disc,
+                  bep) - (fv / (1.0 + eint)), prec);
+        if (new_n)
+            amortsched->final_pmt_opt_6 =
+                rnd (_fi_calc_future_value
+                     (new_n - 1, nint, pve, pmt, CF, PF, disc,
+                      bep) - (fv / (1.0 + eint)), prec);
+        else
+            amortsched->final_pmt_opt_6 = 0.0;
+    }
     else
-      amortsched->final_pmt_opt_6 = 0.0;
-  }
-  else
-  {
-    amortsched->final_pmt_opt_3 =
-      rnd (_fi_calc_future_value (n - 1, nint, pv, pmt, CF, PF, disc, bep) *
-	   (1.0 + eint) - fv, prec);
-    amortsched->final_pmt_opt_4 =
-      rnd (_fi_calc_future_value (n - 1, nint, pve, pmt, CF, PF, disc, bep) *
-	   (1.0 + eint) - fv, prec);
-    amortsched->final_pmt_opt_5 =
-      rnd (_fi_calc_future_value
-	   (n - 1, nint, pve, new_pmt, CF, PF, disc, bep) * (1.0 + eint) - fv,
-	   prec);
-    if (new_n)
-      amortsched->final_pmt_opt_6 =
-	rnd (_fi_calc_future_value
-	     (new_n - 1, nint, pve, pmt, CF, PF, disc,
-	      bep) * (1.0 + eint) - fv, prec);
-    else
-      amortsched->final_pmt_opt_6 = 0.0;
-  }				/* endif */
+    {
+        amortsched->final_pmt_opt_3 =
+            rnd (_fi_calc_future_value (n - 1, nint, pv, pmt, CF, PF, disc, bep) *
+                 (1.0 + eint) - fv, prec);
+        amortsched->final_pmt_opt_4 =
+            rnd (_fi_calc_future_value (n - 1, nint, pve, pmt, CF, PF, disc, bep) *
+                 (1.0 + eint) - fv, prec);
+        amortsched->final_pmt_opt_5 =
+            rnd (_fi_calc_future_value
+                 (n - 1, nint, pve, new_pmt, CF, PF, disc, bep) * (1.0 + eint) - fv,
+                 prec);
+        if (new_n)
+            amortsched->final_pmt_opt_6 =
+                rnd (_fi_calc_future_value
+                     (new_n - 1, nint, pve, pmt, CF, PF, disc,
+                      bep) * (1.0 + eint) - fv, prec);
+        else
+            amortsched->final_pmt_opt_6 = 0.0;
+    }				/* endif */
 
-  /* compute delayed interest */
-  amortsched->delayed_int = pv - amortsched->pve;
+    /* compute delayed interest */
+    amortsched->delayed_int = pv - amortsched->pve;
 
-  return amortsched;
+    return amortsched;
 }				/* Amortization_init */
 
 amort_sched_ptr
 Amortization_Schedule (amort_sched_ptr amortsched)
 {
-  unsigned n = amortsched->n;
-  double nint = amortsched->nint;
-  double pv = amortsched->pv;
-  double pmt = amortsched->pmt;
-  double fv = amortsched->fv;
-  double eint = amortsched->eint;
-  unsigned CF = amortsched->CF;
-  unsigned PF = amortsched->PF;
-  unsigned disc = amortsched->disc;
-  unsigned bep = amortsched->bep;
-  double cpmt = 0;
-  double final_pmt = 0;
-  double delayed_int = amortsched->delayed_int;
-  char summary = amortsched->summary;
-  unsigned option = amortsched->option;
-  unsigned yr_pmt = amortsched->yr_pmt;
-  unsigned fv_case = amortsched->fv_case;
-  unsigned prec = amortsched->prec;
-  unsigned j, s, yr, per_cnt, pmt_cnt = 0, k = 0, sum_prt;
+    unsigned n = amortsched->n;
+    double nint = amortsched->nint;
+    double pv = amortsched->pv;
+    double pmt = amortsched->pmt;
+    double fv = amortsched->fv;
+    double eint = amortsched->eint;
+    unsigned CF = amortsched->CF;
+    unsigned PF = amortsched->PF;
+    unsigned disc = amortsched->disc;
+    unsigned bep = amortsched->bep;
+    double cpmt = 0;
+    double final_pmt = 0;
+    double delayed_int = amortsched->delayed_int;
+    char summary = amortsched->summary;
+    unsigned option = amortsched->option;
+    unsigned yr_pmt = amortsched->yr_pmt;
+    unsigned fv_case = amortsched->fv_case;
+    unsigned prec = amortsched->prec;
+    unsigned j, s, yr, per_cnt, pmt_cnt = 0, k = 0, sum_prt;
 
-  int jj;
+    int jj;
 
-  unsigned long d;
+    unsigned long d;
 
-  double yr_fv, sum_int, yr_int, prin, adv_pmt, pmt_int, hpv = 0.0;
-  yearly_summary_ptr yrly_sum;
-  amort_sched_yr_ptr amortyr;
-  sched_pmt_ptr pmtsched = NULL;
+    double yr_fv, sum_int, yr_int, prin, adv_pmt, pmt_int, hpv = 0.0;
+    yearly_summary_ptr yrly_sum;
+    amort_sched_yr_ptr amortyr;
+    sched_pmt_ptr pmtsched = NULL;
 
-  sum_int = yr_int = 0.0;
+    sum_int = yr_int = 0.0;
 
-  switch (option)
-  {
-  case 1:
-    amortsched->cpmt = cpmt = amortsched->cpmt1;
-    /* re-compute final payment without interest
-     */
-    amortsched->final_pmt = final_pmt = -pv - cpmt * (n - 1);
-    summary = (summary == 'y') ? 'x' : 'o';
-    break;
-  case 2:
-    amortsched->cpmt = cpmt = amortsched->cpmt2;
-    pv = amortsched->pve;
-    /* re-compute final payment without interest
-     */
-    amortsched->final_pmt = final_pmt = -pv - cpmt * (n - 1);
-    summary = (summary == 'y') ? 'x' : 'o';
-    break;
-  case 3:
-    delayed_int = 0.0;
-    amortsched->final_pmt = final_pmt = amortsched->final_pmt_opt_3;
-    break;
-  case 4:
-    pv = amortsched->pve;
-    amortsched->final_pmt = final_pmt = amortsched->final_pmt_opt_4;
-    break;
-  case 5:
-    pv = amortsched->pve;
-    pmt = amortsched->new_pmt;
-    amortsched->final_pmt = final_pmt = amortsched->final_pmt_opt_5;
-    break;
-  case 6:
-    n = amortsched->new_n;
-    pv = amortsched->pve;
-    amortsched->final_pmt = final_pmt = amortsched->final_pmt_opt_6;
-    break;
-  }				/* endswitch */
+    switch (option)
+    {
+    case 1:
+        amortsched->cpmt = cpmt = amortsched->cpmt1;
+        /* re-compute final payment without interest
+         */
+        amortsched->final_pmt = final_pmt = -pv - cpmt * (n - 1);
+        summary = (summary == 'y') ? 'x' : 'o';
+        break;
+    case 2:
+        amortsched->cpmt = cpmt = amortsched->cpmt2;
+        pv = amortsched->pve;
+        /* re-compute final payment without interest
+         */
+        amortsched->final_pmt = final_pmt = -pv - cpmt * (n - 1);
+        summary = (summary == 'y') ? 'x' : 'o';
+        break;
+    case 3:
+        delayed_int = 0.0;
+        amortsched->final_pmt = final_pmt = amortsched->final_pmt_opt_3;
+        break;
+    case 4:
+        pv = amortsched->pve;
+        amortsched->final_pmt = final_pmt = amortsched->final_pmt_opt_4;
+        break;
+    case 5:
+        pv = amortsched->pve;
+        pmt = amortsched->new_pmt;
+        amortsched->final_pmt = final_pmt = amortsched->final_pmt_opt_5;
+        break;
+    case 6:
+        n = amortsched->new_n;
+        pv = amortsched->pve;
+        amortsched->final_pmt = final_pmt = amortsched->final_pmt_opt_6;
+        break;
+    }				/* endswitch */
 
-  yr = amortsched->year_I;
-  sum_prt = TRUE;
-  switch (summary)
-  {
-  case 'a':
-    /* variable advanced prepayment schedule.  prepayment equals next
-     * period principal.  */
-    amortsched->schedule.first_yr =
-      amortyr = (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
+    yr = amortsched->year_I;
+    sum_prt = TRUE;
+    switch (summary)
+    {
+    case 'a':
+        /* variable advanced prepayment schedule.  prepayment equals next
+         * period principal.  */
+        amortsched->schedule.first_yr =
+            amortyr = (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
 
-    d = pv;
+        d = pv;
 
-    for (per_cnt = 0, s = 1, j = n; pv != fv; j -= 2, per_cnt++)
-    {
-      /* basic equation to compute interest this payment period */
-      pmt_int = -rnd ((pv + (amortsched->bp * pmt)) * eint, prec);
+        for (per_cnt = 0, s = 1, j = n; pv != fv; j -= 2, per_cnt++)
+        {
+            /* basic equation to compute interest this payment period */
+            pmt_int = -rnd ((pv + (amortsched->bp * pmt)) * eint, prec);
 
-      /* sum yearly interest paid */
-      yr_int += pmt_int;
+            /* sum yearly interest paid */
+            yr_int += pmt_int;
 
-      /* sum total interest paid */
-      sum_int += pmt_int;
+            /* sum total interest paid */
+            sum_int += pmt_int;
 
-      /* compute principal paid this payment period and round to
-       nearest cent */
-      if (dabs (pmt) > dabs (pv))
-      {
-	prin = -pv;
-	pmt = prin + pmt_int;
-	adv_pmt = 0.0;
-	pv = fv;
-      }
-      else
-      {
-	prin = rnd (pmt - pmt_int, prec);
+            /* compute principal paid this payment period and round to
+             nearest cent */
+            if (dabs (pmt) > dabs (pv))
+            {
+                prin = -pv;
+                pmt = prin + pmt_int;
+                adv_pmt = 0.0;
+                pv = fv;
+            }
+            else
+            {
+                prin = rnd (pmt - pmt_int, prec);
 
-	/* compute remaining pv and round to nearest cent */
-	pv = rnd (pv + prin, prec);
+                /* compute remaining pv and round to nearest cent */
+                pv = rnd (pv + prin, prec);
 
-	/* compute principal for next payment cycle and round to
-	 nearest cent */
-	adv_pmt = rnd (pmt + (pv + (amortsched->bp * pmt)) * eint, prec);
+                /* compute principal for next payment cycle and round to
+                 nearest cent */
+                adv_pmt = rnd (pmt + (pv + (amortsched->bp * pmt)) * eint, prec);
 
-	if (dabs (pv) >= dabs (adv_pmt))
-	{
-	  /* remaining pv greater than advanced principal payment
-	   * compute remaining pv and round to nearest cent */
-	  pv = rnd (pv + adv_pmt, prec);
-	}
-	else
-	{
-	  /* remaining pv less than advanced principal payment reduce
-	   * advanced pricipla payment to remaining pv */
-	  adv_pmt = -pv;
+                if (dabs (pv) >= dabs (adv_pmt))
+                {
+                    /* remaining pv greater than advanced principal payment
+                     * compute remaining pv and round to nearest cent */
+                    pv = rnd (pv + adv_pmt, prec);
+                }
+                else
+                {
+                    /* remaining pv less than advanced principal payment reduce
+                     * advanced pricipla payment to remaining pv */
+                    adv_pmt = -pv;
 
-	  /* and set remaining pv to fv */
-	  pv = fv;
-	}			/* ## endif   */
-      }				/* # endif */
+                    /* and set remaining pv to fv */
+                    pv = fv;
+                }			/* ## endif   */
+            }				/* # endif */
 
-      if (sum_prt)
-      {
-	jj = (j < yr_pmt) ? j + 1 : yr_pmt;
-	amortyr->payments =
-	  pmtsched = (sched_pmt_ptr) calloc (jj, sizeof (sched_pmt));
-	pmt_cnt = 0;
+            if (sum_prt)
+            {
+                jj = (j < yr_pmt) ? j + 1 : yr_pmt;
+                amortyr->payments =
+                    pmtsched = (sched_pmt_ptr) calloc (jj, sizeof (sched_pmt));
+                pmt_cnt = 0;
 
-	sum_prt = FALSE;
-      }				/* endif */
+                sum_prt = FALSE;
+            }				/* endif */
 
-      pmtsched->period_num = s++;
-      pmtsched->interest = pmt_int;
-      pmtsched->principal = prin;
-      pmtsched->advanced_pmt = adv_pmt;
-      pmtsched->total_pmt = pmt + adv_pmt;
-      pmtsched->balance = pv;
-      pmtsched++;
-      pmt_cnt++;
+            pmtsched->period_num = s++;
+            pmtsched->interest = pmt_int;
+            pmtsched->principal = prin;
+            pmtsched->advanced_pmt = adv_pmt;
+            pmtsched->total_pmt = pmt + adv_pmt;
+            pmtsched->balance = pv;
+            pmtsched++;
+            pmt_cnt++;
 
-      if (!--yr_pmt)
-      {
-	yr_pmt = PF;
+            if (!--yr_pmt)
+            {
+                yr_pmt = PF;
 
-	amortyr->year = yr++;
-	amortyr->interest_pd = yr_int;
-	amortyr->principal_pd = pv - hpv;
-	amortyr->yr_end_balance = pv;
-	amortyr->total_interest_pd = sum_int;
-	amortyr->num_periods = pmt_cnt;
-	amortyr->next_yr =
-	  (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
-	amortyr = amortyr->next_yr;
+                amortyr->year = yr++;
+                amortyr->interest_pd = yr_int;
+                amortyr->principal_pd = pv - hpv;
+                amortyr->yr_end_balance = pv;
+                amortyr->total_interest_pd = sum_int;
+                amortyr->num_periods = pmt_cnt;
+                amortyr->next_yr =
+                    (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
+                amortyr = amortyr->next_yr;
 
-	hpv = pv;
-	yr_int = 0.0;
-	sum_prt = TRUE;
-      }				/* endif */
-    }				/* endfor */
+                hpv = pv;
+                yr_int = 0.0;
+                sum_prt = TRUE;
+            }				/* endif */
+        }				/* endfor */
 
-    if (dabs (pv) > 0.0)
-    {
-      /* basic equation to compute interest this payment period */
-      pmt_int = -rnd ((pv + (amortsched->bp * pmt)) * eint, prec);
+        if (dabs (pv) > 0.0)
+        {
+            /* basic equation to compute interest this payment period */
+            pmt_int = -rnd ((pv + (amortsched->bp * pmt)) * eint, prec);
 
-      /* sum yearly interest paid */
-      yr_int += pmt_int;
+            /* sum yearly interest paid */
+            yr_int += pmt_int;
 
-      /* sum total interest paid */
-      sum_int += pmt_int;
+            /* sum total interest paid */
+            sum_int += pmt_int;
 
-      /* compute principal paid this payment period and round to
-       nearest cent */
-      prin = rnd (pmt - pmt_int, prec);
-      final_pmt = pmt;
+            /* compute principal paid this payment period and round to
+             nearest cent */
+            prin = rnd (pmt - pmt_int, prec);
+            final_pmt = pmt;
 
-      /* compute remaining pv and round to nearest cent */
-      pv = rnd (pv + prin, prec);
+            /* compute remaining pv and round to nearest cent */
+            pv = rnd (pv + prin, prec);
 
-      /* Set advanced principal payment to remaining pv */
-      adv_pmt = -pv;
-      amortyr->final_pmt = final_pmt += adv_pmt;
+            /* Set advanced principal payment to remaining pv */
+            adv_pmt = -pv;
+            amortyr->final_pmt = final_pmt += adv_pmt;
 
-      /* and set remaining pv to fv */
-      pv = fv;
+            /* and set remaining pv to fv */
+            pv = fv;
 
-      pmtsched->period_num = s++;
-      pmtsched->interest = pmt_int;
-      pmtsched->principal = prin;
-      pmtsched->advanced_pmt = adv_pmt;
-      pmtsched->total_pmt = final_pmt;
-      pmtsched->balance = pv;
+            pmtsched->period_num = s++;
+            pmtsched->interest = pmt_int;
+            pmtsched->principal = prin;
+            pmtsched->advanced_pmt = adv_pmt;
+            pmtsched->total_pmt = final_pmt;
+            pmtsched->balance = pv;
 
-      per_cnt++;
-      pmt_cnt++;
-    }				/* endif */
+            per_cnt++;
+            pmt_cnt++;
+        }				/* endif */
 
-    if (dabs (yr_int) > 0.0)
-    {
-      amortyr->year = yr++;
-      amortyr->interest_pd = yr_int;
-      amortyr->principal_pd = pv - hpv;
-      amortyr->total_interest_pd = sum_int;
-      amortyr->num_periods = pmt_cnt;
-    }				/* endif */
+        if (dabs (yr_int) > 0.0)
+        {
+            amortyr->year = yr++;
+            amortyr->interest_pd = yr_int;
+            amortyr->principal_pd = pv - hpv;
+            amortyr->total_interest_pd = sum_int;
+            amortyr->num_periods = pmt_cnt;
+        }				/* endif */
 
-    amortsched->total_periods = per_cnt;
-    break;
-  case 'f':
-    /* fixed prepaymet schedule prepayment specified by user */
-    amortsched->schedule.first_yr =
-      amortyr = (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
+        amortsched->total_periods = per_cnt;
+        break;
+    case 'f':
+        /* fixed prepaymet schedule prepayment specified by user */
+        amortsched->schedule.first_yr =
+            amortyr = (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
 
-    d = pv;
+        d = pv;
 
-    /*  set advnaced payment */
-    adv_pmt = amortsched->fixed_pmt;
+        /*  set advnaced payment */
+        adv_pmt = amortsched->fixed_pmt;
 
-    for (per_cnt = 0, s = 1, j = n; j && (pv != fv); j--, per_cnt++)
-    {
-      /* basic equation to compute interest this payment period */
-      pmt_int = -rnd ((pv + (amortsched->bp * pmt)) * eint, prec);
-      /*  sum yearly interest paid
-       */
-      yr_int += pmt_int;
-      /*  sum total interest paid */
-      sum_int += pmt_int;
+        for (per_cnt = 0, s = 1, j = n; j && (pv != fv); j--, per_cnt++)
+        {
+            /* basic equation to compute interest this payment period */
+            pmt_int = -rnd ((pv + (amortsched->bp * pmt)) * eint, prec);
+            /*  sum yearly interest paid
+             */
+            yr_int += pmt_int;
+            /*  sum total interest paid */
+            sum_int += pmt_int;
 
-      /* compute principal paid this payment period and round to
-       nearest cent */
-      if (dabs (pmt) > dabs (pv))
-      {
-	prin = -pv;
-	pmt = prin + pmt_int;
-	adv_pmt = 0.0;
-	pv = 0.0;
-      }
-      else
-      {
-	prin = rnd (pmt - pmt_int, prec);
+            /* compute principal paid this payment period and round to
+             nearest cent */
+            if (dabs (pmt) > dabs (pv))
+            {
+                prin = -pv;
+                pmt = prin + pmt_int;
+                adv_pmt = 0.0;
+                pv = 0.0;
+            }
+            else
+            {
+                prin = rnd (pmt - pmt_int, prec);
 
-	/*  compute remaining pv and round to nearest cent */
-	pv = rnd (pv + prin, prec);
+                /*  compute remaining pv and round to nearest cent */
+                pv = rnd (pv + prin, prec);
 
-	if (dabs (pv) >= dabs (adv_pmt))
-	{
-	  /* remaining pv greater than advanced principal payment
-	   * compute remaining pv and round to nearest cent */
-	  pv = rnd (pv + adv_pmt, prec);
-	}
-	else
-	{
-	  /* remaining pv less than advanced principal payment reduce
-	   * advanced pricipal payment to remaining pv and set
-	   * remaining pv to fv */
-	  adv_pmt = -pv;
-	  pv = fv;
-	}			/*## endif */
-      }				/* # endif */
+                if (dabs (pv) >= dabs (adv_pmt))
+                {
+                    /* remaining pv greater than advanced principal payment
+                     * compute remaining pv and round to nearest cent */
+                    pv = rnd (pv + adv_pmt, prec);
+                }
+                else
+                {
+                    /* remaining pv less than advanced principal payment reduce
+                     * advanced pricipal payment to remaining pv and set
+                     * remaining pv to fv */
+                    adv_pmt = -pv;
+                    pv = fv;
+                }			/*## endif */
+            }				/* # endif */
 
-      if (sum_prt)
-      {
-	jj = (j < yr_pmt) ? j + 1 : yr_pmt;
-	amortyr->payments =
-	  pmtsched = (sched_pmt_ptr) calloc (jj, sizeof (sched_pmt));
-	pmt_cnt = 0;
+            if (sum_prt)
+            {
+                jj = (j < yr_pmt) ? j + 1 : yr_pmt;
+                amortyr->payments =
+                    pmtsched = (sched_pmt_ptr) calloc (jj, sizeof (sched_pmt));
+                pmt_cnt = 0;
 
-	sum_prt = FALSE;
-      }
-      else
-      {
-	(amortyr->num_periods)++;
-      }				/* ## endif */
+                sum_prt = FALSE;
+            }
+            else
+            {
+                (amortyr->num_periods)++;
+            }				/* ## endif */
 
-      pmtsched->period_num = s++;
-      pmtsched->interest = pmt_int;
-      pmtsched->principal = prin;
-      pmtsched->advanced_pmt = adv_pmt;
-      pmtsched->total_pmt = pmt + adv_pmt;
-      pmtsched->balance = pv;
-      pmt_cnt++;
-      pmtsched++;
+            pmtsched->period_num = s++;
+            pmtsched->interest = pmt_int;
+            pmtsched->principal = prin;
+            pmtsched->advanced_pmt = adv_pmt;
+            pmtsched->total_pmt = pmt + adv_pmt;
+            pmtsched->balance = pv;
+            pmt_cnt++;
+            pmtsched++;
 
-      if (!--yr_pmt)
-      {
-	yr_pmt = PF;
+            if (!--yr_pmt)
+            {
+                yr_pmt = PF;
 
-	amortyr->year = yr++;
-	amortyr->interest_pd = yr_int;
-	amortyr->principal_pd = pv - hpv;
-	amortyr->yr_end_balance = pv;
-	amortyr->total_interest_pd = sum_int;
-	amortyr->num_periods = pmt_cnt;
-	amortyr->next_yr =
-	  (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
-	amortyr = amortyr->next_yr;
+                amortyr->year = yr++;
+                amortyr->interest_pd = yr_int;
+                amortyr->principal_pd = pv - hpv;
+                amortyr->yr_end_balance = pv;
+                amortyr->total_interest_pd = sum_int;
+                amortyr->num_periods = pmt_cnt;
+                amortyr->next_yr =
+                    (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
+                amortyr = amortyr->next_yr;
 
-	hpv = pv;
-	yr_int = 0.0;
-	sum_prt = TRUE;
-      }				/* ## endif */
-    }				/* ## endfor */
+                hpv = pv;
+                yr_int = 0.0;
+                sum_prt = TRUE;
+            }				/* ## endif */
+        }				/* ## endfor */
 
-    if (pv != fv)
-    {
-      /* # basic equation to compute interest this payment period */
-      pmt_int = -rnd ((pv + (amortsched->bp * pmt)) * eint, prec);
+        if (pv != fv)
+        {
+            /* # basic equation to compute interest this payment period */
+            pmt_int = -rnd ((pv + (amortsched->bp * pmt)) * eint, prec);
 
-      /* # sum yearly interest paid */
-      yr_int += pmt_int;
-      /* # sum total interest paid */
-      sum_int += pmt_int;
+            /* # sum yearly interest paid */
+            yr_int += pmt_int;
+            /* # sum total interest paid */
+            sum_int += pmt_int;
 
-      /* # compute principal paid this payment period and round to
-       nearest cent */
-      prin = rnd (pmt - pmt_int, prec);
-      final_pmt = pmt;
+            /* # compute principal paid this payment period and round to
+             nearest cent */
+            prin = rnd (pmt - pmt_int, prec);
+            final_pmt = pmt;
 
-      /* # compute remaining pv and round to nearest cent */
-      pv = rnd (pv + prin, prec);
+            /* # compute remaining pv and round to nearest cent */
+            pv = rnd (pv + prin, prec);
 
-      /* # Set advanced principal payment to remaining pv */
-      adv_pmt = -pv;
-      amortyr->final_pmt = final_pmt += adv_pmt;
+            /* # Set advanced principal payment to remaining pv */
+            adv_pmt = -pv;
+            amortyr->final_pmt = final_pmt += adv_pmt;
 
-      /* # and set remaining pv to fv */
-      pv = fv;
+            /* # and set remaining pv to fv */
+            pv = fv;
 
-      pmtsched->period_num = s++;
-      pmtsched->interest = pmt_int;
-      pmtsched->principal = prin;
-      pmtsched->advanced_pmt = adv_pmt;
-      pmtsched->total_pmt = final_pmt;
-      pmtsched->balance = pv;
+            pmtsched->period_num = s++;
+            pmtsched->interest = pmt_int;
+            pmtsched->principal = prin;
+            pmtsched->advanced_pmt = adv_pmt;
+            pmtsched->total_pmt = final_pmt;
+            pmtsched->balance = pv;
 
-      per_cnt++;
-      pmt_cnt++;
-    }				/* # endif */
+            per_cnt++;
+            pmt_cnt++;
+        }				/* # endif */
 
-    if (dabs (yr_int) > 0.0)
-    {
-      amortyr->year = yr++;
-      amortyr->interest_pd = yr_int;
-      amortyr->principal_pd = pv - hpv;
-      amortyr->total_interest_pd = sum_int;
-      amortyr->num_periods = pmt_cnt;
-    }				/* endif */
+        if (dabs (yr_int) > 0.0)
+        {
+            amortyr->year = yr++;
+            amortyr->interest_pd = yr_int;
+            amortyr->principal_pd = pv - hpv;
+            amortyr->total_interest_pd = sum_int;
+            amortyr->num_periods = pmt_cnt;
+        }				/* endif */
 
-    amortsched->total_periods = per_cnt;
-    break;
-  case 'o':
-    /* Constant payment to principal use constant payment equal to
-     * original pv divided by number of periods.  constant payment to
-     * pricipal could be amount specified by user.  */
-    amortsched->schedule.first_yr =
-      amortyr = (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
-    amortsched->total_periods = n;
+        amortsched->total_periods = per_cnt;
+        break;
+    case 'o':
+        /* Constant payment to principal use constant payment equal to
+         * original pv divided by number of periods.  constant payment to
+         * pricipal could be amount specified by user.  */
+        amortsched->schedule.first_yr =
+            amortyr = (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
+        amortsched->total_periods = n;
 
-    d = yr_pmt;
-    for (s = 1, j = n - 1; j; j--, k++)
-    {
-      pmt_int = -rnd (pv * eint, prec);
+        d = yr_pmt;
+        for (s = 1, j = n - 1; j; j--, k++)
+        {
+            pmt_int = -rnd (pv * eint, prec);
 
-      /* sum yearly interest paid */
-      yr_int += pmt_int;
+            /* sum yearly interest paid */
+            yr_int += pmt_int;
 
-      /* sum total interest paid */
-      sum_int += pmt_int;
+            /* sum total interest paid */
+            sum_int += pmt_int;
 
-      pv = rnd (pv + cpmt, prec);
+            pv = rnd (pv + cpmt, prec);
 
-      if (sum_prt)
-      {
-	jj = (j < yr_pmt) ? j + 1 : yr_pmt;
-	amortyr->payments =
-	  pmtsched = (sched_pmt_ptr) calloc (jj, sizeof (sched_pmt));
-	amortyr->num_periods = jj;
-	k = 0;
+            if (sum_prt)
+            {
+                jj = (j < yr_pmt) ? j + 1 : yr_pmt;
+                amortyr->payments =
+                    pmtsched = (sched_pmt_ptr) calloc (jj, sizeof (sched_pmt));
+                amortyr->num_periods = jj;
+                k = 0;
 
-	sum_prt = FALSE;
-      }				/* endif */
+                sum_prt = FALSE;
+            }				/* endif */
 
-      pmtsched->period_num = s++;
-      pmtsched->interest = pmt_int;
-      pmtsched->total_pmt = cpmt + pmt_int;
-      pmtsched->balance = pv;
-      pmtsched++;
+            pmtsched->period_num = s++;
+            pmtsched->interest = pmt_int;
+            pmtsched->total_pmt = cpmt + pmt_int;
+            pmtsched->balance = pv;
+            pmtsched++;
 
-      if (!--yr_pmt)
-      {
-	yr_pmt = PF;
+            if (!--yr_pmt)
+            {
+                yr_pmt = PF;
 
-	amortyr->year = yr++;
-	amortyr->interest_pd = yr_int;
-	amortyr->principal_pd = d * cpmt;
-	amortyr->yr_end_balance = pv;
-	amortyr->total_interest_pd = sum_int;
-	amortyr->next_yr =
-	  (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
-	amortyr = amortyr->next_yr;
+                amortyr->year = yr++;
+                amortyr->interest_pd = yr_int;
+                amortyr->principal_pd = d * cpmt;
+                amortyr->yr_end_balance = pv;
+                amortyr->total_interest_pd = sum_int;
+                amortyr->next_yr =
+                    (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
+                amortyr = amortyr->next_yr;
 
-	d = PF;
-	yr_int = 0.0;
-	sum_prt = TRUE;
-      }				/* endif */
-    }				/* endfor */
+                d = PF;
+                yr_int = 0.0;
+                sum_prt = TRUE;
+            }				/* endif */
+        }				/* endfor */
 
-    if (pv)
-    {
-      pmt_int = -rnd (pv * eint, prec);
+        if (pv)
+        {
+            pmt_int = -rnd (pv * eint, prec);
 
-      /* sum yearly interest paid */
-      yr_int += pmt_int;
+            /* sum yearly interest paid */
+            yr_int += pmt_int;
 
-      /* sum total interest paid */
-      sum_int += pmt_int;
+            /* sum total interest paid */
+            sum_int += pmt_int;
 
-      pmtsched->period_num = s++;
-      pmtsched->interest = -pmt_int;
-      pmtsched->total_pmt = -pv + pmt_int;
-      pmtsched->balance = 0.0;
+            pmtsched->period_num = s++;
+            pmtsched->interest = -pmt_int;
+            pmtsched->total_pmt = -pv + pmt_int;
+            pmtsched->balance = 0.0;
 
-      amortyr->final_pmt = -pv - pmt_int;
-    }				/* endif */
+            amortyr->final_pmt = -pv - pmt_int;
+        }				/* endif */
 
-    if (dabs (yr_int) > 0.0)
-    {
-      amortyr->year = yr++;
-      amortyr->interest_pd = yr_int;
-      amortyr->principal_pd = -pv + k * cpmt;
-      amortyr->total_interest_pd = sum_int;
-    }				/* endif */
-    break;
-  case 'p':
-    /* normal amortization schedule interest, principal and balance
-     * per payment period */
-    amortsched->schedule.first_yr =
-      amortyr = (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
-    amortsched->total_periods = n;
+        if (dabs (yr_int) > 0.0)
+        {
+            amortyr->year = yr++;
+            amortyr->interest_pd = yr_int;
+            amortyr->principal_pd = -pv + k * cpmt;
+            amortyr->total_interest_pd = sum_int;
+        }				/* endif */
+        break;
+    case 'p':
+        /* normal amortization schedule interest, principal and balance
+         * per payment period */
+        amortsched->schedule.first_yr =
+            amortyr = (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
+        amortsched->total_periods = n;
 
-    hpv = pv;
-    for (s = 1, j = n - 1; j; j--)
-    {
-      /* basic equation for computing interest paid in payment period */
-      pmt_int = -rnd ((pv + (amortsched->bp * pmt)) * eint, prec);
+        hpv = pv;
+        for (s = 1, j = n - 1; j; j--)
+        {
+            /* basic equation for computing interest paid in payment period */
+            pmt_int = -rnd ((pv + (amortsched->bp * pmt)) * eint, prec);
 
-      /* sum yearly interest paid */
-      yr_int += pmt_int;
+            /* sum yearly interest paid */
+            yr_int += pmt_int;
 
-      /* sum total interest paid */
-      sum_int += pmt_int;
+            /* sum total interest paid */
+            sum_int += pmt_int;
 
-      /* compute principal paid this payment period */
-      prin = rnd (pmt - pmt_int, prec);
+            /* compute principal paid this payment period */
+            prin = rnd (pmt - pmt_int, prec);
 
-      /* compute remaining pv and round to nearest cent */
-      pv = rnd (pv + prin, prec);
+            /* compute remaining pv and round to nearest cent */
+            pv = rnd (pv + prin, prec);
 
-      if (sum_prt)
-      {
-	jj = (j < yr_pmt) ? j + 1 : yr_pmt;
-	amortyr->payments =
-	  pmtsched = (sched_pmt_ptr) calloc (jj, sizeof (sched_pmt));
-	amortyr->num_periods = jj;
+            if (sum_prt)
+            {
+                jj = (j < yr_pmt) ? j + 1 : yr_pmt;
+                amortyr->payments =
+                    pmtsched = (sched_pmt_ptr) calloc (jj, sizeof (sched_pmt));
+                amortyr->num_periods = jj;
 
-	sum_prt = FALSE;
-      }				/* endif */
+                sum_prt = FALSE;
+            }				/* endif */
 
-      if (fv_case)
-      {
-	pmtsched->period_num = s++;
-	pmtsched->interest = pmt_int;
-	pmtsched->balance = pv;
-	pmtsched++;
-      }
-      else
-      {
-	pmtsched->period_num = s++;
-	pmtsched->interest = pmt_int;
-	pmtsched->principal = prin;
-	pmtsched->balance = pv;
-	pmtsched++;
-      }				/* endif */
+            if (fv_case)
+            {
+                pmtsched->period_num = s++;
+                pmtsched->interest = pmt_int;
+                pmtsched->balance = pv;
+                pmtsched++;
+            }
+            else
+            {
+                pmtsched->period_num = s++;
+                pmtsched->interest = pmt_int;
+                pmtsched->principal = prin;
+                pmtsched->balance = pv;
+                pmtsched++;
+            }				/* endif */
 
-      if (!--yr_pmt)
-      {
-	yr_pmt = PF;
+            if (!--yr_pmt)
+            {
+                yr_pmt = PF;
 
-	amortyr->year = yr++;
-	amortyr->interest_pd = yr_int;
-	if (!fv_case)
-	{
-	  amortyr->principal_pd = pv - hpv;
-	}			/* endif */
-	amortyr->yr_end_balance = pv;
-	amortyr->total_interest_pd = sum_int;
-	amortyr->next_yr =
-	  (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
-	amortyr = amortyr->next_yr;
+                amortyr->year = yr++;
+                amortyr->interest_pd = yr_int;
+                if (!fv_case)
+                {
+                    amortyr->principal_pd = pv - hpv;
+                }			/* endif */
+                amortyr->yr_end_balance = pv;
+                amortyr->total_interest_pd = sum_int;
+                amortyr->next_yr =
+                    (amort_sched_yr_ptr) calloc (1, sizeof (amort_sched_yr));
+                amortyr = amortyr->next_yr;
 
-	hpv = pv;
-	yr_int = 0.0;
-	sum_prt = TRUE;
-      }				/* * endif */
-    }				/* * endfor */
+                hpv = pv;
+                yr_int = 0.0;
+                sum_prt = TRUE;
+            }				/* * endif */
+        }				/* * endfor */
 
-    /* determine if payment due at beginning or end of period in order
-     * to correctly compute final payment, interest and principal */
-    if (bep)
-    {
-      /* paying remainder at beginning of period compute final payment */
-      final_pmt = -pv - fv / (1 + eint);
+        /* determine if payment due at beginning or end of period in order
+         * to correctly compute final payment, interest and principal */
+        if (bep)
+        {
+            /* paying remainder at beginning of period compute final payment */
+            final_pmt = -pv - fv / (1 + eint);
 
-      /* then compute interest paid with final final payment */
-      pmt_int = -rnd ((pv + final_pmt) * eint, prec);
+            /* then compute interest paid with final final payment */
+            pmt_int = -rnd ((pv + final_pmt) * eint, prec);
 
-      /* then compute the principal paid */
-      prin = final_pmt + pmt_int;
-    }
-    else
-    {
-      /* basic equation for computing interest paid in payment period
-       * for payment at end of period */
-      pmt_int = -rnd (pv * eint, prec);
+            /* then compute the principal paid */
+            prin = final_pmt + pmt_int;
+        }
+        else
+        {
+            /* basic equation for computing interest paid in payment period
+             * for payment at end of period */
+            pmt_int = -rnd (pv * eint, prec);
 
-      /* compute principal paid this payment period */
-      prin = -pv;
+            /* compute principal paid this payment period */
+            prin = -pv;
 
-      /* compute the final payment note the final payment may be
-       * computed either of two ways both are equivalent */
-      final_pmt = prin + pmt_int;
-    }				/* * endif   */
+            /* compute the final payment note the final payment may be
+             * computed either of two ways both are equivalent */
+            final_pmt = prin + pmt_int;
+        }				/* * endif   */
 
-    pv = -fv;
+        pv = -fv;
 
-    /* sum yearly interest paid */
-    yr_int += pmt_int;
+        /* sum yearly interest paid */
+        yr_int += pmt_int;
 
-    /* sum total interest paid */
-    sum_int += pmt_int;
+        /* sum total interest paid */
+        sum_int += pmt_int;
 
-    if (sum_prt)
-    {
-      amortyr->payments =
-	pmtsched = (sched_pmt_ptr) calloc (1, sizeof (sched_pmt));
-      amortyr->num_periods = 1;
-    }				/* endif */
+        if (sum_prt)
+        {
+            amortyr->payments =
+                pmtsched = (sched_pmt_ptr) calloc (1, sizeof (sched_pmt));
+            amortyr->num_periods = 1;
+        }				/* endif */
 
-    amortyr->final_pmt = final_pmt;
+        amortyr->final_pmt = final_pmt;
 
-    if (fv_case)
-    {
-      pmtsched->period_num = s++;
-      pmtsched->interest = pmt_int;
-      pmtsched->balance = pv;
-    }
-    else
-    {
-      pmtsched->period_num = s++;
-      pmtsched->interest = pmt_int;
-      pmtsched->principal = prin;
-      pmtsched->balance = pv;
-    }				/* endif */
+        if (fv_case)
+        {
+            pmtsched->period_num = s++;
+            pmtsched->interest = pmt_int;
+            pmtsched->balance = pv;
+        }
+        else
+        {
+            pmtsched->period_num = s++;
+            pmtsched->interest = pmt_int;
+            pmtsched->principal = prin;
+            pmtsched->balance = pv;
+        }				/* endif */
 
-    if (dabs (yr_int) > 0.0)
-    {
-      amortyr->year = yr++;
-      amortyr->interest_pd = yr_int;
-      amortyr->total_interest_pd = sum_int;
-      if (!bep)
-      {
-	amortyr->principal_pd = -hpv;
-      }				/* endif */
-    }				/* endif */
+        if (dabs (yr_int) > 0.0)
+        {
+            amortyr->year = yr++;
+            amortyr->interest_pd = yr_int;
+            amortyr->total_interest_pd = sum_int;
+            if (!bep)
+            {
+                amortyr->principal_pd = -hpv;
+            }				/* endif */
+        }				/* endif */
 
-    break;
-  case 'x':
-    /* constant payment to principal - annual summary */
-    /* compute number of years to summarize */
-    j = n / PF;
-    if (yr_pmt < PF)
-      j++;
-    amortsched->total_periods = j;
-    amortsched->schedule.summary =
-      yrly_sum = (yearly_summary_ptr) calloc (j, sizeof (yearly_summary));
+        break;
+    case 'x':
+        /* constant payment to principal - annual summary */
+        /* compute number of years to summarize */
+        j = n / PF;
+        if (yr_pmt < PF)
+            j++;
+        amortsched->total_periods = j;
+        amortsched->schedule.summary =
+            yrly_sum = (yearly_summary_ptr) calloc (j, sizeof (yearly_summary));
 
-    jj = 0;
-    for (j = n, sum_prt = 0; j > 0; j -= yr_pmt, yr_pmt = PF, sum_prt++)
-    {
-      if (j <= PF)
-      {
-	s = jj + j;
-	yr_pmt = j;
-	yr_fv = rnd (pv + cpmt * (s - 1), prec) + final_pmt;
-      }
-      else
-      {
-	s = jj + yr_pmt;
-	yr_fv = rnd (pv + cpmt * s, prec);
-      }				/* endif */
-      prin = -eint * jj * (pv + (cpmt * (jj - 1) / 2.0));
-      yr_int = -eint * s * (pv + (cpmt * (s - 1) / 2.0));
-      yr_int = rnd (yr_int - prin, prec);
-      jj += yr_pmt;
+        jj = 0;
+        for (j = n, sum_prt = 0; j > 0; j -= yr_pmt, yr_pmt = PF, sum_prt++)
+        {
+            if (j <= PF)
+            {
+                s = jj + j;
+                yr_pmt = j;
+                yr_fv = rnd (pv + cpmt * (s - 1), prec) + final_pmt;
+            }
+            else
+            {
+                s = jj + yr_pmt;
+                yr_fv = rnd (pv + cpmt * s, prec);
+            }				/* endif */
+            prin = -eint * jj * (pv + (cpmt * (jj - 1) / 2.0));
+            yr_int = -eint * s * (pv + (cpmt * (s - 1) / 2.0));
+            yr_int = rnd (yr_int - prin, prec);
+            jj += yr_pmt;
 
-      sum_int += yr_int;
+            sum_int += yr_int;
 
-      yrly_sum[sum_prt].year = yr++;
-      yrly_sum[sum_prt].interest = yr_int;
-      yrly_sum[sum_prt].end_balance = yr_fv;
-    }				/* endfor */
+            yrly_sum[sum_prt].year = yr++;
+            yrly_sum[sum_prt].interest = yr_int;
+            yrly_sum[sum_prt].end_balance = yr_fv;
+        }				/* endfor */
 
-    break;
-  case 'y':
-    /* normal amortization - annual summary */
-    /* compute number of years to summarize */
-    j = n / PF;
-    if (yr_pmt < PF)
-      j++;
-    if (n > (j * PF))
-      j++;
-    amortsched->total_periods = j;
-    amortsched->schedule.summary =
-      yrly_sum = (yearly_summary_ptr) calloc (j, sizeof (yearly_summary));
+        break;
+    case 'y':
+        /* normal amortization - annual summary */
+        /* compute number of years to summarize */
+        j = n / PF;
+        if (yr_pmt < PF)
+            j++;
+        if (n > (j * PF))
+            j++;
+        amortsched->total_periods = j;
+        amortsched->schedule.summary =
+            yrly_sum = (yearly_summary_ptr) calloc (j, sizeof (yearly_summary));
 
-    hpv = pv;
+        hpv = pv;
 
-    for (jj = n, j = 0; jj > 0; jj -= yr_pmt, yr_pmt = PF, j++)
-    {
-      if (jj <= (int)PF)
-      {
-	yr_fv = fv;
-	yr_int = rnd (((jj - 1) * pmt) + hpv + final_pmt, prec);
-      }
-      else
-      {
-	yr_fv =
-	  -rnd (_fi_calc_future_value
-		(yr_pmt, nint, hpv, pmt, CF, PF, disc, bep), prec);
-	yr_int = rnd ((yr_pmt * pmt) + hpv - yr_fv, prec);
-      }				/* * endif */
+        for (jj = n, j = 0; jj > 0; jj -= yr_pmt, yr_pmt = PF, j++)
+        {
+            if (jj <= (int)PF)
+            {
+                yr_fv = fv;
+                yr_int = rnd (((jj - 1) * pmt) + hpv + final_pmt, prec);
+            }
+            else
+            {
+                yr_fv =
+                    -rnd (_fi_calc_future_value
+                          (yr_pmt, nint, hpv, pmt, CF, PF, disc, bep), prec);
+                yr_int = rnd ((yr_pmt * pmt) + hpv - yr_fv, prec);
+            }				/* * endif */
 
-      sum_int += yr_int;
+            sum_int += yr_int;
 
-      yrly_sum[j].year = yr++;
-      yrly_sum[j].interest = yr_int;
-      yrly_sum[j].end_balance = yr_fv;
-      hpv = yr_fv;
-    }				/* * endfor */
+            yrly_sum[j].year = yr++;
+            yrly_sum[j].interest = yr_int;
+            yrly_sum[j].end_balance = yr_fv;
+            hpv = yr_fv;
+        }				/* * endfor */
 
-    break;
-  }				/* * endswitch */
+        break;
+    }				/* * endswitch */
 
-  amortsched->total_interest = sum_int;
+    amortsched->total_interest = sum_int;
 
-  return amortsched;
+    return amortsched;
 }				/* Amortization_Schedule */
 
 /* function to free dynamically allocated memory used for amortization
@@ -2453,26 +2453,26 @@
 void
 Amortization_free (amort_sched_ptr amortsched)
 {
-  amort_sched_yr_ptr amortyr, prst_yr;
+    amort_sched_yr_ptr amortyr, prst_yr;
 
-  switch (amortsched->summary)
-  {
-  case 'a':
-  case 'f':
-  case 'o':
-  case 'p':
-    for (amortyr = amortsched->schedule.first_yr; amortyr; amortyr = prst_yr)
+    switch (amortsched->summary)
     {
-      if (amortyr->payments)
-	free (amortyr->payments);
-      prst_yr = amortyr->next_yr;
-      free (amortyr);
-    }				/* endfor */
-    break;
-  case 'y':
-    free (amortsched->schedule.summary);
-    break;
-  }				/* endswitch */
+    case 'a':
+    case 'f':
+    case 'o':
+    case 'p':
+        for (amortyr = amortsched->schedule.first_yr; amortyr; amortyr = prst_yr)
+        {
+            if (amortyr->payments)
+                free (amortyr->payments);
+            prst_yr = amortyr->next_yr;
+            free (amortyr);
+        }				/* endfor */
+        break;
+    case 'y':
+        free (amortsched->schedule.summary);
+        break;
+    }				/* endswitch */
 
-  amortsched->schedule.first_yr = NULL;
+    amortsched->schedule.first_yr = NULL;
 }				/* amort_free */

Modified: gnucash/trunk/src/calculation/fin_spl_protos.h
===================================================================
--- gnucash/trunk/src/calculation/fin_spl_protos.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/fin_spl_protos.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -26,19 +26,19 @@
 /* expression_parser.c */
 /* Line Number:  344 */
 parser_env_ptr init_parser(
-                           var_store_ptr  predefined_vars,
-                           gchar  *radix_point,
-                           gchar  *group_char,
-                           void          *trans_numeric(const char *digit_str,
-                                                        gchar *radix_point,
-                                                        gchar *group_char,
-                                                        char **rstr),
-                           void          *numeric_ops(char  op_sym,
-                                                      void *left_value,
-                                                      void *right_value),
-                           void          *negate_numeric(void *value),
-                           void           free_numeric(void *numeric_value),
-                           void		 *func_op( const char *fname,
-                                                   int argc, void **argv ) );
+    var_store_ptr  predefined_vars,
+    gchar  *radix_point,
+    gchar  *group_char,
+    void          *trans_numeric(const char *digit_str,
+                                 gchar *radix_point,
+                                 gchar *group_char,
+                                 char **rstr),
+    void          *numeric_ops(char  op_sym,
+                               void *left_value,
+                               void *right_value),
+    void          *negate_numeric(void *value),
+    void           free_numeric(void *numeric_value),
+    void		 *func_op( const char *fname,
+                     int argc, void **argv ) );
 
 #endif

Modified: gnucash/trunk/src/calculation/fin_static_proto.h
===================================================================
--- gnucash/trunk/src/calculation/fin_static_proto.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/fin_static_proto.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -25,47 +25,47 @@
  */
 /* Line Number: 614 */
 static double            rnd(
-                             double x,
-                             unsigned places);
+    double x,
+    unsigned places);
 /* Line Number: 628 */
 static double            dabs(
-                              double x);
+    double x);
 /* Line Number: 634 */
 static double            _A(
-                            double eint,
-                            unsigned per);
+    double eint,
+    unsigned per);
 /* Line Number: 1181 */
 static double            _B(
-                            double eint,
-                            unsigned beg);
+    double eint,
+    unsigned beg);
 /* Line Number: 1394 */
 static double            nom_int(
-                                 double eint,
-                                 unsigned CF,
-                                 unsigned PF,
-                                 unsigned disc);
+    double eint,
+    unsigned CF,
+    unsigned PF,
+    unsigned disc);
 /* Line Number: 781 */
 static double            eff_int(
-                                 double nint,
-                                 unsigned CF,
-                                 unsigned PF,
-                                 unsigned disc);
+    double nint,
+    unsigned CF,
+    unsigned PF,
+    unsigned disc);
 /* Line Number: 798 */
 static double            fi(
-                            unsigned per,
-                            double eint,
-                            double pv,
-                            double pmt,
-                            double fv,
-                            unsigned bep);
+    unsigned per,
+    double eint,
+    double pv,
+    double pmt,
+    double fv,
+    unsigned bep);
 /* Line Number: 1449 */
 static double            fip(
-                             unsigned per,
-                             double eint,
-                             double pv,
-                             double pmt,
-                             double fv,
-                             unsigned bep);
+    unsigned per,
+    double eint,
+    double pv,
+    double pmt,
+    double fv,
+    unsigned bep);
 #endif /* FIN_STATICS */
 
 #if defined( EXPRESSION_PARSER_STATICS )
@@ -74,36 +74,36 @@
  */
 /* Line Number: 485 */
 static var_store_ptr     pop(
-                             parser_env_ptr pe);
+    parser_env_ptr pe);
 /* Line Number: 321 */
 static var_store_ptr     push(
-                              var_store_ptr push_value,
-                              parser_env_ptr pe);
+    var_store_ptr push_value,
+    parser_env_ptr pe);
 /* Line Number: 519 */
 static var_store_ptr     get_named_var(
-                                       parser_env_ptr pe);
+    parser_env_ptr pe);
 /* Line Number: 366 */
 static var_store_ptr     get_unnamed_var(
-                                         parser_env_ptr pe);
+    parser_env_ptr pe);
 /* Line Number: 579 */
 static void              free_var(
-                                  var_store_ptr value,
-                                  parser_env_ptr pe);
+    var_store_ptr value,
+    parser_env_ptr pe);
 /* Line Number: 596 */
 static void              next_token(
-                                    parser_env_ptr pe);
+    parser_env_ptr pe);
 /* Line Number: 426 */
 static void              assignment_op(
-                                       parser_env_ptr pe);
+    parser_env_ptr pe);
 /* Line Number: 695 */
 static void              add_sub_op(
-                                    parser_env_ptr pe);
+    parser_env_ptr pe);
 /* Line Number: 464 */
 static void              multiply_divide_op(
-                                            parser_env_ptr pe);
+    parser_env_ptr pe);
 /* Line Number: 488 */
 static void              primary_exp(
-                                     parser_env_ptr pe);
+    parser_env_ptr pe);
 #endif /* EXPRESSION_PARSER_STATICS */
 
 #if defined( NUMERIC_OPS_STATICS )

Modified: gnucash/trunk/src/calculation/finproto.h
===================================================================
--- gnucash/trunk/src/calculation/finproto.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/finproto.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -112,7 +112,7 @@
 unsigned delete_var (char *var_name, parser_env_ptr pe);
 
 char *parse_string (var_store_ptr value,
-		    const char *string, parser_env_ptr pe);
+                    const char *string, parser_env_ptr pe);
 
 
 /*==================================================*/

Modified: gnucash/trunk/src/calculation/finvar.h
===================================================================
--- gnucash/trunk/src/calculation/finvar.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/finvar.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -39,17 +39,17 @@
 
 typedef enum
 {
-  PARSER_NO_ERROR = 0,
-  UNBALANCED_PARENS,
-  STACK_OVERFLOW,
-  STACK_UNDERFLOW,
-  UNDEFINED_CHARACTER,
-  NOT_A_VARIABLE,
-  NOT_A_FUNC,
-  PARSER_OUT_OF_MEMORY,
-  NUMERIC_ERROR,
-  EXPRESSION_ERROR,
-  PARSER_NUM_ERRORS
+    PARSER_NO_ERROR = 0,
+    UNBALANCED_PARENS,
+    STACK_OVERFLOW,
+    STACK_UNDERFLOW,
+    UNDEFINED_CHARACTER,
+    NOT_A_VARIABLE,
+    NOT_A_FUNC,
+    PARSER_OUT_OF_MEMORY,
+    NUMERIC_ERROR,
+    EXPRESSION_ERROR,
+    PARSER_NUM_ERRORS
 }
 ParseError;
 
@@ -71,19 +71,20 @@
 typedef struct var_store *var_store_ptr;
 
 /* the type of entity contained in the var_store */
-typedef enum {
-  VST_NUMERIC = 0,
-  VST_STRING
+typedef enum
+{
+    VST_NUMERIC = 0,
+    VST_STRING
 } VarStoreType;
 
 typedef struct var_store
 {
-  char *variable_name;	  /* variable name if variable, NULL otherwise       */
-  char use_flag;	  /* flag if variable has been assigned to           */
-  char assign_flag;	  /* flag if variable is used                        */
-  VarStoreType type;
-  void *value;		  /* pointer to implementation defined numeric value */
-  var_store_ptr next_var; /* pointer to next variable in linked list         */
+    char *variable_name;	  /* variable name if variable, NULL otherwise       */
+    char use_flag;	  /* flag if variable has been assigned to           */
+    char assign_flag;	  /* flag if variable is used                        */
+    VarStoreType type;
+    void *value;		  /* pointer to implementation defined numeric value */
+    var_store_ptr next_var; /* pointer to next variable in linked list         */
 }
 var_store;
 
@@ -96,13 +97,13 @@
 typedef struct numeric *numeric_ptr;
 typedef struct numeric
 {
-  char type;			/* designates type of value */
-  union
-  {
-    long int int_value;		/* long integer value   */
-    double dbl_value;		/* double value         */
-  }
-  value;
+    char type;			/* designates type of value */
+    union
+    {
+        long int int_value;		/* long integer value   */
+        double dbl_value;		/* double value         */
+    }
+    value;
 }
 numeric;
 
@@ -114,9 +115,9 @@
 typedef struct yearly_summary *yearly_summary_ptr;
 typedef struct yearly_summary
 {
-  unsigned year;
-  double interest;
-  double end_balance;
+    unsigned year;
+    double interest;
+    double end_balance;
 }
 yearly_summary;
 
@@ -125,12 +126,12 @@
 typedef struct sched_pmt *sched_pmt_ptr;
 typedef struct sched_pmt
 {
-  unsigned period_num;
-  double interest;
-  double principal;
-  double advanced_pmt;
-  double total_pmt;
-  double balance;
+    unsigned period_num;
+    double interest;
+    double principal;
+    double advanced_pmt;
+    double total_pmt;
+    double balance;
 }
 sched_pmt;
 
@@ -139,15 +140,15 @@
 typedef struct amort_sched_yr *amort_sched_yr_ptr;
 typedef struct amort_sched_yr
 {
-  unsigned year;
-  unsigned num_periods;
-  sched_pmt_ptr payments;
-  double interest_pd;
-  double principal_pd;
-  double yr_end_balance;
-  double total_interest_pd;
-  double final_pmt;
-  amort_sched_yr_ptr next_yr;
+    unsigned year;
+    unsigned num_periods;
+    sched_pmt_ptr payments;
+    double interest_pd;
+    double principal_pd;
+    double yr_end_balance;
+    double total_interest_pd;
+    double final_pmt;
+    amort_sched_yr_ptr next_yr;
 }
 amort_sched_yr;
 
@@ -156,63 +157,63 @@
 typedef struct amort_sched *amort_sched_ptr;
 typedef struct amort_sched
 {
-  /* following information set by function calling amortization
-     functions */
-  unsigned n;			/* number of periods                        */
-  double nint;			/* nominal interest rate                    */
-  double pv;			/* present value                            */
-  double pmt;			/* periodic payment                         */
-  double fv;			/* future value                             */
-  unsigned CF;			/* compounding frequency                    */
-  unsigned PF;			/* payment frequency                        */
-  unsigned disc;		/* discrete/continuous compounding flag     */
-  unsigned bep;			/* beginning/end of period payment flag     */
-  unsigned prec;		/* roundoff precision                       */
-  unsigned year_E;		/* Effective date - year                    */
-  unsigned month_E;		/* Effective date - month                   */
-  unsigned day_E;		/* Effective date - day of month            */
-  unsigned year_I;		/* Initial payment date - year              */
-  unsigned month_I;		/* Initial payment date - month             */
-  unsigned day_I;		/* Initial payment date - day of month      */
+    /* following information set by function calling amortization
+       functions */
+    unsigned n;			/* number of periods                        */
+    double nint;			/* nominal interest rate                    */
+    double pv;			/* present value                            */
+    double pmt;			/* periodic payment                         */
+    double fv;			/* future value                             */
+    unsigned CF;			/* compounding frequency                    */
+    unsigned PF;			/* payment frequency                        */
+    unsigned disc;		/* discrete/continuous compounding flag     */
+    unsigned bep;			/* beginning/end of period payment flag     */
+    unsigned prec;		/* roundoff precision                       */
+    unsigned year_E;		/* Effective date - year                    */
+    unsigned month_E;		/* Effective date - month                   */
+    unsigned day_E;		/* Effective date - day of month            */
+    unsigned year_I;		/* Initial payment date - year              */
+    unsigned month_I;		/* Initial payment date - month             */
+    unsigned day_I;		/* Initial payment date - day of month      */
 
-/* following information set by calling function to indicate which
- * schedule to compute and which type of schedule */
-  unsigned option;		/* option flag from 1 to 6 inclusive        */
-  char summary;			/* summary flag == 'y', 'p', 'a' or 'f'     */
+    /* following information set by calling function to indicate which
+     * schedule to compute and which type of schedule */
+    unsigned option;		/* option flag from 1 to 6 inclusive        */
+    char summary;			/* summary flag == 'y', 'p', 'a' or 'f'     */
 
-/* following information set by amortization functions */
-  double eint;			/* effective interest rate                  */
-  double bp;			/* float value of bep                       */
-  double total_interest;	/* total interest paid                  */
-  unsigned total_periods;	/* total numer of periods in schedule   */
-  unsigned long yr_pmt;		/* number of payments in first year         */
-  double final_pmt_opt_1;	/* final payment option 1 */
-  double final_pmt_opt_2;	/* final payment option 2 */
-  double final_pmt_opt_3;	/* final payment option 3 */
-  double final_pmt_opt_4;	/* final payment option 4 */
-  double final_pmt_opt_5;	/* final payment option 5 */
-  double final_pmt_opt_6;	/* final payment option 6 */
-  double final_pmt;		/* final payment          */
-  double pve;			/* pv adjusted for delayed initial payment  */
-  double new_pmt;		/* pmt adjusted for delayed initial payment */
-  double cpmt;			/* constant payment to principal            */
-  double cpmt1;			/* constant payment to principal, 1st case  */
-  double cpmt2;			/* constant payment to principal, 2cd case  */
-  double delayed_int;		/* interest due to delayed initial payment  */
-  double fixed_pmt;		/* fixed prepayment amount for amortization */
-  unsigned new_n;		/* new number of periods to amortize due to
+    /* following information set by amortization functions */
+    double eint;			/* effective interest rate                  */
+    double bp;			/* float value of bep                       */
+    double total_interest;	/* total interest paid                  */
+    unsigned total_periods;	/* total numer of periods in schedule   */
+    unsigned long yr_pmt;		/* number of payments in first year         */
+    double final_pmt_opt_1;	/* final payment option 1 */
+    double final_pmt_opt_2;	/* final payment option 2 */
+    double final_pmt_opt_3;	/* final payment option 3 */
+    double final_pmt_opt_4;	/* final payment option 4 */
+    double final_pmt_opt_5;	/* final payment option 5 */
+    double final_pmt_opt_6;	/* final payment option 6 */
+    double final_pmt;		/* final payment          */
+    double pve;			/* pv adjusted for delayed initial payment  */
+    double new_pmt;		/* pmt adjusted for delayed initial payment */
+    double cpmt;			/* constant payment to principal            */
+    double cpmt1;			/* constant payment to principal, 1st case  */
+    double cpmt2;			/* constant payment to principal, 2cd case  */
+    double delayed_int;		/* interest due to delayed initial payment  */
+    double fixed_pmt;		/* fixed prepayment amount for amortization */
+    unsigned new_n;		/* new number of periods to amortize due to
                                    delayed intial payment */
-  unsigned fv_case;		/* fv case flag */
-  unsigned long Eff_Date_jdn;
-  unsigned yday_E;
-  unsigned long Init_Date_jdn;
-  unsigned yday_I;
-  union
-  {
-    amort_sched_yr_ptr first_yr;
-    yearly_summary_ptr summary;
-  }
-  schedule;
+    unsigned fv_case;		/* fv case flag */
+    unsigned long Eff_Date_jdn;
+    unsigned yday_E;
+    unsigned long Init_Date_jdn;
+    unsigned yday_I;
+    union
+    {
+        amort_sched_yr_ptr first_yr;
+        yearly_summary_ptr summary;
+    }
+    schedule;
 }
 amort_sched;
 
@@ -224,28 +225,28 @@
 typedef struct financial_info *fi_ptr;
 typedef struct financial_info
 {
-  double ir;			/* interest rate            */
-  double pv;			/* present value            */
-  double pmt;			/* periodic payment         */
-  double fv;			/* future value             */
+    double ir;			/* interest rate            */
+    double pv;			/* present value            */
+    double pmt;			/* periodic payment         */
+    double fv;			/* future value             */
 
-  unsigned npp;			/* number of payment periods            */
-  unsigned CF;			/* Compounding frequency                */
-  unsigned PF;			/* payment frequency                    */
-  unsigned bep;			/* beginning/end of period payment flag */
-  /* TRUE  == beginning of period         */
-  /* FALSE == end of period               */
-  unsigned disc;		/* discrete/continuous compounding flag */
-  /* TRUE  == discrete compounding        */
-  /* FALSE == continuous compounding      */
+    unsigned npp;			/* number of payment periods            */
+    unsigned CF;			/* Compounding frequency                */
+    unsigned PF;			/* payment frequency                    */
+    unsigned bep;			/* beginning/end of period payment flag */
+    /* TRUE  == beginning of period         */
+    /* FALSE == end of period               */
+    unsigned disc;		/* discrete/continuous compounding flag */
+    /* TRUE  == discrete compounding        */
+    /* FALSE == continuous compounding      */
 
-  /* precision of roundoff for pv, pmt and fv.
-   * i, Interest not rounded
-   * n, number of periods rounded to integer value, implicit value of zero, 0
-   *
-   * 2 for US Dollars
-   */
-  unsigned prec;
+    /* precision of roundoff for pv, pmt and fv.
+     * i, Interest not rounded
+     * n, number of periods rounded to integer value, implicit value of zero, 0
+     *
+     * 2 for US Dollars
+     */
+    unsigned prec;
 }
 financial_info;
 

Modified: gnucash/trunk/src/calculation/gncmod-calculation.c
===================================================================
--- gnucash/trunk/src/calculation/gncmod-calculation.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/gncmod-calculation.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -23,21 +23,25 @@
 
 
 char *
-libgncmod_calculation_gnc_module_path(void) {
-  return g_strdup("gnucash/calculation");
+libgncmod_calculation_gnc_module_path(void)
+{
+    return g_strdup("gnucash/calculation");
 }
 
 char *
-libgncmod_calculation_gnc_module_description(void) {
-  return g_strdup("GnuCash calculation module");
+libgncmod_calculation_gnc_module_description(void)
+{
+    return g_strdup("GnuCash calculation module");
 }
 
 int
-libgncmod_calculation_gnc_module_init(int refcount) {
-  return TRUE;
+libgncmod_calculation_gnc_module_init(int refcount)
+{
+    return TRUE;
 }
 
 int
-libgncmod_calculation_gnc_module_end(int refcount) {
-  return TRUE;
+libgncmod_calculation_gnc_module_end(int refcount)
+{
+    return TRUE;
 }

Modified: gnucash/trunk/src/calculation/numeric_ops.c
===================================================================
--- gnucash/trunk/src/calculation/numeric_ops.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/numeric_ops.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -33,7 +33,8 @@
 #define NUMERIC_OPS_STATICS
 #include "finvar.h"
 
-static double neg_table[] = {
+static double neg_table[] =
+{
     1e-256,
     1e-128,
     1e-64,
@@ -46,7 +47,8 @@
     1.0
 };
 
-static double pos_table[] = {
+static double pos_table[] =
+{
     1e+256,
     1e+128,
     1e+64,
@@ -82,178 +84,207 @@
  *
  */
 void           *trans_numeric(
-const char *str,              /* pointer to string to translate */
-char   radix_point,      /* radix character                */
-char   group_char,       /* grouping character to left of radix  */
-char **endstr)           /* where to return pointer to first unrecognized character */
+    const char *str,              /* pointer to string to translate */
+    char   radix_point,      /* radix character                */
+    char   group_char,       /* grouping character to left of radix  */
+    char **endstr)           /* where to return pointer to first unrecognized character */
 {
-	double         dblval = 0.0;
-	int            exp = 0,
-	               dchr,
-	               err = 0,
-	               base = 10;
-	long int       inum = 0;
-	unsigned long  msdec = 0,
-	               lsdec = 0,
-                   msscale = 1;
-	unsigned       radix = 0,
-	               sign = 0,
-	               digit_cnt = 0;
-	const char    *strinit = str;
-	numeric_ptr    rslt = NULL;
+    double         dblval = 0.0;
+    int            exp = 0,
+                         dchr,
+                         err = 0,
+                               base = 10;
+    long int       inum = 0;
+    unsigned long  msdec = 0,
+                           lsdec = 0,
+                                   msscale = 1;
+    unsigned       radix = 0,
+                           sign = 0,
+                                  digit_cnt = 0;
+    const char    *strinit = str;
+    numeric_ptr    rslt = NULL;
 
-	while ( isspace(*str) ) str++;
+    while ( isspace(*str) ) str++;
 
-	switch (*str) {
-		case '-':
-			sign++;
-		case '+':
-			str++;
-		default:
-		    break;
-	} /* endswitch */
-	
-	while ( *str ) {
-	
-		while ( (*str >= '0') && (*str <= '9') ) {
-		    digit_cnt++;
-		
-		    if ( msdec < MAX_SCALE ) msdec = msdec * 10 + (*str - '0');
-		      else if ( msscale < MAX_SCALE ) {
-		        lsdec = lsdec * 10 + (*str - '0');
-			    msscale *= 10;
-		    } else exp++;
-		
-		    if ( radix ) exp--;
-		      else {
-		        dchr = *str - '0';
-		        if ( ((LONG_MIN + dchr) / base) > inum ) err = 1;
-		        inum = inum * base + dchr;
-		    } /* endif */
-		    str++;		
-		} /* endwhile */
-		
-		if ( !radix ) {
-		    if ( *str == radix_point ) radix++;
-		      else if ( *str != group_char ) break;
-		  } else {
-		    break;
-		} /* endif */
-		
-		str++;
-	} /* endwhile */
-	
-	if ( digit_cnt ) {
-	    unsigned      exp_dcnt = 0;
-	
-    	if ( (*str == 'e') || (*str == 'E') ) {
-	        char exp_sign = EOS;
-	        int  ex_exp = 0;
+    switch (*str)
+    {
+    case '-':
+        sign++;
+    case '+':
+        str++;
+    default:
+        break;
+    } /* endswitch */
 
-	        switch (*++str) {
-	        	case '-':
-	    	    	exp_sign++;
-        		case '+':
-	        		str++;
-	        	default:
-	        		break;
-    	    } /* endswitch */
-    	
-    	    while ( (*str >= '0') && (*str <= '9') ) {
-        		if (ex_exp < (DBL_MAX_EXP * 2) ) ex_exp = ex_exp * 10 + (*str - '0');
-    	    	str++;
-	    	    exp_dcnt++;
-	        } /* endwhile */
+    while ( *str )
+    {
 
-	        exp += exp_sign ? -ex_exp : ex_exp;
-	    } /* endif */
+        while ( (*str >= '0') && (*str <= '9') )
+        {
+            digit_cnt++;
 
-	    if ( radix || exp ) {
-	        int pow = 256;
-	
-    	    dblval = msdec;
-    	    if ( msscale != 1 )	dblval = dblval * msscale + lsdec;
+            if ( msdec < MAX_SCALE ) msdec = msdec * 10 + (*str - '0');
+            else if ( msscale < MAX_SCALE )
+            {
+                lsdec = lsdec * 10 + (*str - '0');
+                msscale *= 10;
+            }
+            else exp++;
 
-        	if ( dblval && exp ) {
-        	    unsigned u = 0;
+            if ( radix ) exp--;
+            else
+            {
+                dchr = *str - '0';
+                if ( ((LONG_MIN + dchr) / base) > inum ) err = 1;
+                inum = inum * base + dchr;
+            } /* endif */
+            str++;
+        } /* endwhile */
 
-	            pow = 256;
-    	        while ( exp > 0 ) {
-    	        	while ( exp >= pow ) {
-    	        		dblval *= pos_table[u];
-		        	    exp -= pow;
-            		} /* endwhile */
-    	        	pow >>= 1;
-        	    	u++;
-	            } /* endwhile */
-	
-    	        while ( exp < 0 ) {
-    	        	while ( exp <= -pow ) {
-    	        		dblval *= neg_table[u];
-		        	    if ( dblval == 0.0 ) {
-		        	        errno = ERANGE;
-		        	        err = 1;
-		        	    } /* endif */
-        	    		exp += pow;
-	        	    } /* endwhile */
-        	    	pow >>= 1;
-	        	    u++;
-    	        } /* endwhile */
-    	
-        	    /* if overflow occurred		*/
-	            if ( dblval == HUGE_VAL ) {
-	                errno = ERANGE;
-	                err = 1;
-	            } /* endif */
-    	    } /* endif */
+        if ( !radix )
+        {
+            if ( *str == radix_point ) radix++;
+            else if ( *str != group_char ) break;
+        }
+        else
+        {
+            break;
+        } /* endif */
 
-    	    if ( !err ) {
-    	        rslt = (numeric_ptr)calloc(1,sizeof(numeric)); 	
-        	    rslt->type = DBL_TYPE;
-            	rslt->value.dbl_value = dblval;
-        	} /* endif */
-    	  } else {
-    	    if ( (!sign && (inum == LONG_MIN)) || err ) {
-        		inum = LONG_MIN + sign;
-		        errno = ERANGE;
-		      } else {
-		        rslt = (numeric_ptr)calloc(1,sizeof(numeric));
-        	    rslt->type = INT_TYPE;
-    	  	    rslt->value.int_value = inum;		
-        	} /* endif */
-	    } /* endif */
+        str++;
+    } /* endwhile */
+
+    if ( digit_cnt )
+    {
+        unsigned      exp_dcnt = 0;
+
+        if ( (*str == 'e') || (*str == 'E') )
+        {
+            char exp_sign = EOS;
+            int  ex_exp = 0;
+
+            switch (*++str)
+            {
+            case '-':
+                exp_sign++;
+            case '+':
+                str++;
+            default:
+                break;
+            } /* endswitch */
+
+            while ( (*str >= '0') && (*str <= '9') )
+            {
+                if (ex_exp < (DBL_MAX_EXP * 2) ) ex_exp = ex_exp * 10 + (*str - '0');
+                str++;
+                exp_dcnt++;
+            } /* endwhile */
+
+            exp += exp_sign ? -ex_exp : ex_exp;
+        } /* endif */
+
+        if ( radix || exp )
+        {
+            int pow = 256;
+
+            dblval = msdec;
+            if ( msscale != 1 )	dblval = dblval * msscale + lsdec;
+
+            if ( dblval && exp )
+            {
+                unsigned u = 0;
+
+                pow = 256;
+                while ( exp > 0 )
+                {
+                    while ( exp >= pow )
+                    {
+                        dblval *= pos_table[u];
+                        exp -= pow;
+                    } /* endwhile */
+                    pow >>= 1;
+                    u++;
+                } /* endwhile */
+
+                while ( exp < 0 )
+                {
+                    while ( exp <= -pow )
+                    {
+                        dblval *= neg_table[u];
+                        if ( dblval == 0.0 )
+                        {
+                            errno = ERANGE;
+                            err = 1;
+                        } /* endif */
+                        exp += pow;
+                    } /* endwhile */
+                    pow >>= 1;
+                    u++;
+                } /* endwhile */
+
+                /* if overflow occurred		*/
+                if ( dblval == HUGE_VAL )
+                {
+                    errno = ERANGE;
+                    err = 1;
+                } /* endif */
+            } /* endif */
+
+            if ( !err )
+            {
+                rslt = (numeric_ptr)calloc(1, sizeof(numeric));
+                rslt->type = DBL_TYPE;
+                rslt->value.dbl_value = dblval;
+            } /* endif */
+        }
+        else
+        {
+            if ( (!sign && (inum == LONG_MIN)) || err )
+            {
+                inum = LONG_MIN + sign;
+                errno = ERANGE;
+            }
+            else
+            {
+                rslt = (numeric_ptr)calloc(1, sizeof(numeric));
+                rslt->type = INT_TYPE;
+                rslt->value.int_value = inum;
+            } /* endif */
+        } /* endif */
     } /* endif */
-	
-	if ( endstr ) {
-	   if ( !digit_cnt ) *endstr = (char *) strinit;
-	     else *endstr = (char *) str;
-	} /* endif */
-	
-	return (void *)rslt;
+
+    if ( endstr )
+    {
+        if ( !digit_cnt ) *endstr = (char *) strinit;
+        else *endstr = (char *) str;
+    } /* endif */
+
+    return (void *)rslt;
 } /* strtod_flt */
 
 /* function to free memory used by numeric structure
  */
 void  free_numeric(
-void *numeric_value)
+    void *numeric_value)
 {
-	if ( numeric_value ) free(numeric_value);
+    if ( numeric_value ) free(numeric_value);
 } /* free_numeric */
 
 /* function to perform unary '-' operation
  */
 void *negate_numeric(
-void *value)
+    void *value)
 {
-	numeric_ptr rslt = (numeric_ptr)value;
-	
-	switch ( rslt->type ) {
-        case INT_TYPE:
-            rslt->value.int_value = -rslt->value.int_value;
-            break;
-        case DBL_TYPE:
-            rslt->value.dbl_value = -rslt->value.dbl_value;
-            break;
+    numeric_ptr rslt = (numeric_ptr)value;
+
+    switch ( rslt->type )
+    {
+    case INT_TYPE:
+        rslt->value.int_value = -rslt->value.int_value;
+        break;
+    case DBL_TYPE:
+        rslt->value.dbl_value = -rslt->value.dbl_value;
+        break;
     } /* endswitch */
 
     return (void *)rslt;
@@ -270,118 +301,139 @@
  *  r_value - pointer to right hand value
  */
 void          *numeric_ops(
-                           char  op_symbol,
-                           void *l_value,
-                           void *r_value)
+    char  op_symbol,
+    void *l_value,
+    void *r_value)
 {
-	numeric_ptr lval = (numeric_ptr)l_value,
-				rval = (numeric_ptr)r_value,
-				rslt = (op_symbol == ASN_OP) ? lval : (numeric_ptr)calloc(1,sizeof(numeric));
-				
-	switch ( op_symbol ) {
-		case ADD_OP:
-			if ( lval->type == rval->type ) {
-				rslt->type = lval->type;
-				switch ( lval->type ) {
-             		case INT_TYPE:
-		  				rslt->value.int_value = lval->value.int_value + rval->value.int_value;
-                 		break;
-             		case DBL_TYPE:
-                 		rslt->value.dbl_value = lval->value.dbl_value + rval->value.dbl_value;
-                 		break;
-               	} /* endswitch */
-        	  } else {
-        	  	rslt->type = DBL_TYPE;
-        	  	switch ( lval->type ) {
-            		case INT_TYPE:
-                		rslt->value.dbl_value = (double)(lval->value.int_value) + rval->value.dbl_value;
-                		break;
-            		case DBL_TYPE:
-                		rslt->value.dbl_value = lval->value.dbl_value + (double)(rval->value.int_value);
-                		break;
-                		
-		   		} /* endswitch */
-        	} /* endif */
-			break;
-		case SUB_OP:
-			if ( lval->type == rval->type ) {
-				rslt->type = lval->type;
-				switch ( lval->type ) {
-             		case INT_TYPE:
-		  				rslt->value.int_value = lval->value.int_value - rval->value.int_value;
-                 		break;
-             		case DBL_TYPE:
-                 		rslt->value.dbl_value = lval->value.dbl_value - rval->value.dbl_value;
-                 		break;
-               	} /* endswitch */
-        	  } else {
-        	  	rslt->type = DBL_TYPE;
-        	  	switch ( lval->type ) {
-            		case INT_TYPE:
-                		rslt->value.dbl_value = (double)(lval->value.int_value) - rval->value.dbl_value;
-                		break;
-            		case DBL_TYPE:
-                		rslt->value.dbl_value = lval->value.dbl_value - (double)(rval->value.int_value);
-                		break;
-                		
-		   		} /* endswitch */
-        	} /* endif */		
-			break;
-		case DIV_OP:
-			rslt->type = DBL_TYPE;
-			if ( lval->type == rval->type ) {
-				switch ( lval->type ) {
-             		case INT_TYPE:
-		  				rslt->value.dbl_value = (double)(lval->value.int_value) / (double)(rval->value.int_value);
-                 		break;
-             		case DBL_TYPE:
-                 		rslt->value.dbl_value = lval->value.dbl_value / rval->value.dbl_value;
-                 		break;
-               	} /* endswitch */
-        	  } else {
-        	  	switch ( lval->type ) {
-            		case INT_TYPE:
-                		rslt->value.dbl_value = (double)(lval->value.int_value) / rval->value.dbl_value;
-                		break;
-            		case DBL_TYPE:
-                		rslt->value.dbl_value = lval->value.dbl_value / (double)(rval->value.int_value);
-                		break;
-                		
-		   		} /* endswitch */
-        	} /* endif */				
-			break;
-		case MUL_OP:
-			if ( lval->type == rval->type ) {
-				rslt->type = lval->type;
-				switch ( lval->type ) {
-             		case INT_TYPE:
-		  				rslt->value.int_value = lval->value.int_value * rval->value.int_value;
-                 		break;
-             		case DBL_TYPE:
-                 		rslt->value.dbl_value = lval->value.dbl_value * rval->value.dbl_value;
-                 		break;
-               	} /* endswitch */
-        	  } else {
-        	  	rslt->type = DBL_TYPE;
-        	  	switch ( lval->type ) {
-            		case INT_TYPE:
-                		rslt->value.dbl_value = (double)(lval->value.int_value) * rval->value.dbl_value;
-                		break;
-            		case DBL_TYPE:
-                		rslt->value.dbl_value = lval->value.dbl_value * (double)(rval->value.int_value);
-                		break;
-                		
-		   		} /* endswitch */
-        	} /* endif */			
-			break;
-		case ASN_OP:
-			if ( !lval ) lval = (numeric_ptr)calloc(1,sizeof(numeric));
-			lval->type = rval->type;
-			lval->value = rval->value;
-			rslt = lval;
-			break;
-	} /* endswitch */
-	
-	
-	return (void *)rslt;
+    numeric_ptr lval = (numeric_ptr)l_value,
+                       rval = (numeric_ptr)r_value,
+                              rslt = (op_symbol == ASN_OP) ? lval : (numeric_ptr)calloc(1, sizeof(numeric));
+
+    switch ( op_symbol )
+    {
+    case ADD_OP:
+        if ( lval->type == rval->type )
+        {
+            rslt->type = lval->type;
+            switch ( lval->type )
+            {
+            case INT_TYPE:
+                rslt->value.int_value = lval->value.int_value + rval->value.int_value;
+                break;
+            case DBL_TYPE:
+                rslt->value.dbl_value = lval->value.dbl_value + rval->value.dbl_value;
+                break;
+            } /* endswitch */
+        }
+        else
+        {
+            rslt->type = DBL_TYPE;
+            switch ( lval->type )
+            {
+            case INT_TYPE:
+                rslt->value.dbl_value = (double)(lval->value.int_value) + rval->value.dbl_value;
+                break;
+            case DBL_TYPE:
+                rslt->value.dbl_value = lval->value.dbl_value + (double)(rval->value.int_value);
+                break;
+
+            } /* endswitch */
+        } /* endif */
+        break;
+    case SUB_OP:
+        if ( lval->type == rval->type )
+        {
+            rslt->type = lval->type;
+            switch ( lval->type )
+            {
+            case INT_TYPE:
+                rslt->value.int_value = lval->value.int_value - rval->value.int_value;
+                break;
+            case DBL_TYPE:
+                rslt->value.dbl_value = lval->value.dbl_value - rval->value.dbl_value;
+                break;
+            } /* endswitch */
+        }
+        else
+        {
+            rslt->type = DBL_TYPE;
+            switch ( lval->type )
+            {
+            case INT_TYPE:
+                rslt->value.dbl_value = (double)(lval->value.int_value) - rval->value.dbl_value;
+                break;
+            case DBL_TYPE:
+                rslt->value.dbl_value = lval->value.dbl_value - (double)(rval->value.int_value);
+                break;
+
+            } /* endswitch */
+        } /* endif */
+        break;
+    case DIV_OP:
+        rslt->type = DBL_TYPE;
+        if ( lval->type == rval->type )
+        {
+            switch ( lval->type )
+            {
+            case INT_TYPE:
+                rslt->value.dbl_value = (double)(lval->value.int_value) / (double)(rval->value.int_value);
+                break;
+            case DBL_TYPE:
+                rslt->value.dbl_value = lval->value.dbl_value / rval->value.dbl_value;
+                break;
+            } /* endswitch */
+        }
+        else
+        {
+            switch ( lval->type )
+            {
+            case INT_TYPE:
+                rslt->value.dbl_value = (double)(lval->value.int_value) / rval->value.dbl_value;
+                break;
+            case DBL_TYPE:
+                rslt->value.dbl_value = lval->value.dbl_value / (double)(rval->value.int_value);
+                break;
+
+            } /* endswitch */
+        } /* endif */
+        break;
+    case MUL_OP:
+        if ( lval->type == rval->type )
+        {
+            rslt->type = lval->type;
+            switch ( lval->type )
+            {
+            case INT_TYPE:
+                rslt->value.int_value = lval->value.int_value * rval->value.int_value;
+                break;
+            case DBL_TYPE:
+                rslt->value.dbl_value = lval->value.dbl_value * rval->value.dbl_value;
+                break;
+            } /* endswitch */
+        }
+        else
+        {
+            rslt->type = DBL_TYPE;
+            switch ( lval->type )
+            {
+            case INT_TYPE:
+                rslt->value.dbl_value = (double)(lval->value.int_value) * rval->value.dbl_value;
+                break;
+            case DBL_TYPE:
+                rslt->value.dbl_value = lval->value.dbl_value * (double)(rval->value.int_value);
+                break;
+
+            } /* endswitch */
+        } /* endif */
+        break;
+    case ASN_OP:
+        if ( !lval ) lval = (numeric_ptr)calloc(1, sizeof(numeric));
+        lval->type = rval->type;
+        lval->value = rval->value;
+        rslt = lval;
+        break;
+    } /* endswitch */
+
+
+    return (void *)rslt;
 } /* numeric_ops */

Modified: gnucash/trunk/src/calculation/test/test-link.c
===================================================================
--- gnucash/trunk/src/calculation/test/test-link.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/calculation/test/test-link.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -1,6 +1,6 @@
 int
-main(int argc, char ** argv) 
+main(int argc, char ** argv)
 {
-  return 0;
+    return 0;
 }
 

Modified: gnucash/trunk/src/core-utils/gnc-gconf-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gconf-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-gconf-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -41,71 +41,83 @@
 
 const gchar *
 gnc_enum_to_nick(GType type,
-		 gint value)
+                 gint value)
 {
-  GEnumClass   	    *enum_class;
-  GEnumValue   	    *enum_value;
+    GEnumClass   	    *enum_class;
+    GEnumValue   	    *enum_value;
 
-  /* Lookup the enum in the glib type system */
-  enum_class = g_type_class_ref (type);
-  if (!enum_class) {
-    /* g_type_class_ref has already printed a warning. */
-    return NULL;
-  }
+    /* Lookup the enum in the glib type system */
+    enum_class = g_type_class_ref (type);
+    if (!enum_class)
+    {
+        /* g_type_class_ref has already printed a warning. */
+        return NULL;
+    }
 
-  enum_value = g_enum_get_value (enum_class, value);
-  if (!enum_value) {
-    /* Use the first item in the enum */
-    enum_value = g_enum_get_value (enum_class, 0);
-  }
-  return enum_value->value_nick;
+    enum_value = g_enum_get_value (enum_class, value);
+    if (!enum_value)
+    {
+        /* Use the first item in the enum */
+        enum_value = g_enum_get_value (enum_class, 0);
+    }
+    return enum_value->value_nick;
 }
 
 gint
 gnc_enum_from_nick(GType type,
-		   const gchar *name,
-		   gint default_value)
+                   const gchar *name,
+                   gint default_value)
 {
-  GEnumClass   *enum_class;
-  GEnumValue   *enum_value;
-  gchar        *alt_name, *ptr;
+    GEnumClass   *enum_class;
+    GEnumValue   *enum_value;
+    gchar        *alt_name, *ptr;
 
-  if (name == NULL)
-    return default_value;
+    if (name == NULL)
+        return default_value;
 
-  /* Lookup the enum class in the glib type system */
-  enum_class = g_type_class_ref (type);
-  if (!enum_class) {
-    /* g_type_class_ref has already printed a warning. */
-    return default_value;
-  }
+    /* Lookup the enum class in the glib type system */
+    enum_class = g_type_class_ref (type);
+    if (!enum_class)
+    {
+        /* g_type_class_ref has already printed a warning. */
+        return default_value;
+    }
 
-  /* Lookup the specified enum in the class */
-  enum_value = g_enum_get_value_by_nick(enum_class, name);
-  if (enum_value)
-    return enum_value->value;
+    /* Lookup the specified enum in the class */
+    enum_value = g_enum_get_value_by_nick(enum_class, name);
+    if (enum_value)
+        return enum_value->value;
 
-  /* Flip '-' and '_' and try again */
-  alt_name = g_strdup(name);
-  if ((ptr = strchr(alt_name, '-')) != NULL) {
-    do {
-      *ptr++ = '_';
-    } while ((ptr = strchr(ptr, '-')) != NULL);
-  } else  if ((ptr = strchr(alt_name, '_')) != NULL) {
-    do {
-      *ptr++ = '-';
-    } while ((ptr = strchr(ptr, '_')) != NULL);
-  } else {
+    /* Flip '-' and '_' and try again */
+    alt_name = g_strdup(name);
+    if ((ptr = strchr(alt_name, '-')) != NULL)
+    {
+        do
+        {
+            *ptr++ = '_';
+        }
+        while ((ptr = strchr(ptr, '-')) != NULL);
+    }
+    else  if ((ptr = strchr(alt_name, '_')) != NULL)
+    {
+        do
+        {
+            *ptr++ = '-';
+        }
+        while ((ptr = strchr(ptr, '_')) != NULL);
+    }
+    else
+    {
+        g_free(alt_name);
+        return default_value;
+    }
+
+    /* Lookup the specified enum in the class */
+    enum_value = g_enum_get_value_by_nick(enum_class, alt_name);
     g_free(alt_name);
+    if (enum_value)
+        return enum_value->value;
     return default_value;
-  }
-
-  /* Lookup the specified enum in the class */
-  enum_value = g_enum_get_value_by_nick(enum_class, alt_name);
-  g_free(alt_name);
-  if (enum_value)
-    return enum_value->value;
-  return default_value;
 }
 
 /************************************************************/
@@ -119,130 +131,135 @@
 static gpointer
 gcb_init (gpointer unused)
 {
-  gcb_callback_hash = g_hash_table_new(g_str_hash, g_str_equal);
+    gcb_callback_hash = g_hash_table_new(g_str_hash, g_str_equal);
 
-  gcb_final_hook_list = g_malloc(sizeof(GHookList));
-  g_hook_list_init(gcb_final_hook_list, sizeof(GHook));
-  return NULL;
+    gcb_final_hook_list = g_malloc(sizeof(GHookList));
+    g_hook_list_init(gcb_final_hook_list, sizeof(GHook));
+    return NULL;
 }
 
 static void
 gcb_call_hook (GHook *hook, gpointer data)
 {
-  ((GFunc)hook->func)(data, hook->data);
+    ((GFunc)hook->func)(data, hook->data);
 }
 
 static void
 gnc_gconf_general_changed (GConfClient *client,
-			   guint cnxn_id,
-			   GConfEntry *entry,
-			   gpointer data)
+                           guint cnxn_id,
+                           GConfEntry *entry,
+                           gpointer data)
 {
-  const gchar *key, *key_tail;
-  GHookList *hook_list;
+    const gchar *key, *key_tail;
+    GHookList *hook_list;
 
-  g_once(&gcb_init_once, gcb_init, NULL);
+    g_once(&gcb_init_once, gcb_init, NULL);
 
-  key = gconf_entry_get_key(entry);
-  key_tail = strrchr(key, '/');
-  if (key_tail != NULL) {
-    key_tail++;
-  }
-  if (key_tail == NULL) {
-    /* Should never happen. */
-    g_warning("Malformed key %s:",key);
-    return;
-  }
+    key = gconf_entry_get_key(entry);
+    key_tail = strrchr(key, '/');
+    if (key_tail != NULL)
+    {
+        key_tail++;
+    }
+    if (key_tail == NULL)
+    {
+        /* Should never happen. */
+        g_warning("Malformed key %s:", key);
+        return;
+    }
 
-  hook_list = g_hash_table_lookup(gcb_callback_hash, key_tail);
-  if (hook_list != NULL)
-    g_hook_list_marshal(hook_list, TRUE, gcb_call_hook, entry);
-  g_hook_list_invoke(gcb_final_hook_list, TRUE);
+    hook_list = g_hash_table_lookup(gcb_callback_hash, key_tail);
+    if (hook_list != NULL)
+        g_hook_list_marshal(hook_list, TRUE, gcb_call_hook, entry);
+    g_hook_list_invoke(gcb_final_hook_list, TRUE);
 }
 
 
 void
 gnc_gconf_general_register_cb (const gchar *key,
-			       GncGconfGeneralCb func,
-			       gpointer user_data)
+                               GncGconfGeneralCb func,
+                               gpointer user_data)
 {
-  GHookList *hook_list;
-  GHook *hook;
+    GHookList *hook_list;
+    GHook *hook;
 
-  g_once(&gcb_init_once, gcb_init, NULL);
-  hook_list = g_hash_table_lookup(gcb_callback_hash, key);
-  if (hook_list == NULL) {
-    hook_list = g_malloc(sizeof(GHookList));
-    g_hook_list_init(hook_list, sizeof(GHook));
-    g_hash_table_insert(gcb_callback_hash, (gpointer)key, hook_list);
-  }
+    g_once(&gcb_init_once, gcb_init, NULL);
+    hook_list = g_hash_table_lookup(gcb_callback_hash, key);
+    if (hook_list == NULL)
+    {
+        hook_list = g_malloc(sizeof(GHookList));
+        g_hook_list_init(hook_list, sizeof(GHook));
+        g_hash_table_insert(gcb_callback_hash, (gpointer)key, hook_list);
+    }
 
-  hook = g_hook_find_func_data(hook_list, TRUE, func, user_data);
-  if (hook != NULL) {
-    return;
-  }
+    hook = g_hook_find_func_data(hook_list, TRUE, func, user_data);
+    if (hook != NULL)
+    {
+        return;
+    }
 
-  hook = g_hook_alloc(hook_list);
-  hook->func = func;
-  hook->data = user_data;
-  g_hook_append(hook_list, hook);
+    hook = g_hook_alloc(hook_list);
+    hook->func = func;
+    hook->data = user_data;
+    g_hook_append(hook_list, hook);
 }
 
 
 void
 gnc_gconf_general_remove_cb (const gchar *key,
-			     GncGconfGeneralCb func,
-			     gpointer user_data)
+                             GncGconfGeneralCb func,
+                             gpointer user_data)
 {
-  GHookList *hook_list;
-  GHook *hook;
+    GHookList *hook_list;
+    GHook *hook;
 
-  g_once(&gcb_init_once, gcb_init, NULL);
-  hook_list = g_hash_table_lookup(gcb_callback_hash, key);
-  if (hook_list == NULL)
-    return;
-  hook = g_hook_find_func_data(hook_list, TRUE, func, user_data);
-  if (hook == NULL)
-    return;
+    g_once(&gcb_init_once, gcb_init, NULL);
+    hook_list = g_hash_table_lookup(gcb_callback_hash, key);
+    if (hook_list == NULL)
+        return;
+    hook = g_hook_find_func_data(hook_list, TRUE, func, user_data);
+    if (hook == NULL)
+        return;
 
-  g_hook_destroy_link(hook_list, hook);
-  if (hook_list->hooks == NULL) {
-    g_hash_table_remove(gcb_callback_hash, key);
-    g_free(hook_list);
-  }
+    g_hook_destroy_link(hook_list, hook);
+    if (hook_list->hooks == NULL)
+    {
+        g_hash_table_remove(gcb_callback_hash, key);
+        g_free(hook_list);
+    }
 }
 
 
 void
 gnc_gconf_general_register_any_cb (GncGconfGeneralAnyCb func,
-				   gpointer user_data)
+                                   gpointer user_data)
 {
-  GHook *hook;
+    GHook *hook;
 
-  g_once(&gcb_init_once, gcb_init, NULL);
-  hook = g_hook_find_func_data(gcb_final_hook_list, TRUE, func, user_data);
-  if (hook != NULL)
-    return;
+    g_once(&gcb_init_once, gcb_init, NULL);
+    hook = g_hook_find_func_data(gcb_final_hook_list, TRUE, func, user_data);
+    if (hook != NULL)
+        return;
 
-  hook = g_hook_alloc(gcb_final_hook_list);
-  hook->func = func;
-  hook->data = user_data;
-  g_hook_append(gcb_final_hook_list, hook);
+    hook = g_hook_alloc(gcb_final_hook_list);
+    hook->func = func;
+    hook->data = user_data;
+    g_hook_append(gcb_final_hook_list, hook);
 }
 
 
 void
 gnc_gconf_general_remove_any_cb (GncGconfGeneralAnyCb func,
-				 gpointer user_data)
+                                 gpointer user_data)
 {
-  GHook *hook;
+    GHook *hook;
 
-  g_once(&gcb_init_once, gcb_init, NULL);
-  hook = g_hook_find_func_data(gcb_final_hook_list, TRUE, func, user_data);
-  if (hook == NULL)
-    return;
+    g_once(&gcb_init_once, gcb_init, NULL);
+    hook = g_hook_find_func_data(gcb_final_hook_list, TRUE, func, user_data);
+    if (hook == NULL)
+        return;
 
-  g_hook_unref(gcb_final_hook_list, hook);
+    g_hook_unref(gcb_final_hook_list, hook);
 }
 
 
@@ -253,84 +270,90 @@
 char *
 gnc_gconf_section_name (const char *name)
 {
-  if (name == NULL) {
-    /* Need to return a newly allocated string */
-    return g_strdup(gnc_get_gconf_path());
-  }
-  if (*name == '/') {
-    /* Need to return a newly allocated string */
-    return g_strdup(name);
-  }
+    if (name == NULL)
+    {
+        /* Need to return a newly allocated string */
+        return g_strdup(gnc_get_gconf_path());
+    }
+    if (*name == '/')
+    {
+        /* Need to return a newly allocated string */
+        return g_strdup(name);
+    }
 
-  /* This could (should?) be accomplished with a call to
-   * gnome_gconf_get_app_settings_relative(), but that would introduce
-   * a new library dependancy, even though its not a gui library.  In
-   * order to keep this file completely "gnome-free" this approach was
-   * used.
-   */
-  return g_strjoin("/", gnc_get_gconf_path(), name, NULL);
+    /* This could (should?) be accomplished with a call to
+     * gnome_gconf_get_app_settings_relative(), but that would introduce
+     * a new library dependancy, even though its not a gui library.  In
+     * order to keep this file completely "gnome-free" this approach was
+     * used.
+     */
+    return g_strjoin("/", gnc_get_gconf_path(), name, NULL);
 }
 
 char *
 gnc_gconf_schema_section_name (const char *name)
 {
-  if (strncmp(name, "/schemas", sizeof("/schemas")) == 0) {
-    /* Need to return a newly allocated string */
-    return g_strdup(name);
-  }
+    if (strncmp(name, "/schemas", sizeof("/schemas")) == 0)
+    {
+        /* Need to return a newly allocated string */
+        return g_strdup(name);
+    }
 
-  /* This could (should?) be accomplished with a call to
-   * gnome_gconf_get_app_settings_relative(), but that would introduce
-   * a new library dependancy, even though its not a gui library.  In
-   * order to keep this file completely "gnome-free" this approach was
-   * used.
-   */
-  return g_strconcat("/schemas", gnc_get_gconf_path(), "/", name, NULL);
+    /* This could (should?) be accomplished with a call to
+     * gnome_gconf_get_app_settings_relative(), but that would introduce
+     * a new library dependancy, even though its not a gui library.  In
+     * order to keep this file completely "gnome-free" this approach was
+     * used.
+     */
+    return g_strconcat("/schemas", gnc_get_gconf_path(), "/", name, NULL);
 }
 
 static gchar *
 gnc_gconf_make_key (const gchar *section, const gchar *name)
 {
-  gchar *section_path, *key;
+    gchar *section_path, *key;
 
-  g_assert ((section != NULL) || (name != NULL));
+    g_assert ((section != NULL) || (name != NULL));
 
-  if (section == NULL) {
-    if (*name == '/')
-      return g_strdup(name);
-    return gnc_gconf_section_name(name);
-  }
-    
-  if (name == NULL) {
+    if (section == NULL)
+    {
+        if (*name == '/')
+            return g_strdup(name);
+        return gnc_gconf_section_name(name);
+    }
+
+    if (name == NULL)
+    {
+        if (*section == '/')
+            return g_strdup(section);
+        return gnc_gconf_section_name(section);
+    }
+
     if (*section == '/')
-      return g_strdup(section);
-    return gnc_gconf_section_name(section);
-  }
+    {
+        if (*name == '/')
+            return g_strjoin(NULL, section, name, NULL);
+        return g_strjoin("/", section, name, NULL);
+    }
 
-  if (*section == '/') {
-    if (*name == '/')
-      return g_strjoin(NULL, section, name, NULL);
-    return g_strjoin("/", section, name, NULL);
-  }
-
-  section_path = gnc_gconf_section_name(section);
-  key = g_strjoin("/", section_path, name, NULL);
-  g_free(section_path);
-  return key;
+    section_path = gnc_gconf_section_name(section);
+    key = g_strjoin("/", section_path, name, NULL);
+    g_free(section_path);
+    return key;
 }
 
 
 static gchar *
 gnc_gconf_make_schema_key (const gchar *section, const gchar *name)
 {
-  gchar *intermediate, *key;
+    gchar *intermediate, *key;
 
-  g_assert ((section != NULL) || (name != NULL));
+    g_assert ((section != NULL) || (name != NULL));
 
-  intermediate = gnc_gconf_make_key(section, name);
-  key = g_strconcat("/schemas", intermediate, NULL);
-  g_free(intermediate);
-  return key;
+    intermediate = gnc_gconf_make_key(section, name);
+    key = g_strconcat("/schemas", intermediate, NULL);
+    g_free(intermediate);
+    return key;
 }
 
 
@@ -353,15 +376,18 @@
  */
 static void
 gnc_gconf_load_error (const gchar *key,
-		      GError **caller_error,
-		      GError *error)
+                      GError **caller_error,
+                      GError *error)
 {
-  if (caller_error) {
-    g_propagate_error(caller_error, error);
-  } else {
-    printf("Failed to load key %s: %s", key, error->message);
-    g_error_free(error);
-  }
+    if (caller_error)
+    {
+        g_propagate_error(caller_error, error);
+    }
+    else
+    {
+        printf("Failed to load key %s: %s", key, error->message);
+        g_error_free(error);
+    }
 }
 
 
@@ -384,514 +410,552 @@
  */
 static void
 gnc_gconf_save_error (const gchar *key,
-		      GError **caller_error,
-		      GError *error)
+                      GError **caller_error,
+                      GError *error)
 {
-  if (caller_error) {
-    g_propagate_error(caller_error, error);
-  } else if (error) {
-    printf("Failed to save key %s: %s", key, error->message);
-    g_error_free(error);
-  } else {
-    printf("Failed to save key %s: %s", key, "Unknown error");
-  }
+    if (caller_error)
+    {
+        g_propagate_error(caller_error, error);
+    }
+    else if (error)
+    {
+        printf("Failed to save key %s: %s", key, error->message);
+        g_error_free(error);
+    }
+    else
+    {
+        printf("Failed to save key %s: %s", key, "Unknown error");
+    }
 }
 
 
 gboolean
 gnc_gconf_get_bool (const gchar *section,
-		    const gchar *name,
-		    GError **caller_error)
+                    const gchar *name,
+                    GError **caller_error)
 {
-  GError *error = NULL;
-  gboolean value;
-  gchar *key;
+    GError *error = NULL;
+    gboolean value;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  key = gnc_gconf_make_key(section, name);
-  value = gconf_client_get_bool(our_client, key, &error);
-  if (error) {
-    gnc_gconf_load_error(key, caller_error, error);
-  }
-  g_free(key);
-  return value;
+    key = gnc_gconf_make_key(section, name);
+    value = gconf_client_get_bool(our_client, key, &error);
+    if (error)
+    {
+        gnc_gconf_load_error(key, caller_error, error);
+    }
+    g_free(key);
+    return value;
 }
 
 gboolean
 gnc_gconf_get_bool_no_error (const gchar *section,
-			     const gchar *name)
+                             const gchar *name)
 {
-  return gnc_gconf_get_bool(section, name, NULL);
+    return gnc_gconf_get_bool(section, name, NULL);
 }
 
 void
 gnc_gconf_set_bool (const gchar *section,
-		    const gchar *name,
-		    const gboolean value,
-		    GError **caller_error)
+                    const gchar *name,
+                    const gboolean value,
+                    GError **caller_error)
 {
-  GError *error = NULL;
-  gchar *key;
+    GError *error = NULL;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  /* Remember whether the column width */
-  key = gnc_gconf_make_key(section, name);
-  if (!gconf_client_set_bool(our_client, key, value, &error)) {
-    gnc_gconf_save_error(key, caller_error, error);
-  }
-  g_free(key);
+    /* Remember whether the column width */
+    key = gnc_gconf_make_key(section, name);
+    if (!gconf_client_set_bool(our_client, key, value, &error))
+    {
+        gnc_gconf_save_error(key, caller_error, error);
+    }
+    g_free(key);
 }
 
 gint
 gnc_gconf_get_int (const gchar *section,
-		   const gchar *name,
-		   GError **caller_error)
+                   const gchar *name,
+                   GError **caller_error)
 {
-  GError *error = NULL;
-  gint value;
-  gchar *key;
+    GError *error = NULL;
+    gint value;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  key = gnc_gconf_make_key(section, name);
-  value = gconf_client_get_int(our_client, key, &error);
-  if (error) {
-    gnc_gconf_load_error(key, caller_error, error);
-  }
-  g_free(key);
-  return value;
+    key = gnc_gconf_make_key(section, name);
+    value = gconf_client_get_int(our_client, key, &error);
+    if (error)
+    {
+        gnc_gconf_load_error(key, caller_error, error);
+    }
+    g_free(key);
+    return value;
 }
 
 void
 gnc_gconf_set_int (const gchar *section,
-		   const gchar *name,
-		   const gint value,
-		   GError **caller_error)
+                   const gchar *name,
+                   const gint value,
+                   GError **caller_error)
 {
-  GError *error = NULL;
-  gchar *key;
+    GError *error = NULL;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  /* Remember whether the column width */
-  key = gnc_gconf_make_key(section, name);
-  if (!gconf_client_set_int(our_client, key, value, &error)) {
-    gnc_gconf_save_error(key, caller_error, error);
-  }
-  g_free(key);
+    /* Remember whether the column width */
+    key = gnc_gconf_make_key(section, name);
+    if (!gconf_client_set_int(our_client, key, value, &error))
+    {
+        gnc_gconf_save_error(key, caller_error, error);
+    }
+    g_free(key);
 }
 
 gdouble
 gnc_gconf_get_float (const gchar *section,
-		     const gchar *name,
-		     GError **caller_error)
+                     const gchar *name,
+                     GError **caller_error)
 {
-  GError *error = NULL;
-  gint value;
-  gchar *key;
+    GError *error = NULL;
+    gint value;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  key = gnc_gconf_make_key(section, name);
-  value = gconf_client_get_float(our_client, key, &error);
-  if (error) {
-    gnc_gconf_load_error(key, caller_error, error);
-  }
-  g_free(key);
-  return value;
+    key = gnc_gconf_make_key(section, name);
+    value = gconf_client_get_float(our_client, key, &error);
+    if (error)
+    {
+        gnc_gconf_load_error(key, caller_error, error);
+    }
+    g_free(key);
+    return value;
 }
 
 void
 gnc_gconf_set_float (const gchar *section,
-		     const gchar *name,
-		     const gdouble value,
-		     GError **caller_error)
+                     const gchar *name,
+                     const gdouble value,
+                     GError **caller_error)
 {
-  GError *error = NULL;
-  gchar *key;
+    GError *error = NULL;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  /* Remember whether the column width */
-  key = gnc_gconf_make_key(section, name);
-  if (!gconf_client_set_float(our_client, key, value, &error)) {
-    gnc_gconf_save_error(key, caller_error, error);
-  }
-  g_free(key);
+    /* Remember whether the column width */
+    key = gnc_gconf_make_key(section, name);
+    if (!gconf_client_set_float(our_client, key, value, &error))
+    {
+        gnc_gconf_save_error(key, caller_error, error);
+    }
+    g_free(key);
 }
 
 gchar *
 gnc_gconf_get_string (const gchar *section,
-		      const gchar *name,
-		      GError **caller_error)
+                      const gchar *name,
+                      GError **caller_error)
 {
-  GError *error = NULL;
-  gchar *value;
-  gchar *key;
+    GError *error = NULL;
+    gchar *value;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  key = gnc_gconf_make_key(section, name);
-  value = gconf_client_get_string(our_client, key, &error);
-  if (error) {
-    gnc_gconf_load_error(key, caller_error, error);
-  }
-  g_free(key);
+    key = gnc_gconf_make_key(section, name);
+    value = gconf_client_get_string(our_client, key, &error);
+    if (error)
+    {
+        gnc_gconf_load_error(key, caller_error, error);
+    }
+    g_free(key);
 
-  if (value && strlen(value) == 0) {
-    g_free(value);
-    return NULL;
-  }
-  return value;
+    if (value && strlen(value) == 0)
+    {
+        g_free(value);
+        return NULL;
+    }
+    return value;
 }
 
 void
 gnc_gconf_set_string (const gchar *section,
-		      const gchar *name,
-		      const gchar *value,
-		      GError **caller_error)
+                      const gchar *name,
+                      const gchar *value,
+                      GError **caller_error)
 {
-  GError *error = NULL;
-  gchar *key;
+    GError *error = NULL;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  key = gnc_gconf_make_key(section, name);
-  if (!gconf_client_set_string(our_client, key, value, &error)) {
-    gnc_gconf_save_error(key, caller_error, error);
-  }
-  g_free(key);
+    key = gnc_gconf_make_key(section, name);
+    if (!gconf_client_set_string(our_client, key, value, &error))
+    {
+        gnc_gconf_save_error(key, caller_error, error);
+    }
+    g_free(key);
 }
 
 GSList *
 gnc_gconf_get_list (const gchar *section,
-		    const gchar *name,
-		    GConfValueType list_type,
-		    GError **caller_error)
+                    const gchar *name,
+                    GConfValueType list_type,
+                    GError **caller_error)
 {
-  GError *error = NULL;
-  GSList *value;
-  gchar *key;
+    GError *error = NULL;
+    GSList *value;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  key = gnc_gconf_make_key(section, name);
-  value = gconf_client_get_list(our_client, key, list_type, &error);
-  if (error) {
-    gnc_gconf_load_error(key, caller_error, error);
-  }
-  g_free(key);
-  return value;
+    key = gnc_gconf_make_key(section, name);
+    value = gconf_client_get_list(our_client, key, list_type, &error);
+    if (error)
+    {
+        gnc_gconf_load_error(key, caller_error, error);
+    }
+    g_free(key);
+    return value;
 }
 
 void
 gnc_gconf_set_list (const gchar *section,
-		    const gchar *name,
-		    GConfValueType list_type,
-		    GSList *value,
-		    GError **caller_error)
+                    const gchar *name,
+                    GConfValueType list_type,
+                    GSList *value,
+                    GError **caller_error)
 {
-  GError *error = NULL;
-  gchar *key;
+    GError *error = NULL;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  key = gnc_gconf_make_key(section, name);
-  if (!gconf_client_set_list(our_client, key, list_type, value, &error)) {
-    gnc_gconf_save_error(key, caller_error, error);
-  }
-  g_free(key);
+    key = gnc_gconf_make_key(section, name);
+    if (!gconf_client_set_list(our_client, key, list_type, value, &error))
+    {
+        gnc_gconf_save_error(key, caller_error, error);
+    }
+    g_free(key);
 }
 
 GConfSchema *
 gnc_gconf_get_schema (const gchar *section,
-		      const gchar *name,
-		      GError **caller_error)
+                      const gchar *name,
+                      GError **caller_error)
 {
-  GError *error = NULL;
-  GConfSchema *value;
-  gchar *key;
+    GError *error = NULL;
+    GConfSchema *value;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  key = gnc_gconf_make_key(section, name);
-  value = gconf_client_get_schema(our_client, key, &error);
-  if (error) {
-    gnc_gconf_load_error(key, caller_error, error);
-  }
-  g_free(key);
-  return value;
+    key = gnc_gconf_make_key(section, name);
+    value = gconf_client_get_schema(our_client, key, &error);
+    if (error)
+    {
+        gnc_gconf_load_error(key, caller_error, error);
+    }
+    g_free(key);
+    return value;
 }
 
 GSList *
 gnc_gconf_client_all_entries (const gchar *name)
 {
-  GError *error = NULL;
-  GSList *value;
-  gchar *section;
+    GError *error = NULL;
+    GSList *value;
+    gchar *section;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  section = gnc_gconf_section_name(name);
-  value = gconf_client_all_entries(our_client, section, &error);
-  if (error != NULL) {
-    printf("Failed to get list of all gconf keys: %s", error->message);
-    g_error_free(error);
-  }
+    section = gnc_gconf_section_name(name);
+    value = gconf_client_all_entries(our_client, section, &error);
+    if (error != NULL)
+    {
+        printf("Failed to get list of all gconf keys: %s", error->message);
+        g_error_free(error);
+    }
 
-  return value;
+    return value;
 }
 
 void
 gnc_gconf_unset (const gchar *section,
-		 const gchar *name,
-		 GError **caller_error)
+                 const gchar *name,
+                 GError **caller_error)
 {
-  GError *error = NULL;
-  gchar *key;
+    GError *error = NULL;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  key = gnc_gconf_make_key(section, name);
-  if (!gconf_client_unset(our_client, key, &error)) {
-    if (caller_error) {
-      g_propagate_error(caller_error, error);
-    } else {
-      printf("Failed to unset key %s: %s", key, error->message);
-      g_error_free(error);
+    key = gnc_gconf_make_key(section, name);
+    if (!gconf_client_unset(our_client, key, &error))
+    {
+        if (caller_error)
+        {
+            g_propagate_error(caller_error, error);
+        }
+        else
+        {
+            printf("Failed to unset key %s: %s", key, error->message);
+            g_error_free(error);
+        }
     }
-  }
-  g_free(key);
+    g_free(key);
 }
 
 
 void
 gnc_gconf_unset_dir (const gchar *section,
-		     GError **caller_error)
+                     GError **caller_error)
 {
-  GError *error = NULL;
-  GSList *entries, *tmp;
-  const gchar *key;
-  gchar *dir_key;
+    GError *error = NULL;
+    GSList *entries, *tmp;
+    const gchar *key;
+    gchar *dir_key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  dir_key = gnc_gconf_make_key(section, NULL);
-  entries = gconf_client_all_entries(our_client, dir_key, &error);
-  g_free(dir_key);
-  if (error) {
-    if (caller_error) {
-      g_propagate_error(caller_error, error);
-    } else {
-      printf("Failed to get directory entries for key %s: %s",
-	     dir_key, error->message);
-      g_error_free(error);
+    dir_key = gnc_gconf_make_key(section, NULL);
+    entries = gconf_client_all_entries(our_client, dir_key, &error);
+    g_free(dir_key);
+    if (error)
+    {
+        if (caller_error)
+        {
+            g_propagate_error(caller_error, error);
+        }
+        else
+        {
+            printf("Failed to get directory entries for key %s: %s",
+                   dir_key, error->message);
+            g_error_free(error);
+        }
+        return;
     }
-    return;
-  }
 
-  for (tmp = entries; tmp; tmp = g_slist_next(tmp)) {
-    key = gconf_entry_get_key(tmp->data);
-    if (!gconf_client_unset(our_client, key, &error)) {
-      if (caller_error) {
-	g_propagate_error(caller_error, error);
-      } else {
-	printf("Failed to unset key %s: %s", key, error->message);
-	g_error_free(error);
-      }
-      break;
+    for (tmp = entries; tmp; tmp = g_slist_next(tmp))
+    {
+        key = gconf_entry_get_key(tmp->data);
+        if (!gconf_client_unset(our_client, key, &error))
+        {
+            if (caller_error)
+            {
+                g_propagate_error(caller_error, error);
+            }
+            else
+            {
+                printf("Failed to unset key %s: %s", key, error->message);
+                g_error_free(error);
+            }
+            break;
+        }
     }
-  }
 
-  g_slist_foreach(entries, (GFunc)gconf_entry_free, NULL);
-  g_slist_free(entries);
+    g_slist_foreach(entries, (GFunc)gconf_entry_free, NULL);
+    g_slist_free(entries);
 }
 
 
 void
 gnc_gconf_suggest_sync (void)
 {
-  GError *error = NULL;
+    GError *error = NULL;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  gconf_client_suggest_sync(our_client, &error);
-  if (error != NULL) {
-    printf("Failed to sync gconf: %s", error->message);
-    g_error_free(error);
-  }
+    gconf_client_suggest_sync(our_client, &error);
+    if (error != NULL)
+    {
+        printf("Failed to sync gconf: %s", error->message);
+        g_error_free(error);
+    }
 }
 
 
 void
 gnc_gconf_add_notification (GObject *object,
-			    const gchar *section,
-			    GConfClientNotifyFunc callback,
-			    const gchar *whoami)
+                            const gchar *section,
+                            GConfClientNotifyFunc callback,
+                            const gchar *whoami)
 {
-	GConfClient *client;
-	GError *error = NULL;
-	gchar *path, *client_tag, *notify_tag;
-	guint id;
+    GConfClient *client;
+    GError *error = NULL;
+    gchar *path, *client_tag, *notify_tag;
+    guint id;
 
-	g_return_if_fail(G_IS_OBJECT(object));
-	g_return_if_fail(callback != NULL);
-	g_return_if_fail(whoami != NULL);
+    g_return_if_fail(G_IS_OBJECT(object));
+    g_return_if_fail(callback != NULL);
+    g_return_if_fail(whoami != NULL);
 
-	client = gconf_client_get_default();
-	path = gnc_gconf_section_name(section);
+    client = gconf_client_get_default();
+    path = gnc_gconf_section_name(section);
 
-	/*
-	 * First we have to add the directory...
-	 */
-	gconf_client_add_dir(client, path, GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
-	if (error != NULL) {
-	    printf("Failed to add history section to watched directories in gconf: %s", error->message);
-	    g_error_free(error);
-	    g_object_unref(client);
-	    g_free(path);
-	    return;
-	}
+    /*
+     * First we have to add the directory...
+     */
+    gconf_client_add_dir(client, path, GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
+    if (error != NULL)
+    {
+        printf("Failed to add history section to watched directories in gconf: %s", error->message);
+        g_error_free(error);
+        g_object_unref(client);
+        g_free(path);
+        return;
+    }
 
-	/*
-	 * Then we can add the notification callback.
-	 */
-	id = gconf_client_notify_add(client, path, callback,
-				     object, NULL, &error);
-	if (error != NULL) {
-	      printf("Failed to set gconf notify for history section: %s", error->message);
-	      gconf_client_remove_dir(client, path, NULL);
-	      g_error_free(error);
-	      g_object_unref(client);
-	      g_free(path);
-	      return;
-	}
-	
-	/*
-	 * Save the values needed to undo this later.
-	 */
-	client_tag = g_strdup_printf(CLIENT_TAG, section ? section:"", whoami);
-	notify_tag = g_strdup_printf(NOTIFY_TAG, section ? section:"", whoami);
-	g_object_set_data(object, client_tag, client);
-	g_object_set_data(object, notify_tag, GUINT_TO_POINTER(id));
-	g_free(notify_tag);
-	g_free(client_tag);
-	g_free(path);
+    /*
+     * Then we can add the notification callback.
+     */
+    id = gconf_client_notify_add(client, path, callback,
+                                 object, NULL, &error);
+    if (error != NULL)
+    {
+        printf("Failed to set gconf notify for history section: %s", error->message);
+        gconf_client_remove_dir(client, path, NULL);
+        g_error_free(error);
+        g_object_unref(client);
+        g_free(path);
+        return;
+    }
+
+    /*
+     * Save the values needed to undo this later.
+     */
+    client_tag = g_strdup_printf(CLIENT_TAG, section ? section : "", whoami);
+    notify_tag = g_strdup_printf(NOTIFY_TAG, section ? section : "", whoami);
+    g_object_set_data(object, client_tag, client);
+    g_object_set_data(object, notify_tag, GUINT_TO_POINTER(id));
+    g_free(notify_tag);
+    g_free(client_tag);
+    g_free(path);
 }
 
 
 guint
 gnc_gconf_add_anon_notification (const gchar *section,
-				 GConfClientNotifyFunc callback,
-				 gpointer data)
+                                 GConfClientNotifyFunc callback,
+                                 gpointer data)
 {
-	GConfClient *client;
-	GError *error = NULL;
-	gchar *path;
-	guint id;
+    GConfClient *client;
+    GError *error = NULL;
+    gchar *path;
+    guint id;
 
-	g_return_val_if_fail(callback != NULL, 0);
+    g_return_val_if_fail(callback != NULL, 0);
 
-	client = gconf_client_get_default();
-	path = gnc_gconf_section_name(section);
+    client = gconf_client_get_default();
+    path = gnc_gconf_section_name(section);
 
 
-	/*
-	 * First we have to add the directory...
-	 */
-	gconf_client_add_dir(client, path, GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
-	if (error != NULL) {
-	    printf("Failed to add history section to watched directories in gconf: %s", error->message);
-	    g_error_free(error);
-	    g_object_unref(client);
-	    g_free(path);
-	    return 0;
-	}
+    /*
+     * First we have to add the directory...
+     */
+    gconf_client_add_dir(client, path, GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
+    if (error != NULL)
+    {
+        printf("Failed to add history section to watched directories in gconf: %s", error->message);
+        g_error_free(error);
+        g_object_unref(client);
+        g_free(path);
+        return 0;
+    }
 
-	/*
-	 * Then we can add the notification callback.
-	 */
-	id = gconf_client_notify_add(client, path, callback,
-				     data, NULL, &error);
-	if (error != NULL) {
-	      printf("Failed to set gconf notify for history section: %s", error->message);
-	      gconf_client_remove_dir(client, path, NULL);
-	      g_error_free(error);
-	      g_object_unref(client);
-	      g_free(path);
-	      return 0;
-	}
-	g_free(path);
-	return id;
+    /*
+     * Then we can add the notification callback.
+     */
+    id = gconf_client_notify_add(client, path, callback,
+                                 data, NULL, &error);
+    if (error != NULL)
+    {
+        printf("Failed to set gconf notify for history section: %s", error->message);
+        gconf_client_remove_dir(client, path, NULL);
+        g_error_free(error);
+        g_object_unref(client);
+        g_free(path);
+        return 0;
+    }
+    g_free(path);
+    return id;
 }
 
 
 void
 gnc_gconf_remove_notification (GObject *object,
-			       const gchar *section,
-			       const gchar *whoami)
+                               const gchar *section,
+                               const gchar *whoami)
 {
-	GConfClient *client;
-	gchar *path, *client_tag, *notify_tag;
-	guint id;
+    GConfClient *client;
+    gchar *path, *client_tag, *notify_tag;
+    guint id;
 
-	g_return_if_fail(G_IS_OBJECT(object));
-	g_return_if_fail(whoami != NULL);
+    g_return_if_fail(G_IS_OBJECT(object));
+    g_return_if_fail(whoami != NULL);
 
-	/*
-	 * Remove any gconf notifications
-	 */
-	client_tag = g_strdup_printf(CLIENT_TAG, section ? section:"", whoami);
-	client = g_object_get_data(object, client_tag);
-	path = gnc_gconf_section_name(section);
-	if (client) {
-	  notify_tag = g_strdup_printf(NOTIFY_TAG, section ? section:"", whoami);
-	  id = GPOINTER_TO_UINT(g_object_get_data(object, notify_tag));
-	  gconf_client_notify_remove(client, id);
-	  gconf_client_remove_dir(client, path, NULL);
-	  g_object_unref(client);
-	  g_free(notify_tag);
-	}
-	g_free(path);
-	g_free(client_tag);
+    /*
+     * Remove any gconf notifications
+     */
+    client_tag = g_strdup_printf(CLIENT_TAG, section ? section : "", whoami);
+    client = g_object_get_data(object, client_tag);
+    path = gnc_gconf_section_name(section);
+    if (client)
+    {
+        notify_tag = g_strdup_printf(NOTIFY_TAG, section ? section : "", whoami);
+        id = GPOINTER_TO_UINT(g_object_get_data(object, notify_tag));
+        gconf_client_notify_remove(client, id);
+        gconf_client_remove_dir(client, path, NULL);
+        g_object_unref(client);
+        g_free(notify_tag);
+    }
+    g_free(path);
+    g_free(client_tag);
 }
 
 
 void
 gnc_gconf_remove_anon_notification (const gchar *section,
-				    guint cnxn_id)
+                                    guint cnxn_id)
 {
-	GConfClient *client;
-	gchar *path;
+    GConfClient *client;
+    gchar *path;
 
-	/*
-	 * Remove any gconf notifications
-	 */
-	path = gnc_gconf_section_name(section);
-	client = gconf_client_get_default();
-	if (client) {
-	  gconf_client_notify_remove(client, cnxn_id);
-	  gconf_client_remove_dir(client, path, NULL);
-	  g_object_unref(client);
-	}
-	g_free(path);
+    /*
+     * Remove any gconf notifications
+     */
+    path = gnc_gconf_section_name(section);
+    client = gconf_client_get_default();
+    if (client)
+    {
+        gconf_client_notify_remove(client, cnxn_id);
+        gconf_client_remove_dir(client, path, NULL);
+        g_object_unref(client);
+    }
+    g_free(path);
 }
 
 /* ============================================================== */
@@ -899,25 +963,26 @@
 gboolean
 gnc_gconf_schemas_found (void)
 {
-  GConfSchema* schema;
-  GError *err = NULL;
-  gchar *key;
+    GConfSchema* schema;
+    GError *err = NULL;
+    gchar *key;
 
-  if (our_client == NULL)
-    our_client = gconf_client_get_default();
+    if (our_client == NULL)
+        our_client = gconf_client_get_default();
 
-  key = gnc_gconf_make_schema_key(GCONF_GENERAL_REGISTER, "use_theme_colors");
-  schema = gconf_client_get_schema(our_client, key, &err);
-  g_free(key);
-  if (schema == NULL) {
-    return FALSE;
-  }
-  gconf_schema_free(schema);
+    key = gnc_gconf_make_schema_key(GCONF_GENERAL_REGISTER, "use_theme_colors");
+    schema = gconf_client_get_schema(our_client, key, &err);
+    g_free(key);
+    if (schema == NULL)
+    {
+        return FALSE;
+    }
+    gconf_schema_free(schema);
 
-  /* Set up convenience callback for general section */
-  
-  gconf_general_cb_id =
-    gnc_gconf_add_anon_notification(GCONF_GENERAL, gnc_gconf_general_changed,
-				    NULL);
+    /* Set up convenience callback for general section */
+
+    gconf_general_cb_id =
+        gnc_gconf_add_anon_notification(GCONF_GENERAL, gnc_gconf_general_changed,
+                                        NULL);
     return TRUE;
 }

Modified: gnucash/trunk/src/core-utils/gnc-gconf-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gconf-utils.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-gconf-utils.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -30,9 +30,9 @@
     system from within Gnucash.  GConf is a shared key/value storage
     system.
 
-    The main benefits of these routines are that they 
-    -# maintain a GConfClient object, 
-    -# convert gnucash internal section names into full gconf pathnames, and 
+    The main benefits of these routines are that they
+    -# maintain a GConfClient object,
+    -# convert gnucash internal section names into full gconf pathnames, and
     -# optionally take care of error checking on return values.
 
     @{ */
@@ -74,7 +74,7 @@
 
 
 /** @name GConf Miscellaneous Functions
- @{ 
+ @{
 */
 
 /** This function takes an enum value and returns its nickname.
@@ -105,8 +105,8 @@
  *  @return A pointer to the textual "nickname" for this enum.
  */
 gint gnc_enum_from_nick(GType type,
-			const gchar *name,
-			gint default_value);
+                        const gchar *name,
+                        gint default_value);
 
 /** Convert a local key name to a full gconf path name.
  *
@@ -161,8 +161,8 @@
 
 
 
-/** @name GConf "General" Section Convenience Functions 
- @{ 
+/** @name GConf "General" Section Convenience Functions
+ @{
 */
 
 
@@ -181,8 +181,8 @@
  *  function.
  */
 void gnc_gconf_general_register_cb (const gchar *key,
-				    GncGconfGeneralCb func,
-				    gpointer user_data);
+                                    GncGconfGeneralCb func,
+                                    gpointer user_data);
 
 
 /** Remove a function that was registered for a callback when a
@@ -200,8 +200,8 @@
  *  function.
  */
 void gnc_gconf_general_remove_cb (const gchar *key,
-				  GncGconfGeneralCb func,
-				  gpointer user_data);
+                                  GncGconfGeneralCb func,
+                                  gpointer user_data);
 
 
 /** Register a callback for when any key in the general section of
@@ -216,7 +216,7 @@
  *  function.
  */
 void gnc_gconf_general_register_any_cb (GncGconfGeneralAnyCb func,
-					gpointer user_data);
+                                        gpointer user_data);
 
 
 /** Remove a function that was registered for a callback when any key
@@ -231,14 +231,14 @@
  *  function.
  */
 void gnc_gconf_general_remove_any_cb (GncGconfGeneralAnyCb func,
-				      gpointer user_data);
+                                      gpointer user_data);
 
 /** @} */
 
 
 
-/** @name GConf Get Functions 
- @{ 
+/** @name GConf Get Functions
+ @{
 */
 
 /** Get a boolean value from GConf.
@@ -274,8 +274,8 @@
  *  returned by GConf.
  */
 gboolean gnc_gconf_get_bool (const gchar *section,
-			     /*@ null @*/ const gchar *name,
-			     /*@ null @*/ GError **error);
+                             /*@ null @*/ const gchar *name,
+                             /*@ null @*/ GError **error);
 
 /** Get a boolean value from GConf with no error argument.
  *
@@ -308,7 +308,7 @@
  * functions.  It should not be called from C code.
  */
 gboolean gnc_gconf_get_bool_no_error (const gchar *section,
-				      const gchar *name);
+                                      const gchar *name);
 
 /** Get an integer value from GConf.
  *
@@ -343,8 +343,8 @@
  *  by GConf.
  */
 gint gnc_gconf_get_int (const gchar *section,
-			const gchar *name,
-			GError **error);
+                        const gchar *name,
+                        GError **error);
 
 /** Get an float value from GConf.
  *
@@ -379,8 +379,8 @@
  *  by GConf.
  */
 gdouble gnc_gconf_get_float (const gchar *section,
-			     const gchar *name,
-			     GError **error);
+                             const gchar *name,
+                             GError **error);
 
 /** Get a string value from GConf.
  *
@@ -416,8 +416,8 @@
  *  returned by this function.
  */
 char *gnc_gconf_get_string (const gchar *section,
-			    const gchar *name,
-			    GError **error);
+                            const gchar *name,
+                            GError **error);
 
 /** Get a list of values from GConf.
  *
@@ -460,9 +460,9 @@
  *  list data that are string values.
  */
 GSList *gnc_gconf_get_list (const gchar *section,
-			    const gchar *name,
-			    GConfValueType list_type,
-			    GError **error);
+                            const gchar *name,
+                            GConfValueType list_type,
+                            GError **error);
 
 
 /** Get a schema value from GConf.
@@ -498,13 +498,13 @@
  *  calling the gconf_schema_free() function.
  */
 GConfSchema *gnc_gconf_get_schema (const gchar *section,
-				   const gchar *name,
-				   GError **caller_error);
+                                   const gchar *name,
+                                   GError **caller_error);
 
 /** @} */
 
-/** @name GConf Set/Unset Functions 
- @{ 
+/** @name GConf Set/Unset Functions
+ @{
 */
 
 
@@ -536,9 +536,9 @@
  *  will pass any error back to the calling function for it to handle.
  */
 void gnc_gconf_set_bool (const gchar *section,
-			 const gchar *name,
-			 const gboolean value,
-			 GError **error);
+                         const gchar *name,
+                         const gboolean value,
+                         GError **error);
 
 /** Store an integer value into GConf.
  *
@@ -568,9 +568,9 @@
  *  will pass any error back to the calling function for it to handle.
  */
 void gnc_gconf_set_int (const gchar *section,
-			const gchar *name,
-			const gint value,
-			GError **error);
+                        const gchar *name,
+                        const gint value,
+                        GError **error);
 
 /** Store an float value into GConf.
  *
@@ -600,9 +600,9 @@
  *  will pass any error back to the calling function for it to handle.
  */
 void gnc_gconf_set_float (const gchar *section,
-			  const gchar *name,
-			  const gdouble value,
-			  GError **error);
+                          const gchar *name,
+                          const gdouble value,
+                          GError **error);
 
 /** Store a string into GConf.
  *
@@ -634,9 +634,9 @@
  *  will pass any error back to the calling function for it to handle.
  */
 void gnc_gconf_set_string (const gchar *section,
-			   const gchar *name,
-			   const gchar *value,
-			   GError **error);
+                           const gchar *name,
+                           const gchar *value,
+                           GError **error);
 
 /** Store a list of values into GConf.
  *
@@ -674,10 +674,10 @@
  *  will pass any error back to the calling function for it to handle.
  */
 void gnc_gconf_set_list (const gchar *section,
-			 const gchar *name,
-			 GConfValueType list_type,
-			 GSList *value,
-			 GError **error);
+                         const gchar *name,
+                         GConfValueType list_type,
+                         GSList *value,
+                         GError **error);
 
 /** Delete a value from GConf.
  *
@@ -707,8 +707,8 @@
  *  will pass any error back to the calling function for it to handle.
  */
 void gnc_gconf_unset (const gchar *section,
-		      const gchar *name,
-		      GError **error);
+                      const gchar *name,
+                      GError **error);
 
 
 /** Delete a directory of values from GConf.
@@ -732,12 +732,12 @@
  *  will pass any error back to the calling function for it to handle.
  */
 void gnc_gconf_unset_dir (const gchar *section,
-			  GError **error);
+                          GError **error);
 
 /** @} */
 
-/** @name GConf Notification Functions 
- @{ 
+/** @name GConf Notification Functions
+ @{
 */
 
 /** Add a notification callback to GConf.
@@ -772,9 +772,9 @@
  *  section and whoami should be unique across all callers.
  */
 void gnc_gconf_add_notification (GObject *object,
-				 const gchar *section,
-				 GConfClientNotifyFunc callback,
-				 const gchar *whoami);
+                                 const gchar *section,
+                                 GConfClientNotifyFunc callback,
+                                 const gchar *whoami);
 
 
 /** An alternative function for adding a notification callback to
@@ -808,8 +808,8 @@
  *  reverse the actions of this function.
  */
 guint gnc_gconf_add_anon_notification (const gchar *section,
-				       GConfClientNotifyFunc callback,
-				       gpointer data);
+                                       GConfClientNotifyFunc callback,
+                                       gpointer data);
 
 
 /** Remove a callback from GConf.
@@ -832,8 +832,8 @@
  *  section and whoami should be unique across all callers.
  */
 void gnc_gconf_remove_notification (GObject *object,
-				    const gchar *section,
-				    const gchar *whoami);
+                                    const gchar *section,
+                                    const gchar *whoami);
 
 
 
@@ -852,7 +852,7 @@
  *  gnc_gconf_add_anon_notification() function.
  */
 void gnc_gconf_remove_anon_notification (const gchar *section,
-					 guint cnxn_id);
+        guint cnxn_id);
 
 
 /** Retrieve a list of all key/value pairs in the specified GConf
@@ -888,8 +888,8 @@
 
 /** @} */
 
-/** @name GConf One Liners 
- @{ 
+/** @name GConf One Liners
+ @{
 */
 
 #define DESTKOP_TEAROFF_MENUS "/desktop/gnome/interface/menus_have_tearoff"
@@ -899,19 +899,19 @@
 static inline gboolean
 gnc_gconf_menus_have_tearoff (void)
 {
-  return gnc_gconf_get_bool(DESTKOP_TEAROFF_MENUS, NULL, NULL);
+    return gnc_gconf_get_bool(DESTKOP_TEAROFF_MENUS, NULL, NULL);
 }
 
 static inline gboolean
 gnc_gconf_menubar_detachable (void)
 {
-  return gnc_gconf_get_bool(DESTKOP_MENUBAR_DETACHABLE, NULL, NULL);
+    return gnc_gconf_get_bool(DESTKOP_MENUBAR_DETACHABLE, NULL, NULL);
 }
 
 static inline gboolean
 gnc_gconf_toolbar_detachable (void)
 {
-  return gnc_gconf_get_bool(DESTKOP_TOOLBAR_DETACHABLE, NULL, NULL);
+    return gnc_gconf_get_bool(DESTKOP_TOOLBAR_DETACHABLE, NULL, NULL);
 }
 
 /** @} */

Modified: gnucash/trunk/src/core-utils/gnc-gdate-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gdate-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-gdate-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -31,58 +31,58 @@
 gboolean
 gnc_gdate_equal(gconstpointer gda, gconstpointer gdb)
 {
-  return (g_date_compare( (GDate*)gda, (GDate*)gdb ) == 0 ? TRUE : FALSE);
+    return (g_date_compare( (GDate*)gda, (GDate*)gdb ) == 0 ? TRUE : FALSE);
 }
 
 guint
 gnc_gdate_hash( gconstpointer gd )
 {
-  gint val = (g_date_get_year( (GDate*)gd ) * 10000)
-    + (g_date_get_month( (GDate*)gd ) * 100)
-    + g_date_get_day( (GDate*)gd );
-  return g_int_hash( &val );
+    gint val = (g_date_get_year( (GDate*)gd ) * 10000)
+               + (g_date_get_month( (GDate*)gd ) * 100)
+               + g_date_get_day( (GDate*)gd );
+    return g_int_hash( &val );
 }
 
 
 time_t
 gnc_timet_get_day_start_gdate (GDate *date)
 {
-  struct tm stm;
-  time_t secs;
+    struct tm stm;
+    time_t secs;
 
-  /* First convert to a 'struct tm' */
-  g_date_to_struct_tm(date, &stm);
+    /* First convert to a 'struct tm' */
+    g_date_to_struct_tm(date, &stm);
 
-  /* Then convert to number of seconds */
-  secs = mktime (&stm);
-  return secs;
+    /* Then convert to number of seconds */
+    secs = mktime (&stm);
+    return secs;
 }
 
 time_t
 gnc_timet_get_day_end_gdate (GDate *date)
 {
-  struct tm stm;
-  time_t secs;
+    struct tm stm;
+    time_t secs;
 
-  /* First convert to a 'struct tm' */
-  g_date_to_struct_tm(date, &stm);
+    /* First convert to a 'struct tm' */
+    g_date_to_struct_tm(date, &stm);
 
-  /* Force to th last second of the day */
-  stm.tm_hour = 23;
-  stm.tm_min = 59;
-  stm.tm_sec = 59;
-  stm.tm_isdst = -1;
+    /* Force to th last second of the day */
+    stm.tm_hour = 23;
+    stm.tm_min = 59;
+    stm.tm_sec = 59;
+    stm.tm_isdst = -1;
 
-  /* Then convert to number of seconds */
-  secs = mktime (&stm);
-  return secs;
+    /* Then convert to number of seconds */
+    secs = mktime (&stm);
+    return secs;
 }
 
 
 void
 gnc_gdate_set_month_start (GDate *date)
 {
-  g_date_set_day(date, 1);
+    g_date_set_day(date, 1);
 }
 
 
@@ -90,18 +90,18 @@
  *  knowledge of how many days are in a month, whether its a leap
  *  year, etc.  All that information is contained in the glib date
  *  functions.
- *  
+ *
  *  @param date The GDate to modify.
  */
 void
 gnc_gdate_set_month_end (GDate *date)
 {
-  /* First set the start of next month. */
-  g_date_set_day(date, 1);
-  g_date_add_months(date, 1);
+    /* First set the start of next month. */
+    g_date_set_day(date, 1);
+    g_date_add_months(date, 1);
 
-  /* Then back up one day */
-  g_date_subtract_days(date, 1);
+    /* Then back up one day */
+    g_date_subtract_days(date, 1);
 }
 
 
@@ -109,14 +109,14 @@
  *  routine has no knowledge of how many days are in a month, whether
  *  its a leap year, etc.  All that information is contained in the
  *  glib date functions.
- *  
+ *
  *  @param date The GDate to modify.
  */
 void
 gnc_gdate_set_prev_month_start (GDate *date)
 {
-  g_date_set_day(date, 1);
-  g_date_subtract_months(date, 1);
+    g_date_set_day(date, 1);
+    g_date_subtract_months(date, 1);
 }
 
 
@@ -124,15 +124,15 @@
  *  routine has no knowledge of how many days are in a month, whether
  *  its a leap year, etc.  All that information is contained in the
  *  glib date functions.
- *  
+ *
  *  @param date The GDate to modify.
  */
 void
 gnc_gdate_set_prev_month_end (GDate *date)
 {
-  /* This will correctly handle the varying month lengths */
-  g_date_set_day(date, 1);
-  g_date_subtract_days(date, 1);
+    /* This will correctly handle the varying month lengths */
+    g_date_set_day(date, 1);
+    g_date_subtract_days(date, 1);
 }
 
 /* ========== */
@@ -140,47 +140,47 @@
 void
 gnc_gdate_set_quarter_start (GDate *date)
 {
-  gint months;
+    gint months;
 
-  /* Set the date to the first day of the specified month. */
-  g_date_set_day(date, 1);
+    /* Set the date to the first day of the specified month. */
+    g_date_set_day(date, 1);
 
-  /* Back up 0-2 months */ 
-  months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
-  g_date_subtract_months(date, months);
+    /* Back up 0-2 months */
+    months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
+    g_date_subtract_months(date, months);
 }
 
 
 void
 gnc_gdate_set_quarter_end (GDate *date)
 {
-  gint months;
+    gint months;
 
-  /* Set the date to the first day of the specified month. */
-  g_date_set_day(date, 1);
+    /* Set the date to the first day of the specified month. */
+    g_date_set_day(date, 1);
 
-  /* Add 1-3 months to get the first day of the next quarter.*/
-  months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
-  g_date_add_months(date, 3 - months);
+    /* Add 1-3 months to get the first day of the next quarter.*/
+    months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
+    g_date_add_months(date, 3 - months);
 
-  /* Now back up one day */
-  g_date_subtract_days(date, 1);
+    /* Now back up one day */
+    g_date_subtract_days(date, 1);
 }
 
 
 void
 gnc_gdate_set_prev_quarter_start (GDate *date)
 {
-  gnc_gdate_set_quarter_start(date);
-  g_date_subtract_months(date, 3);
+    gnc_gdate_set_quarter_start(date);
+    g_date_subtract_months(date, 3);
 }
 
 
 void
 gnc_gdate_set_prev_quarter_end (GDate *date)
 {
-  gnc_gdate_set_quarter_end(date);
-  g_date_subtract_months(date, 3);
+    gnc_gdate_set_quarter_end(date);
+    g_date_subtract_months(date, 3);
 }
 
 /* ========== */
@@ -188,101 +188,101 @@
 void
 gnc_gdate_set_year_start (GDate *date)
 {
-  g_date_set_month(date, G_DATE_JANUARY);
-  g_date_set_day(date, 1);
+    g_date_set_month(date, G_DATE_JANUARY);
+    g_date_set_day(date, 1);
 }
 
 
 void
 gnc_gdate_set_year_end (GDate *date)
 {
-  g_date_set_month(date, G_DATE_DECEMBER);
-  g_date_set_day(date, 31);
+    g_date_set_month(date, G_DATE_DECEMBER);
+    g_date_set_day(date, 31);
 }
 
 
 void
 gnc_gdate_set_prev_year_start (GDate *date)
 {
-  gnc_gdate_set_year_start(date);
-  g_date_subtract_years(date, 1);
+    gnc_gdate_set_year_start(date);
+    g_date_subtract_years(date, 1);
 }
 
 
 void
 gnc_gdate_set_prev_year_end (GDate *date)
 {
-  gnc_gdate_set_year_end(date);
-  g_date_subtract_years(date, 1);
+    gnc_gdate_set_year_end(date);
+    g_date_subtract_years(date, 1);
 }
 
 /* ========== */
 
 void
 gnc_gdate_set_fiscal_year_start (GDate *date,
-				const GDate *fy_end)
+                                 const GDate *fy_end)
 {
-  GDate temp;
-  gboolean new_fy;
+    GDate temp;
+    gboolean new_fy;
 
-  g_return_if_fail(date);
-  g_return_if_fail(fy_end);
+    g_return_if_fail(date);
+    g_return_if_fail(fy_end);
 
-  /* Compute the FY end that occurred this CY */
-  temp = *fy_end;
-  g_date_set_year(&temp, g_date_get_year(date));
+    /* Compute the FY end that occurred this CY */
+    temp = *fy_end;
+    g_date_set_year(&temp, g_date_get_year(date));
 
-  /* Has it already passed? */
-  new_fy = (g_date_compare(date, &temp) > 0);
+    /* Has it already passed? */
+    new_fy = (g_date_compare(date, &temp) > 0);
 
-  /* Set start date */
-  *date = temp;
-  g_date_add_days(date, 1);
-  if (!new_fy)
-    g_date_subtract_years(date, 1);
+    /* Set start date */
+    *date = temp;
+    g_date_add_days(date, 1);
+    if (!new_fy)
+        g_date_subtract_years(date, 1);
 }
 
 void
 gnc_gdate_set_fiscal_year_end (GDate *date,
-			      const GDate *fy_end)
+                               const GDate *fy_end)
 {
-  GDate temp;
-  gboolean new_fy;
+    GDate temp;
+    gboolean new_fy;
 
-  g_return_if_fail(date);
-  g_return_if_fail(fy_end);
+    g_return_if_fail(date);
+    g_return_if_fail(fy_end);
 
-  /* Compute the FY end that occurred this CY */
-  temp = *fy_end;
-  g_date_set_year(&temp, g_date_get_year(date));
+    /* Compute the FY end that occurred this CY */
+    temp = *fy_end;
+    g_date_set_year(&temp, g_date_get_year(date));
 
-  /* Has it already passed? */
-  new_fy = (g_date_compare(date, &temp) > 0);
+    /* Has it already passed? */
+    new_fy = (g_date_compare(date, &temp) > 0);
 
-  /* Set end date */
-  *date = temp;
-  if (new_fy)
-    g_date_add_years(date, 1);
+    /* Set end date */
+    *date = temp;
+    if (new_fy)
+        g_date_add_years(date, 1);
 }
 
 void
 gnc_gdate_set_prev_fiscal_year_start (GDate *date,
-				     const GDate *fy_end)
+                                      const GDate *fy_end)
 {
-  g_return_if_fail(date);
-  g_return_if_fail(fy_end);
+    g_return_if_fail(date);
+    g_return_if_fail(fy_end);
 
-  gnc_gdate_set_fiscal_year_start(date, fy_end);
-  g_date_subtract_years(date, 1);
+    gnc_gdate_set_fiscal_year_start(date, fy_end);
+    g_date_subtract_years(date, 1);
 }
 
 void
 gnc_gdate_set_prev_fiscal_year_end (GDate *date,
-				   const GDate *fy_end)
+                                    const GDate *fy_end)
 {
-  g_return_if_fail(date);
-  g_return_if_fail(fy_end);
+    g_return_if_fail(date);
+    g_return_if_fail(fy_end);
 
-  gnc_gdate_set_fiscal_year_end(date, fy_end);
-  g_date_subtract_years(date, 1);
+    gnc_gdate_set_fiscal_year_end(date, fy_end);
+    g_date_subtract_years(date, 1);
 }

Modified: gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -58,39 +58,39 @@
 static gchar *
 _g_utf8_make_valid (const gchar *name)
 {
-  GString *string;
-  const gchar *remainder, *invalid;
-  gint remaining_bytes, valid_bytes;
-  
-  string = NULL;
-  remainder = name;
-  remaining_bytes = strlen (name);
-  
-  while (remaining_bytes != 0) 
+    GString *string;
+    const gchar *remainder, *invalid;
+    gint remaining_bytes, valid_bytes;
+
+    string = NULL;
+    remainder = name;
+    remaining_bytes = strlen (name);
+
+    while (remaining_bytes != 0)
     {
-      if (g_utf8_validate (remainder, remaining_bytes, &invalid)) 
-	break;
-      valid_bytes = invalid - remainder;
-    
-      if (string == NULL) 
-	string = g_string_sized_new (remaining_bytes);
+        if (g_utf8_validate (remainder, remaining_bytes, &invalid))
+            break;
+        valid_bytes = invalid - remainder;
 
-      g_string_append_len (string, remainder, valid_bytes);
-      /* append U+FFFD REPLACEMENT CHARACTER */
-      g_string_append (string, "\357\277\275");
-      
-      remaining_bytes -= valid_bytes + 1;
-      remainder = invalid + 1;
+        if (string == NULL)
+            string = g_string_sized_new (remaining_bytes);
+
+        g_string_append_len (string, remainder, valid_bytes);
+        /* append U+FFFD REPLACEMENT CHARACTER */
+        g_string_append (string, "\357\277\275");
+
+        remaining_bytes -= valid_bytes + 1;
+        remainder = invalid + 1;
     }
-  
-  if (string == NULL)
-    return g_strdup (name);
-  
-  g_string_append (string, remainder);
 
-  g_assert (g_utf8_validate (string->str, -1, NULL));
-  
-  return g_string_free (string, FALSE);
+    if (string == NULL)
+        return g_strdup (name);
+
+    g_string_append (string, remainder);
+
+    g_assert (g_utf8_validate (string->str, -1, NULL));
+
+    return g_string_free (string, FALSE);
 }
 
 static gdouble
@@ -98,69 +98,69 @@
                                    const gchar  *value,
                                    GError      **error)
 {
-  gchar *end_of_valid_d;
-  gdouble double_value = 0;
+    gchar *end_of_valid_d;
+    gdouble double_value = 0;
 
-  double_value = g_ascii_strtod (value, &end_of_valid_d);
+    double_value = g_ascii_strtod (value, &end_of_valid_d);
 
-  if (*end_of_valid_d != '\0' || end_of_valid_d == value)
+    if (*end_of_valid_d != '\0' || end_of_valid_d == value)
     {
-      gchar *value_utf8 = _g_utf8_make_valid (value);
-      g_set_error (error, G_KEY_FILE_ERROR,
-		   G_KEY_FILE_ERROR_INVALID_VALUE,
-		   _("Value '%s' cannot be interpreted "
-		     "as a float number."), 
-		   value_utf8);
-      g_free (value_utf8);
+        gchar *value_utf8 = _g_utf8_make_valid (value);
+        g_set_error (error, G_KEY_FILE_ERROR,
+                     G_KEY_FILE_ERROR_INVALID_VALUE,
+                     _("Value '%s' cannot be interpreted "
+                       "as a float number."),
+                     value_utf8);
+        g_free (value_utf8);
     }
 
-  return double_value;
+    return double_value;
 }
 
 gdouble
 g_key_file_get_double (GKeyFile *key_file, const gchar *group_name,
                        const gchar *key, GError **error)
 {
-  GError *key_file_error;
-  gchar *value;
-  gdouble double_value;
+    GError *key_file_error;
+    gchar *value;
+    gdouble double_value;
 
-  g_return_val_if_fail (key_file != NULL, -1);
-  g_return_val_if_fail (group_name != NULL, -1);
-  g_return_val_if_fail (key != NULL, -1);
+    g_return_val_if_fail (key_file != NULL, -1);
+    g_return_val_if_fail (group_name != NULL, -1);
+    g_return_val_if_fail (key != NULL, -1);
 
-  key_file_error = NULL;
+    key_file_error = NULL;
 
-  value = g_key_file_get_value (key_file, group_name, key, &key_file_error);
+    value = g_key_file_get_value (key_file, group_name, key, &key_file_error);
 
-  if (key_file_error)
+    if (key_file_error)
     {
-      g_propagate_error (error, key_file_error);
-      return 0;
+        g_propagate_error (error, key_file_error);
+        return 0;
     }
 
-  double_value = g_key_file_parse_value_as_double (key_file, value,
-                                                  &key_file_error);
-  g_free (value);
+    double_value = g_key_file_parse_value_as_double (key_file, value,
+                   &key_file_error);
+    g_free (value);
 
-  if (key_file_error)
+    if (key_file_error)
     {
-      if (g_error_matches (key_file_error,
-                           G_KEY_FILE_ERROR,
-                           G_KEY_FILE_ERROR_INVALID_VALUE))
+        if (g_error_matches (key_file_error,
+                             G_KEY_FILE_ERROR,
+                             G_KEY_FILE_ERROR_INVALID_VALUE))
         {
-          g_set_error (error, G_KEY_FILE_ERROR,
-                       G_KEY_FILE_ERROR_INVALID_VALUE,
-                       _("Key file contains key '%s' in group '%s' "
-                         "which has a value that cannot be interpreted."), key,
-                       group_name);
-          g_error_free (key_file_error);
+            g_set_error (error, G_KEY_FILE_ERROR,
+                         G_KEY_FILE_ERROR_INVALID_VALUE,
+                         _("Key file contains key '%s' in group '%s' "
+                           "which has a value that cannot be interpreted."), key,
+                         group_name);
+            g_error_free (key_file_error);
         }
-      else
-        g_propagate_error (error, key_file_error);
+        else
+            g_propagate_error (error, key_file_error);
     }
 
-  return double_value;
+    return double_value;
 }
 
 void
@@ -169,12 +169,12 @@
                         const gchar *key,
                         gdouble      value)
 {
-  gchar result[G_ASCII_DTOSTR_BUF_SIZE];
+    gchar result[G_ASCII_DTOSTR_BUF_SIZE];
 
-  g_return_if_fail (key_file != NULL);
+    g_return_if_fail (key_file != NULL);
 
-  g_ascii_dtostr (result, sizeof (result), value);
-  g_key_file_set_value (key_file, group_name, key, result);
+    g_ascii_dtostr (result, sizeof (result), value);
+    g_key_file_set_value (key_file, group_name, key, result);
 }
 
 gdouble*
@@ -184,75 +184,75 @@
                             gsize *length,
                             GError **error)
 {
-  GError *key_file_error = NULL;
-  gchar **values;
-  gdouble *double_values;
-  gsize i, num_doubles;
+    GError *key_file_error = NULL;
+    gchar **values;
+    gdouble *double_values;
+    gsize i, num_doubles;
 
-  g_return_val_if_fail (key_file != NULL, NULL);
-  g_return_val_if_fail (group_name != NULL, NULL);
-  g_return_val_if_fail (key != NULL, NULL);
+    g_return_val_if_fail (key_file != NULL, NULL);
+    g_return_val_if_fail (group_name != NULL, NULL);
+    g_return_val_if_fail (key != NULL, NULL);
 
-  values = g_key_file_get_string_list (key_file, group_name, key,
-                                       &num_doubles, &key_file_error);
+    values = g_key_file_get_string_list (key_file, group_name, key,
+                                         &num_doubles, &key_file_error);
 
-  if (key_file_error)
-    g_propagate_error (error, key_file_error);
+    if (key_file_error)
+        g_propagate_error (error, key_file_error);
 
-  if (!values)
-    return NULL;
+    if (!values)
+        return NULL;
 
-  double_values = g_new0 (gdouble, num_doubles);
+    double_values = g_new0 (gdouble, num_doubles);
 
-  for (i = 0; i < num_doubles; i++)
+    for (i = 0; i < num_doubles; i++)
     {
-      double_values[i] = g_key_file_parse_value_as_double (key_file,
-							   values[i],
-							   &key_file_error);
+        double_values[i] = g_key_file_parse_value_as_double (key_file,
+                           values[i],
+                           &key_file_error);
 
-      if (key_file_error)
+        if (key_file_error)
         {
-          g_propagate_error (error, key_file_error);
-          g_strfreev (values);
-          g_free (double_values);
+            g_propagate_error (error, key_file_error);
+            g_strfreev (values);
+            g_free (double_values);
 
-          return NULL;
+            return NULL;
         }
     }
-  g_strfreev (values);
+    g_strfreev (values);
 
-  if (length)
-    *length = num_doubles;
+    if (length)
+        *length = num_doubles;
 
-  return double_values;
+    return double_values;
 }
 
 void
 g_key_file_set_double_list (GKeyFile     *key_file,
-			    const gchar  *group_name,
-			    const gchar  *key,
-			    gdouble       list[],
-			    gsize         length)
+                            const gchar  *group_name,
+                            const gchar  *key,
+                            gdouble       list[],
+                            gsize         length)
 {
-  GString *values;
-  gsize i;
+    GString *values;
+    gsize i;
 
-  g_return_if_fail (key_file != NULL);
-  g_return_if_fail (list != NULL);
+    g_return_if_fail (key_file != NULL);
+    g_return_if_fail (list != NULL);
 
-  values = g_string_sized_new (length * 16);
-  for (i = 0; i < length; i++)
+    values = g_string_sized_new (length * 16);
+    for (i = 0; i < length; i++)
     {
-      gchar result[G_ASCII_DTOSTR_BUF_SIZE];
+        gchar result[G_ASCII_DTOSTR_BUF_SIZE];
 
-      g_ascii_dtostr( result, sizeof (result), list[i] );
+        g_ascii_dtostr( result, sizeof (result), list[i] );
 
-      g_string_append (values, result);
-      g_string_append_c (values, ';');
+        g_string_append (values, result);
+        g_string_append_c (values, ';');
     }
 
-  g_key_file_set_value (key_file, group_name, key, values->str);
-  g_string_free (values, TRUE);
+    g_key_file_set_value (key_file, group_name, key, values->str);
+    g_string_free (values, TRUE);
 }
 /**********************************************************************
  *
@@ -264,104 +264,123 @@
 
 GKeyFile *
 gnc_key_file_load_from_file (const gchar *filename,
-			     gboolean ignore_error,
-			     gboolean return_empty_struct,
-			     GError **caller_error)
+                             gboolean ignore_error,
+                             gboolean return_empty_struct,
+                             GError **caller_error)
 {
-  GKeyFile *key_file;
-  GError *error = NULL;
+    GKeyFile *key_file;
+    GError *error = NULL;
 
-  g_return_val_if_fail(filename != NULL, NULL);
+    g_return_val_if_fail(filename != NULL, NULL);
 
-  if (!g_file_test(filename, G_FILE_TEST_EXISTS))
-    return NULL;
+    if (!g_file_test(filename, G_FILE_TEST_EXISTS))
+        return NULL;
 
-  key_file = g_key_file_new();
-  if (!key_file)
-    return NULL;
+    key_file = g_key_file_new();
+    if (!key_file)
+        return NULL;
 
-  if (g_key_file_load_from_file(key_file, filename, G_KEY_FILE_NONE, &error))
-    return key_file;
+    if (g_key_file_load_from_file(key_file, filename, G_KEY_FILE_NONE, &error))
+        return key_file;
 
-  /* An error occurred */
-  if (!return_empty_struct) {
-    g_key_file_free(key_file);
-    key_file = NULL;
-  }
+    /* An error occurred */
+    if (!return_empty_struct)
+    {
+        g_key_file_free(key_file);
+        key_file = NULL;
+    }
 
-  if (!ignore_error)
-    g_warning("Unable to read file %s: %s\n", filename, error->message);
-  g_propagate_error(caller_error, error);
-  return key_file;
+    if (!ignore_error)
+        g_warning("Unable to read file %s: %s\n", filename, error->message);
+    g_propagate_error(caller_error, error);
+    return key_file;
 }
 
 
 gboolean
 gnc_key_file_save_to_file (const gchar *filename,
-			   GKeyFile *key_file,
-			   GError **error)
+                           GKeyFile *key_file,
+                           GError **error)
 {
-  gchar *contents;
-  gint fd;
-  extern int errno;
-  gint length;
-  ssize_t written;
-  gboolean success = TRUE;
+    gchar *contents;
+    gint fd;
+    extern int errno;
+    gint length;
+    ssize_t written;
+    gboolean success = TRUE;
 
-  g_return_val_if_fail(filename != NULL, FALSE);
-  g_return_val_if_fail(key_file != NULL, FALSE);
-  if (error)
-    g_return_val_if_fail(*error == NULL, FALSE);
+    g_return_val_if_fail(filename != NULL, FALSE);
+    g_return_val_if_fail(key_file != NULL, FALSE);
+    if (error)
+        g_return_val_if_fail(*error == NULL, FALSE);
 
-  contents = g_key_file_to_data(key_file, NULL, NULL);
-  length = strlen(contents);
-  fd = g_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
-  if (fd == -1) {
-    if (error) {
-      *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), 
-			   "Cannot open file %s: %s", filename,
-			   strerror(errno));
-    } else {
-      g_critical("Cannot open file %s: %s\n", filename, strerror(errno));
+    contents = g_key_file_to_data(key_file, NULL, NULL);
+    length = strlen(contents);
+    fd = g_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+    if (fd == -1)
+    {
+        if (error)
+        {
+            *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno),
+                                 "Cannot open file %s: %s", filename,
+                                 strerror(errno));
+        }
+        else
+        {
+            g_critical("Cannot open file %s: %s\n", filename, strerror(errno));
+        }
+        g_free(contents);
+        return FALSE;
     }
-    g_free(contents);
-    return FALSE;
-  }
 
-  written = write(fd, contents, length);
-  if (written == -1 ) {
-    success = FALSE;
-    if (error) {
-      *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), 
-			   "Cannot write to file %s: %s", filename,
-			   strerror(errno));
-    } else {
-      g_critical("Cannot write to file %s: %s\n", filename, strerror(errno));
+    written = write(fd, contents, length);
+    if (written == -1 )
+    {
+        success = FALSE;
+        if (error)
+        {
+            *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno),
+                                 "Cannot write to file %s: %s", filename,
+                                 strerror(errno));
+        }
+        else
+        {
+            g_critical("Cannot write to file %s: %s\n", filename, strerror(errno));
+        }
+        close(fd);
     }
-    close(fd);
-  } else if (written != length) {
-    success = FALSE;
-    if (error) {
-      *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), 
-			   "File %s truncated (provided %d, written %d)",
-			   filename, length, (int)written);
-    } else {
-      g_critical("File %s truncated (provided %d, written %d)",
-	      filename, length, (int)written);
+    else if (written != length)
+    {
+        success = FALSE;
+        if (error)
+        {
+            *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno),
+                                 "File %s truncated (provided %d, written %d)",
+                                 filename, length, (int)written);
+        }
+        else
+        {
+            g_critical("File %s truncated (provided %d, written %d)",
+                       filename, length, (int)written);
+        }
+        /* Ignore any error */
+        close(fd);
     }
-    /* Ignore any error */
-    close(fd);
-  } else if (close(fd) == -1) {
-    if (error) {
-      *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), 
-			   "Close failed for file %s: %s", filename,
-			   strerror(errno));
-    } else {
-      g_warning("Close failed for file %s: %s", filename, strerror(errno));
+    else if (close(fd) == -1)
+    {
+        if (error)
+        {
+            *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno),
+                                 "Close failed for file %s: %s", filename,
+                                 strerror(errno));
+        }
+        else
+        {
+            g_warning("Close failed for file %s: %s", filename, strerror(errno));
+        }
     }
-  }
-  g_free(contents);
-  return success;
+    g_free(contents);
+    return success;
 }
 
 /** @} */

Modified: gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -50,7 +50,7 @@
 g_key_file_get_double_list (GKeyFile *key_file, const gchar *group_name,
                             const gchar *key, gsize *length, GError **error);
 void
-g_key_file_set_double_list (GKeyFile *key_file, const gchar *group_name, 
+g_key_file_set_double_list (GKeyFile *key_file, const gchar *group_name,
                             const gchar *key, gdouble list[], gsize length);
 #endif
 
@@ -70,9 +70,9 @@
  *  @return A pointer to a GKeyFile data structure, or NULL.
  */
 GKeyFile *gnc_key_file_load_from_file (const gchar *file,
-				       gboolean ignore_error,
-				       gboolean return_empty_struct,
-				       GError **caller_error);
+                                       gboolean ignore_error,
+                                       gboolean return_empty_struct,
+                                       GError **caller_error);
 
 
 /** Write a key/value file from memory to disk.  If there is no data
@@ -88,8 +88,8 @@
  *  FALSE if there was an error.
  */
 gboolean gnc_key_file_save_to_file (const gchar *file,
-				    GKeyFile *key_file,
-				    GError **error);
+                                    GKeyFile *key_file,
+                                    GError **error);
 
 #endif /* GNC_GKEYFILE_UTILS_H */
 /** @} */

Modified: gnucash/trunk/src/core-utils/gnc-glib-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-glib-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-glib-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -36,18 +36,18 @@
 int
 safe_utf8_collate (const char * da, const char * db)
 {
-  if (da && !(*da))
-    da = NULL;
-  if (db && !(*db))
-    db = NULL;
+    if (da && !(*da))
+        da = NULL;
+    if (db && !(*db))
+        db = NULL;
 
-  if (da && db)
-    return g_utf8_collate(da, db);
-  if (da)
-    return 1;
-  if (db)
-    return -1;
-  return 0;
+    if (da && db)
+        return g_utf8_collate(da, db);
+    if (da)
+        return 1;
+    if (db)
+        return -1;
+    return 0;
 }
 
 /********************************************************************
@@ -97,8 +97,8 @@
     ((Char) < 0x10000 ? 3 :            \
      ((Char) < 0x200000 ? 4 :          \
       ((Char) < 0x4000000 ? 5 : 6)))))
-   
 
+
 #define UTF8_GET(Result, Chars, Count, Mask, Len)			      \
   (Result) = (Chars)[0] & (Mask);					      \
   for ((Count) = 1; (Count) < (Len); ++(Count))				      \
@@ -121,151 +121,155 @@
 
 gboolean
 gnc_utf8_validate(const gchar  *str,
-                  gssize        max_len,    
+                  gssize        max_len,
                   const gchar **end)
 {
 
-  const gchar *p;
+    const gchar *p;
 
-  g_return_val_if_fail (str != NULL, FALSE);
-  
-  if (end)
-    *end = str;
-  
-  p = str;
-  
-  while ((max_len < 0 || (p - str) < max_len) && *p)
+    g_return_val_if_fail (str != NULL, FALSE);
+
+    if (end)
+        *end = str;
+
+    p = str;
+
+    while ((max_len < 0 || (p - str) < max_len) && *p)
     {
-      int i, mask = 0, len;
-      gunichar result;
-      unsigned char c = (unsigned char) *p;
-      
-      UTF8_COMPUTE (c, mask, len);
+        int i, mask = 0, len;
+        gunichar result;
+        unsigned char c = (unsigned char) * p;
 
-      if (len == -1)
-        break;
+        UTF8_COMPUTE (c, mask, len);
 
-      /* check that the expected number of bytes exists in str */
-      if (max_len >= 0 &&
-          ((max_len - (p - str)) < len))
-        break;
-        
-      UTF8_GET (result, p, i, mask, len);
+        if (len == -1)
+            break;
 
-      if (UTF8_LENGTH (result) != len) /* Check for overlong UTF-8 */
-	break;
+        /* check that the expected number of bytes exists in str */
+        if (max_len >= 0 &&
+                ((max_len - (p - str)) < len))
+            break;
 
-      if (result == (gunichar)-1)
-        break;
+        UTF8_GET (result, p, i, mask, len);
 
-      if (!UNICODE_VALID (result))
-	break;
-      
-      p += len;
+        if (UTF8_LENGTH (result) != len) /* Check for overlong UTF-8 */
+            break;
+
+        if (result == (gunichar) - 1)
+            break;
+
+        if (!UNICODE_VALID (result))
+            break;
+
+        p += len;
     }
 
-  if (end)
-    *end = p;
+    if (end)
+        *end = p;
 
-  /* See that we covered the entire length if a length was
-   * passed in, or that we ended on a nul if not
-   */
-  if (max_len >= 0 &&
-      p != (str + max_len))
-    return FALSE;
-  else if (max_len < 0 &&
-           *p != '\0')
-    return FALSE;
-  else
-    return TRUE;
+    /* See that we covered the entire length if a length was
+     * passed in, or that we ended on a nul if not
+     */
+    if (max_len >= 0 &&
+            p != (str + max_len))
+        return FALSE;
+    else if (max_len < 0 &&
+             *p != '\0')
+        return FALSE;
+    else
+        return TRUE;
 }
 
 void
 gnc_utf8_strip_invalid (gchar *str)
 {
-  gchar *end;
-  gint len;
+    gchar *end;
+    gint len;
 
-  g_return_if_fail(str);
+    g_return_if_fail(str);
 
-  if (gnc_utf8_validate(str, -1, (const gchar **)&end))
-    return;
+    if (gnc_utf8_validate(str, -1, (const gchar **)&end))
+        return;
 
-  g_warning("Invalid utf8 string: %s", str);
-  do {
-    len = strlen(end);
-    memmove(end, end+1, len);	/* shuffle the remainder one byte */
-  } while (!gnc_utf8_validate(str, -1, (const gchar **)&end));
+    g_warning("Invalid utf8 string: %s", str);
+    do
+    {
+        len = strlen(end);
+        memmove(end, end + 1, len);	/* shuffle the remainder one byte */
+    }
+    while (!gnc_utf8_validate(str, -1, (const gchar **)&end));
 }
 
 gchar *
 gnc_utf8_strip_invalid_strdup(const gchar* str)
 {
-  gchar *result = g_strdup (str);
-  gnc_utf8_strip_invalid (result);
-  return result;
+    gchar *result = g_strdup (str);
+    gnc_utf8_strip_invalid (result);
+    return result;
 }
 
 gchar *
 gnc_locale_from_utf8(const gchar* str)
 {
-  gchar *   locale_str;
-  gsize     bytes_written = 0;
-  GError *  err = NULL;
+    gchar *   locale_str;
+    gsize     bytes_written = 0;
+    GError *  err = NULL;
 
-  /* Convert from UTF-8 to the encoding used in the current locale. */
-  locale_str = g_locale_from_utf8(str, -1, NULL, &bytes_written, &err);
-  if (err) {
-    g_warning("g_locale_from_utf8 failed: %s", err->message);
-    g_error_free(err);
-  }
+    /* Convert from UTF-8 to the encoding used in the current locale. */
+    locale_str = g_locale_from_utf8(str, -1, NULL, &bytes_written, &err);
+    if (err)
+    {
+        g_warning("g_locale_from_utf8 failed: %s", err->message);
+        g_error_free(err);
+    }
 
-  return locale_str;
+    return locale_str;
 }
 
 gchar *
 gnc_locale_to_utf8(const gchar* str)
 {
-  gchar *   utf8_str;
-  gsize     bytes_written = 0;
-  GError *  err = NULL;
+    gchar *   utf8_str;
+    gsize     bytes_written = 0;
+    GError *  err = NULL;
 
-  /* Convert to UTF-8 from the encoding used in the current locale. */
-  utf8_str = g_locale_to_utf8(str, -1, NULL, &bytes_written, &err);
-  if (err) {
-    g_warning("g_locale_to_utf8 failed: %s", err->message);
-    g_error_free(err);
-  }
+    /* Convert to UTF-8 from the encoding used in the current locale. */
+    utf8_str = g_locale_to_utf8(str, -1, NULL, &bytes_written, &err);
+    if (err)
+    {
+        g_warning("g_locale_to_utf8 failed: %s", err->message);
+        g_error_free(err);
+    }
 
-  return utf8_str;
+    return utf8_str;
 }
 
 GList*
 gnc_g_list_map(GList* list, GncGMapFunc fn, gpointer user_data)
 {
-  GList *rtn = NULL;
-  for (; list != NULL; list = list->next)
-  {
-    rtn = g_list_append(rtn, (*fn)(list->data, user_data));
-  }
-  return rtn;
+    GList *rtn = NULL;
+    for (; list != NULL; list = list->next)
+    {
+        rtn = g_list_append(rtn, (*fn)(list->data, user_data));
+    }
+    return rtn;
 }
 
 void
 gnc_g_list_cut(GList **list, GList *cut_point)
 {
-  if (list == NULL || *list == NULL)
-    return;
+    if (list == NULL || *list == NULL)
+        return;
 
-  // if it's the first element.
-  if (cut_point->prev == NULL)
-  {
-    *list = NULL;
-    return;
-  }
+    // if it's the first element.
+    if (cut_point->prev == NULL)
+    {
+        *list = NULL;
+        return;
+    }
 
-  cut_point->prev->next = NULL;
-  cut_point->prev = NULL;
+    cut_point->prev->next = NULL;
+    cut_point->prev = NULL;
 }
 
 void
@@ -295,13 +299,15 @@
 void gnc_gpid_kill(GPid pid)
 {
 #ifdef G_OS_WIN32
-    if (!TerminateProcess((HANDLE) pid, 0)) {
+    if (!TerminateProcess((HANDLE) pid, 0))
+    {
         gchar *msg = g_win32_error_message(GetLastError());
         g_warning("Could not kill child process: %s", msg ? msg : "(null)");
         g_free(msg);
     }
 #else /* !G_OS_WIN32 */
-    if (kill(pid, SIGKILL)) {
+    if (kill(pid, SIGKILL))
+    {
         g_warning("Could not kill child process: %s", g_strerror(errno));
     }
 #endif /* G_OS_WIN32 */

Modified: gnucash/trunk/src/core-utils/gnc-glib-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-glib-utils.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-glib-utils.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -40,7 +40,7 @@
 #include <glib.h>
 
 /** @name Character Sets
- @{ 
+ @{
 */
 
 /** Collate two UTF-8 strings.  This function performs basic argument
@@ -74,7 +74,7 @@
  * routines @e require valid UTF-8 as input;
  * so data read from a file or the network should be checked
  * with g_utf8_validate() before doing anything else with it.
- * 
+ *
  * @param str a pointer to character data
  * @param max_len max bytes to validate, or -1 to go until NUL
  * @param end return location for end of valid data
@@ -139,7 +139,7 @@
 /** @} */
 
 /** @name GList Manipulation
- @{ 
+ @{
 */
 typedef gpointer (*GncGMapFunc)(gpointer data, gpointer user_data);
 
@@ -158,7 +158,7 @@
 /** @} */
 
 /** @name Message Logging
- @{ 
+ @{
 */
 void gnc_scm_log_warn(const gchar *msg);
 void gnc_scm_log_error(const gchar *msg);
@@ -168,7 +168,7 @@
 /** @} */
 
 /** @name glib Miscellaneous Functions
- @{ 
+ @{
 */
 
 /** Kill a process.  On UNIX send a SIGKILL, on Windows call TerminateProcess.

Modified: gnucash/trunk/src/core-utils/gnc-gobject-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gobject-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-gobject-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -27,7 +27,7 @@
 #include "gnc-gobject-utils.h"
 
 #include <gtk/gtk.h>	// For gtk_main_quit(). Can't get this to work with
-			// a g_source attached to the main glib context.
+// a g_source attached to the main glib context.
 
 
 static void gnc_gobject_weak_cb (gpointer user_data, GObject *object);
@@ -48,15 +48,16 @@
 static GHashTable*
 gnc_gobject_tracking_table (void)
 {
-  static GHashTable *singleton = NULL;
+    static GHashTable *singleton = NULL;
 
-  if (!singleton) {
-    singleton = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+    if (!singleton)
+    {
+        singleton = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 #if DEBUG_REFERENCE_COUNTING
-    gtk_quit_add (0, (GtkFunction)gnc_gobject_tracking_dump, NULL);
+        gtk_quit_add (0, (GtkFunction)gnc_gobject_tracking_dump, NULL);
 #endif
-  }
-  return singleton;
+    }
+    return singleton;
 }
 
 
@@ -71,9 +72,9 @@
 static void
 gnc_gobject_dump_gobject (GObject *object, const gchar *name)
 {
-  //printf("Enter %s: object %p, name %s\n", G_STRFUNC, object, name);
-  g_message("    object %p, ref count %d", object, object->ref_count);
-  //printf("Leave %s:\n", G_STRFUNC);
+    //printf("Enter %s: object %p, name %s\n", G_STRFUNC, object, name);
+    g_message("    object %p, ref count %d", object, object->ref_count);
+    //printf("Leave %s:\n", G_STRFUNC);
 }
 
 
@@ -86,11 +87,11 @@
 static gboolean
 gnc_gobject_dump_list (const gchar *name, GList *list, gpointer user_data)
 {
-  //printf("Enter %s: name %s, list %p\n", G_STRFUNC, name, list);
-  g_message("  %d %s", g_list_length(list), name);
-  g_list_foreach(list, (GFunc)gnc_gobject_dump_gobject, (gpointer)name);
-  //printf("Leave %s:\n", G_STRFUNC);
-  return TRUE;
+    //printf("Enter %s: name %s, list %p\n", G_STRFUNC, name, list);
+    g_message("  %d %s", g_list_length(list), name);
+    g_list_foreach(list, (GFunc)gnc_gobject_dump_gobject, (gpointer)name);
+    //printf("Leave %s:\n", G_STRFUNC);
+    return TRUE;
 }
 
 
@@ -103,16 +104,17 @@
 void
 gnc_gobject_tracking_dump (void)
 {
-  GHashTable *table;
+    GHashTable *table;
 
-  //printf("Enter %s:\n", G_STRFUNC);
-  table = gnc_gobject_tracking_table();
+    //printf("Enter %s:\n", G_STRFUNC);
+    table = gnc_gobject_tracking_table();
 
-  if (g_hash_table_size(table) > 0) {
-    g_message("The following objects remain alive:");
-    g_hash_table_foreach_remove(table, (GHRFunc)gnc_gobject_dump_list, NULL);
-  }
-  //printf("Leave %s:\n", G_STRFUNC);
+    if (g_hash_table_size(table) > 0)
+    {
+        g_message("The following objects remain alive:");
+        g_hash_table_foreach_remove(table, (GHRFunc)gnc_gobject_dump_list, NULL);
+    }
+    //printf("Leave %s:\n", G_STRFUNC);
 }
 
 
@@ -121,72 +123,78 @@
 void
 gnc_gobject_tracking_remember (GObject *object, GObjectClass *klass)
 {
-  GHashTable *table;
-  GList *list;
-  const gchar *name;
+    GHashTable *table;
+    GList *list;
+    const gchar *name;
 
-  g_return_if_fail(G_IS_OBJECT(object));
+    g_return_if_fail(G_IS_OBJECT(object));
 
-  /* Little dance here to handle startup conditions. During object
-   * initialization the object type changes as each each parent class
-   * is initialized.  The class passed to the initialization function
-   * is always the ultimate class of the object. */
-  if (klass == NULL)
-    klass = G_OBJECT_GET_CLASS(object);
-  name = g_type_name(G_TYPE_FROM_CLASS(klass));
+    /* Little dance here to handle startup conditions. During object
+     * initialization the object type changes as each each parent class
+     * is initialized.  The class passed to the initialization function
+     * is always the ultimate class of the object. */
+    if (klass == NULL)
+        klass = G_OBJECT_GET_CLASS(object);
+    name = g_type_name(G_TYPE_FROM_CLASS(klass));
 
-  //printf("Enter %s: object %p of type %s\n", G_STRFUNC, object, name);
-  table = gnc_gobject_tracking_table();
-  list = g_hash_table_lookup(table, name);
+    //printf("Enter %s: object %p of type %s\n", G_STRFUNC, object, name);
+    table = gnc_gobject_tracking_table();
+    list = g_hash_table_lookup(table, name);
 
-  if (g_list_index(list, object) != -1) {
-    g_critical("Object %p is already in list of %s", object, name);
-    //printf("Leave %s: already in list\n", G_STRFUNC);
-    return;
-  }
+    if (g_list_index(list, object) != -1)
+    {
+        g_critical("Object %p is already in list of %s", object, name);
+        //printf("Leave %s: already in list\n", G_STRFUNC);
+        return;
+    }
 
-  list = g_list_append(list, object);
-  g_hash_table_insert(table, g_strdup(name), list);
+    list = g_list_append(list, object);
+    g_hash_table_insert(table, g_strdup(name), list);
 
-  g_object_weak_ref(object, gnc_gobject_weak_cb, NULL);
-  //printf("Leave %s:\n", G_STRFUNC);
+    g_object_weak_ref(object, gnc_gobject_weak_cb, NULL);
+    //printf("Leave %s:\n", G_STRFUNC);
 }
 
 
 static gboolean
 gnc_gobject_tracking_forget_internal (GObject *object)
 {
-  GHashTable *table;
-  GList *list, *item;
-  const gchar *name;
+    GHashTable *table;
+    GList *list, *item;
+    const gchar *name;
 
-  g_return_val_if_fail(G_IS_OBJECT(object), FALSE);
+    g_return_val_if_fail(G_IS_OBJECT(object), FALSE);
 
-  name = G_OBJECT_TYPE_NAME(object);
-  //printf("Enter %s: object %p of type %s\n", G_STRFUNC, object, name);
-  table = gnc_gobject_tracking_table();
-  list = g_hash_table_lookup(table, name);
-  if (!list) {
-    //printf("Leave %s: list for %s objects not found.\n", G_STRFUNC, name);
-    return FALSE;
-  }
+    name = G_OBJECT_TYPE_NAME(object);
+    //printf("Enter %s: object %p of type %s\n", G_STRFUNC, object, name);
+    table = gnc_gobject_tracking_table();
+    list = g_hash_table_lookup(table, name);
+    if (!list)
+    {
+        //printf("Leave %s: list for %s objects not found.\n", G_STRFUNC, name);
+        return FALSE;
+    }
 
-  item = g_list_find(list, object);
-  if (!item) {
-    //printf("Leave %s: object %p not in %s object list.\n", G_STRFUNC,
-    //       object, name);
-    return FALSE;
-  }
+    item = g_list_find(list, object);
+    if (!item)
+    {
+        //printf("Leave %s: object %p not in %s object list.\n", G_STRFUNC,
+        //       object, name);
+        return FALSE;
+    }
 
-  list = g_list_remove_link(list, item);
-  if (list) {
-    g_hash_table_replace(table, g_strdup(name), list);
-    //printf("Leave %s: object removed.\n", G_STRFUNC);
-  } else {
-    g_hash_table_remove(table, name);
-    //printf("Leave %s: object and list removed.\n", G_STRFUNC);
-  }
-  return TRUE;
+    list = g_list_remove_link(list, item);
+    if (list)
+    {
+        g_hash_table_replace(table, g_strdup(name), list);
+        //printf("Leave %s: object removed.\n", G_STRFUNC);
+    }
+    else
+    {
+        g_hash_table_remove(table, name);
+        //printf("Leave %s: object and list removed.\n", G_STRFUNC);
+    }
+    return TRUE;
 }
 
 
@@ -195,8 +203,8 @@
 void
 gnc_gobject_tracking_forget (GObject *object)
 {
-  if (gnc_gobject_tracking_forget_internal(object))
-    g_object_weak_unref(object, gnc_gobject_weak_cb, NULL);
+    if (gnc_gobject_tracking_forget_internal(object))
+        g_object_weak_unref(object, gnc_gobject_weak_cb, NULL);
 }
 
 
@@ -212,7 +220,7 @@
 static void
 gnc_gobject_weak_cb (gpointer user_data, GObject *object)
 {
-  gnc_gobject_tracking_forget_internal(object);
+    gnc_gobject_tracking_forget_internal(object);
 }
 
 
@@ -221,12 +229,12 @@
 const GList *
 gnc_gobject_tracking_get_list (const gchar *name)
 {
-  GHashTable *table;
-  GList *list;
+    GHashTable *table;
+    GList *list;
 
-  //printf("Enter %s: name %s\n", G_STRFUNC, name);
-  table = gnc_gobject_tracking_table();
-  list = g_hash_table_lookup(table, name);
-  //printf("Leave %s: list %p\n", G_STRFUNC, list);
-  return list;
+    //printf("Enter %s: name %s\n", G_STRFUNC, name);
+    table = gnc_gobject_tracking_table();
+    list = g_hash_table_lookup(table, name);
+    //printf("Leave %s: list %p\n", G_STRFUNC, list);
+    return list;
 }

Modified: gnucash/trunk/src/core-utils/gnc-gobject-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gobject-utils.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-gobject-utils.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -42,7 +42,7 @@
 #include <glib-object.h>
 
 /** @name Gobject Tracking Functions
- *  @{ 
+ *  @{
  *
  *  This set of functions is used to maintain a "database" of objects
  *  that are built on top of a GObject (any level of nesting).  This

Modified: gnucash/trunk/src/core-utils/gnc-gtk-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gtk-utils.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-gtk-utils.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -39,39 +39,42 @@
  *  entry. */
 void
 gnc_cbe_set_by_string(GtkComboBoxEntry *cbe,
-		      const gchar *text)
+                      const gchar *text)
 {
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  gchar *tree_string;
-  gint column, index, id;
-  gboolean match;
+    GtkTreeModel *model;
+    GtkTreeIter iter;
+    gchar *tree_string;
+    gint column, index, id;
+    gboolean match;
 
-  model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe));
-  if (!gtk_tree_model_get_iter_first(model, &iter)) {
-    /* empty tree */
-    gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), -1);
-    return;
-  }
+    model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe));
+    if (!gtk_tree_model_get_iter_first(model, &iter))
+    {
+        /* empty tree */
+        gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), -1);
+        return;
+    }
 
-  column = gtk_combo_box_entry_get_text_column(cbe);
-  do {
-    gtk_tree_model_get(model, &iter, column, &tree_string, -1);
-    match = g_utf8_collate(text, tree_string) == 0;
-    g_free(tree_string);
-    if (!match)
-      continue;
+    column = gtk_combo_box_entry_get_text_column(cbe);
+    do
+    {
+        gtk_tree_model_get(model, &iter, column, &tree_string, -1);
+        match = g_utf8_collate(text, tree_string) == 0;
+        g_free(tree_string);
+        if (!match)
+            continue;
 
-    /* Found a matching string */
-    id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cbe), CHANGED_ID));
-    g_signal_handler_block(cbe, id);
-    gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cbe), &iter);
-    g_signal_handler_unblock(cbe, id);
+        /* Found a matching string */
+        id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cbe), CHANGED_ID));
+        g_signal_handler_block(cbe, id);
+        gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cbe), &iter);
+        g_signal_handler_unblock(cbe, id);
 
-    index = gtk_combo_box_get_active(GTK_COMBO_BOX(cbe));
-    g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
-    return;
-  } while (gtk_tree_model_iter_next(model, &iter));
+        index = gtk_combo_box_get_active(GTK_COMBO_BOX(cbe));
+        g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
+        return;
+    }
+    while (gtk_tree_model_iter_next(model, &iter));
 }
 
 
@@ -84,14 +87,14 @@
  *   @param cbe A pointer to a GtkComboBoxEntry widget. */
 static void
 gnc_cbe_changed_cb (GtkComboBox *widget,
-		    GtkComboBoxEntry *cbe)
+                    GtkComboBoxEntry *cbe)
 {
-  gint index;
+    gint index;
 
-  index = gtk_combo_box_get_active(widget);
-  if (index == -1)
-    return;
-  g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
+    index = gtk_combo_box_get_active(widget);
+    if (index == -1)
+        return;
+    g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
 }
 
 
@@ -113,18 +116,18 @@
  *   @param cbe A pointer to a currency entry widget. */
 static gboolean
 gnc_cbe_match_selected_cb (GtkEntryCompletion *completion,
-			   GtkTreeModel       *comp_model,
-			   GtkTreeIter        *comp_iter,
-			   GtkComboBoxEntry   *cbe)
+                           GtkTreeModel       *comp_model,
+                           GtkTreeIter        *comp_iter,
+                           GtkComboBoxEntry   *cbe)
 {
-  gint column;
-  gchar *text;
+    gint column;
+    gchar *text;
 
-  column = gtk_combo_box_entry_get_text_column(cbe);
-  gtk_tree_model_get(comp_model, comp_iter, column, &text, -1);
-  gnc_cbe_set_by_string(cbe, text);
-  g_free(text);
-  return FALSE;
+    column = gtk_combo_box_entry_get_text_column(cbe);
+    gtk_tree_model_get(comp_model, comp_iter, column, &text, -1);
+    gnc_cbe_set_by_string(cbe, text);
+    g_free(text);
+    return FALSE;
 }
 
 
@@ -142,79 +145,81 @@
  *   @param cbe A pointer to a currency entry widget. */
 static gboolean
 gnc_cbe_focus_out_cb (GtkEntry *entry,
-		      GdkEventFocus *event,
-		      GtkComboBoxEntry *cbe)
+                      GdkEventFocus *event,
+                      GtkComboBoxEntry *cbe)
 {
-  const gchar *text;
-  gint index;
+    const gchar *text;
+    gint index;
 
-  /* Make a final attempt to match the current text. */
-  text = gtk_entry_get_text(entry);
-  gnc_cbe_set_by_string(cbe, text);
+    /* Make a final attempt to match the current text. */
+    text = gtk_entry_get_text(entry);
+    gnc_cbe_set_by_string(cbe, text);
 
-  /* Get the last known index (which may have just been set). */
-  index = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cbe), LAST_INDEX));
-  gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), index);
-  return FALSE;
+    /* Get the last known index (which may have just been set). */
+    index = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cbe), LAST_INDEX));
+    gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), index);
+    return FALSE;
 }
 
 void
 gnc_cbe_add_completion (GtkComboBoxEntry *cbe)
 {
-  GtkEntry *entry;
-  GtkEntryCompletion *completion;
-  GtkTreeModel *model;
+    GtkEntry *entry;
+    GtkEntryCompletion *completion;
+    GtkTreeModel *model;
 
-  entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbe)));
-  completion = gtk_entry_get_completion(entry);
-  if (completion)
-    return;
+    entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbe)));
+    completion = gtk_entry_get_completion(entry);
+    if (completion)
+        return;
 
-  /* No completion yet? Set one up. */
-  completion = gtk_entry_completion_new();
-  model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe));
-  gtk_entry_completion_set_model(completion, model);
-  gtk_entry_completion_set_text_column(completion, 0);
-  gtk_entry_completion_set_inline_completion(completion, TRUE);
-  gtk_entry_set_completion(entry, completion);
-  g_object_unref(completion);
+    /* No completion yet? Set one up. */
+    completion = gtk_entry_completion_new();
+    model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe));
+    gtk_entry_completion_set_model(completion, model);
+    gtk_entry_completion_set_text_column(completion, 0);
+    gtk_entry_completion_set_inline_completion(completion, TRUE);
+    gtk_entry_set_completion(entry, completion);
+    g_object_unref(completion);
 }
 
 void
 gnc_cbe_require_list_item (GtkComboBoxEntry *cbe)
 {
-  GtkEntry *entry;
-  GtkEntryCompletion *completion;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  gint index, id;
+    GtkEntry *entry;
+    GtkEntryCompletion *completion;
+    GtkTreeModel *model;
+    GtkTreeIter iter;
+    gint index, id;
 
-  /* Ensure completion is set up. */
-  gnc_cbe_add_completion(cbe);
+    /* Ensure completion is set up. */
+    gnc_cbe_add_completion(cbe);
 
-  /* If an item in the combo box isn't already selected, then force
-   * select the first item. Take care, the combo box may not have been
-   * filled yet.  */
-  entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbe)));
-  completion = gtk_entry_get_completion(entry);
-  index = gtk_combo_box_get_active(GTK_COMBO_BOX(cbe));
-  if (index == -1) {
-    model = gtk_entry_completion_get_model(completion);
-    if (gtk_tree_model_get_iter_first(model, &iter)) {
-      gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), 0);
-      index = 0;
+    /* If an item in the combo box isn't already selected, then force
+     * select the first item. Take care, the combo box may not have been
+     * filled yet.  */
+    entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbe)));
+    completion = gtk_entry_get_completion(entry);
+    index = gtk_combo_box_get_active(GTK_COMBO_BOX(cbe));
+    if (index == -1)
+    {
+        model = gtk_entry_completion_get_model(completion);
+        if (gtk_tree_model_get_iter_first(model, &iter))
+        {
+            gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), 0);
+            index = 0;
+        }
     }
-  }
-  g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
+    g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
 
-  /* Now the signals to make sure the user can't leave the
-     widget without a valid currency. */
-  id = g_signal_connect(cbe, "changed",
-			G_CALLBACK(gnc_cbe_changed_cb), cbe);
-  g_signal_connect(completion, "match_selected",
-		   G_CALLBACK(gnc_cbe_match_selected_cb), cbe);
-  g_signal_connect(entry, "focus-out-event",
-		   G_CALLBACK(gnc_cbe_focus_out_cb), cbe);
+    /* Now the signals to make sure the user can't leave the
+       widget without a valid currency. */
+    id = g_signal_connect(cbe, "changed",
+                          G_CALLBACK(gnc_cbe_changed_cb), cbe);
+    g_signal_connect(completion, "match_selected",
+                     G_CALLBACK(gnc_cbe_match_selected_cb), cbe);
+    g_signal_connect(entry, "focus-out-event",
+                     G_CALLBACK(gnc_cbe_focus_out_cb), cbe);
 
-  g_object_set_data(G_OBJECT(cbe), CHANGED_ID, GINT_TO_POINTER(id));
+    g_object_set_data(G_OBJECT(cbe), CHANGED_ID, GINT_TO_POINTER(id));
 }

Modified: gnucash/trunk/src/core-utils/gnc-gtk-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gtk-utils.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-gtk-utils.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -38,7 +38,7 @@
 #include <gtk/gtk.h>
 
 /** @name gtk Miscellaneous Functions
- @{ 
+ @{
 */
 
 void gnc_cbe_set_by_string(GtkComboBoxEntry *cbe, const gchar *text);

Modified: gnucash/trunk/src/core-utils/gnc-main.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-main.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/core-utils/gnc-main.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -29,7 +29,7 @@
 static gboolean extras_enabled = 0;
 static const gchar *gconf_path;
 
-void 
+void
 gnc_main_set_namespace_regexp(const gchar *str)
 {
     if (namespace_regexp)

Modified: gnucash/trunk/src/doc/doxygen_main_page.c
===================================================================
--- gnucash/trunk/src/doc/doxygen_main_page.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/doc/doxygen_main_page.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -14,9 +14,9 @@
 
 \subsection manualguide External documentation.
 
-Please refer to the main 
+Please refer to the main
 <a href="http://www.gnucash.org/docs.phtml">documentation
-page</a> on the gnucash website which includes links to the 
+page</a> on the gnucash website which includes links to the
 GnuCash Manual and the Concepts Guide in various formats.
 
 \subsection texihtml Documentation elsewhere in the source tree.
@@ -57,7 +57,7 @@
 - \ref todo
 - \ref userprefs
 
-Each overview in this section is generated directly from the 
+Each overview in this section is generated directly from the
 source files using Doxygen but some topics need updating.
 
 \section maingeneral General Doxygen help.
@@ -89,12 +89,12 @@
 There is the beginning of a style guide for documenting under
 \ref tipshints.
 
-The Book Merge files are an attempt to document "by the book". 
+The Book Merge files are an attempt to document "by the book".
 \ref BookMerge\n
-Feel free to start documenting or playing with doxygen configuration. 
+Feel free to start documenting or playing with doxygen configuration.
 This main page can be found in src/doc/doxygen_main_page.c .
 
-Each doxygen section must be within a single comment block although 
+Each doxygen section must be within a single comment block although
 large comment blocks can be split into separate pages:
 \ref stylediscussion.
 
@@ -106,8 +106,8 @@
 - \ref reference Links to the Doxygen manual
 
 Code snippets need special handling in the text overviews. Change all
-comment markers to // (so that the overview comment remains intact) 
-and then wrap each code snippet in the \a verbatim \a endverbatim 
+comment markers to // (so that the overview comment remains intact)
+and then wrap each code snippet in the \a verbatim \a endverbatim
 doxygen markers.
 
 One useful method is to edit these .txt files using the syntax highlighting
@@ -120,9 +120,9 @@
  - \ref index Introduction
  - \ref stylediscussion Long comments, pages, editors
  - \ref reference The Doxygen manual
- 
+
 \section tips An introduction to doxygen markup
- 
+
 \subsection Locations What to document
 
 All declarations for:
@@ -137,7 +137,7 @@
 
 \subsection Files Private files
 
-If your declarations are in separate files, like private header files, 
+If your declarations are in separate files, like private header files,
 a simple block can still be linked into doxygen as long as the file is
 identified to doxygen using a '\\file' section:
 
@@ -147,11 +147,11 @@
 
 \subsection Methods How to document
 
-Every doxygen comment block starts with an adapted comment marker. 
+Every doxygen comment block starts with an adapted comment marker.
 You can use an extra slash /// or an extra asterisk ** . Blocks end
 in the usual way. Doxygen accepts commands using a backslash.
 
-To put a description with each function or structure, use '\\brief' 
+To put a description with each function or structure, use '\\brief'
 End the brief description with a blank line. The rest of the documentation will
 then be shown in the body of the doxygen page.
 
@@ -166,7 +166,7 @@
 		- revert to previous list
 
 	End the list with a blank line.
-Use :: at the start of a function or structure to link to the page 
+Use :: at the start of a function or structure to link to the page
 for that function in the doxygen documentation. e.g. ::qof_class_foreach
 
 Use the param command to describe function parameters in the text.
@@ -196,7 +196,7 @@
 can be handled more easily by splitting the old single comment into repeated
 comments, split into pages. I've worked on doxygen files in Kate, KWrite and XCode (MacOSX) and
 the comment higlighting works fine. If you do have problems, particularly when
-you start a new line within an existing comment, enter a character at the end of 
+you start a new line within an existing comment, enter a character at the end of
 the last highlighted line to refresh the highlighting. Some editors have a specific
 refresh option.
 
@@ -209,7 +209,7 @@
 Structures" page? Unfortunately I don't know how.
 
 [codehelpgpg 2004-07-25] Yes, there is a way of linking to these data structures.
-Make sure that the private header is included in the documentation by including a 
+Make sure that the private header is included in the documentation by including a
 \\file command in the private header file. Then include a short doxygen comment above
 the declaration. Doxygen will accept both valid C struct definition formats.
 
@@ -220,7 +220,7 @@
 - \ref index Introduction
 - \ref tipshints Tips and hints for using doxygen
 - \ref stylediscussion Long comments, pages, editors
-	
+
 The Doxygen web site (http://www.stack.nl/~dimitri/doxygen/) has a
 complete user manual.  For the impatient, here are the most
 interesting sections:
@@ -240,7 +240,7 @@
 News about GnuCash as well as the latest version can always be found at http://www.gnucash.org/
 
 \subsection email Email
-If you have any suggestions concerning this documentation, do not hesitate to send suggestions to 
+If you have any suggestions concerning this documentation, do not hesitate to send suggestions to
 gnucash-devel (see http://www.gnucash.org/en/lists.phtml for details)
 
 Benoit Grégoire <bock at step.polymtl.ca>

Modified: gnucash/trunk/src/gnc-module/gnc-module.c
===================================================================
--- gnucash/trunk/src/gnc-module/gnc-module.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/gnc-module.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -17,22 +17,23 @@
 static GHashTable * loaded_modules = NULL;
 static GList      * module_info = NULL;
 
-typedef struct {
-  char * module_path;
-  char * module_description;
-  char * module_filepath;
-  int    module_interface;
-  int    module_age;
-  int    module_revision;
+typedef struct
+{
+    char * module_path;
+    char * module_description;
+    char * module_filepath;
+    int    module_interface;
+    int    module_age;
+    int    module_revision;
 } GNCModuleInfo;
 
 typedef struct
 {
-  GModule       * gmodule;
-  gchar         * filename;
-  int           load_count;
-  GNCModuleInfo * info;
-  int           (* init_func)(int refcount);
+    GModule       * gmodule;
+    gchar         * filename;
+    int           load_count;
+    GNCModuleInfo * info;
+    int           (* init_func)(int refcount);
 } GNCLoadedModule;
 
 static GNCModuleInfo * gnc_module_get_info(const char * lib_path);
@@ -42,112 +43,112 @@
  * return a list of dirs to look in for gnc_module libraries
  *************************************************************/
 
-static GList * 
-gnc_module_system_search_dirs(void) 
+static GList *
+gnc_module_system_search_dirs(void)
 {
-  const char *spath = g_getenv("GNC_MODULE_PATH");
-  GList * list    = NULL;
-  GString * token = g_string_new(NULL);
-  int   escchar   = 0;
-  const char *cpos;
+    const char *spath = g_getenv("GNC_MODULE_PATH");
+    GList * list    = NULL;
+    GString * token = g_string_new(NULL);
+    int   escchar   = 0;
+    const char *cpos;
 
-  if(!spath) 
-  {
-    spath = DEFAULT_MODULE_PATH;
-  }
-  
-  for(cpos = spath; *cpos; cpos++) 
-  {
-    switch(*cpos) 
+    if (!spath)
     {
+        spath = DEFAULT_MODULE_PATH;
+    }
+
+    for (cpos = spath; *cpos; cpos++)
+    {
+        switch (*cpos)
+        {
 #ifndef G_OS_WIN32
-    /* On windows, with '\' as the directory separator character,
-       this additional de-quoting will make every path processing
-       fail miserably. Anyway this should probably be thrown out
-       altogether, because this additional level of de-quoting
-       (after shell quoting) is completely unexpected and
-       uncommon. */
-    case '\\':
-      if(!escchar) 
-      {
-        escchar = TRUE;      
-      }
-      else 
-      {
-        g_string_append_c(token, *cpos);
-        escchar = FALSE;
-      }
-      break;
+            /* On windows, with '\' as the directory separator character,
+               this additional de-quoting will make every path processing
+               fail miserably. Anyway this should probably be thrown out
+               altogether, because this additional level of de-quoting
+               (after shell quoting) is completely unexpected and
+               uncommon. */
+        case '\\':
+            if (!escchar)
+            {
+                escchar = TRUE;
+            }
+            else
+            {
+                g_string_append_c(token, *cpos);
+                escchar = FALSE;
+            }
+            break;
 #endif
-      
-      /* This is ':' on UNIX machines and ';' under Windows. */
-    case G_SEARCHPATH_SEPARATOR:
-      if(!escchar) 
-      {
+
+            /* This is ':' on UNIX machines and ';' under Windows. */
+        case G_SEARCHPATH_SEPARATOR:
+            if (!escchar)
+            {
+                list = g_list_append(list, token->str);
+                g_string_free(token, FALSE);
+                token = g_string_new(NULL);
+            }
+            else
+            {
+                g_string_append_c(token, *cpos);
+                escchar = FALSE;
+            }
+            break;
+
+        default:
+            g_string_append_c(token, *cpos);
+            escchar = FALSE;
+            break;
+        }
+    }
+    if (token->len)
+    {
         list = g_list_append(list, token->str);
         g_string_free(token, FALSE);
-        token = g_string_new(NULL);
-      }
-      else 
-      {
-        g_string_append_c(token, *cpos);
-        escchar = FALSE;
-      }
-      break;
-
-    default:
-      g_string_append_c(token, *cpos);
-      escchar = FALSE;
-      break;
     }
-  }
-  if(token->len) 
-  {
-    list = g_list_append(list, token->str);
-    g_string_free(token, FALSE);
-  }
-  else 
-  {
-    g_string_free(token, TRUE);
-  }
-  return list;
+    else
+    {
+        g_string_free(token, TRUE);
+    }
+    return list;
 }
 
 /*************************************************************
  * gnc_module_system_setup_load_path
- * initialize the Guile load path 
+ * initialize the Guile load path
  *************************************************************/
 
 static void
 gnc_module_system_setup_load_path(void)
 {
-  GList * dirs = gnc_module_system_search_dirs();
-  GList * lp;
+    GList * dirs = gnc_module_system_search_dirs();
+    GList * lp;
 
-  if(dirs)
-  {
-    char *envt = g_strdup(g_getenv("LD_LIBRARY_PATH"));
-    
-    if(!envt)
+    if (dirs)
     {
-      envt = g_strdup("");
+        char *envt = g_strdup(g_getenv("LD_LIBRARY_PATH"));
+
+        if (!envt)
+        {
+            envt = g_strdup("");
+        }
+
+        for (lp = dirs; lp; lp = lp->next)
+        {
+            char *tmp = g_strdup_printf("%s:%s", envt, (char *) lp->data);
+            g_free(envt);
+            envt = tmp;
+            g_free(lp->data);
+        }
+        g_list_free(dirs);
+
+        if (!g_setenv("LD_LIBRARY_PATH", envt, TRUE))
+        {
+            g_warning ("gnc-module failed to set LD_LIBRARY_PATH");
+        }
+        g_free(envt);
     }
-    
-    for(lp=dirs; lp; lp=lp->next) 
-    {
-      char *tmp = g_strdup_printf("%s:%s", envt, (char *) lp->data);
-      g_free(envt);
-      envt = tmp;
-      g_free(lp->data);
-    }
-    g_list_free(dirs);
-    
-    if (!g_setenv("LD_LIBRARY_PATH", envt, TRUE))
-    {
-      g_warning ("gnc-module failed to set LD_LIBRARY_PATH");
-    }
-    g_free(envt);
-  }
 }
 
 /*************************************************************
@@ -158,97 +159,97 @@
 void
 gnc_module_system_init(void)
 {
-  if (loaded_modules)
-    return;
+    if (loaded_modules)
+        return;
 
-  loaded_modules = g_hash_table_new(g_direct_hash, g_direct_equal);
+    loaded_modules = g_hash_table_new(g_direct_hash, g_direct_equal);
 
-  gnc_module_system_setup_load_path();
+    gnc_module_system_setup_load_path();
 
-  /* now crawl the GNC_MODULE_PATH to find likely libraries */
-  gnc_module_system_refresh();
+    /* now crawl the GNC_MODULE_PATH to find likely libraries */
+    gnc_module_system_refresh();
 }
 
 
 /*************************************************************
- * gnc_module_system_refresh 
+ * gnc_module_system_refresh
  * build the database of modules by looking through the
  * GNC_MODULE_PATH
  *************************************************************/
 
 void
-gnc_module_system_refresh(void) 
+gnc_module_system_refresh(void)
 {
-  GList * search_dirs; 
-  GList * current;
+    GList * search_dirs;
+    GList * current;
 
-  if(!loaded_modules) 
-  {
-    gnc_module_system_init();
-  }
-  
-  /* get the GNC_MODULE_PATH and split it into directories */
-  search_dirs = gnc_module_system_search_dirs();
+    if (!loaded_modules)
+    {
+        gnc_module_system_init();
+    }
 
-  /* look in each search directory */
-  for(current = search_dirs; current; current = current->next) 
-  {
-      GDir *d = g_dir_open(current->data, 0,NULL);
-      const gchar *dent = NULL;
-      char * fullpath = NULL;
-      GNCModuleInfo * info;
+    /* get the GNC_MODULE_PATH and split it into directories */
+    search_dirs = gnc_module_system_search_dirs();
 
-      if (!d) continue;
+    /* look in each search directory */
+    for (current = search_dirs; current; current = current->next)
+    {
+        GDir *d = g_dir_open(current->data, 0, NULL);
+        const gchar *dent = NULL;
+        char * fullpath = NULL;
+        GNCModuleInfo * info;
 
-      while ((dent = g_dir_read_name(d)) != NULL)
-      {
-        /* is the file a loadable module? */
+        if (!d) continue;
 
-        /* Gotcha: On MacOS, G_MODULE_SUFFIX is defined as "so", but if we do
-         * not build clean libtool modules with "-module", we get dynamic
-         * libraries ending on .dylib */
-        if (g_str_has_suffix(dent, "." G_MODULE_SUFFIX) ||
-            g_str_has_suffix(dent, ".dylib"))
+        while ((dent = g_dir_read_name(d)) != NULL)
         {
-          /* get the full path name, then dlopen the library and see
-           * if it has the appropriate symbols to be a gnc_module */
-          fullpath = g_build_filename((const gchar *)(current->data),
-                                      dent, (char*)NULL);
-          info     = gnc_module_get_info(fullpath);
-          
-          if(info) 
-          {
-            module_info = g_list_prepend(module_info, info);
-          }
-          g_free(fullpath);
+            /* is the file a loadable module? */
+
+            /* Gotcha: On MacOS, G_MODULE_SUFFIX is defined as "so", but if we do
+             * not build clean libtool modules with "-module", we get dynamic
+             * libraries ending on .dylib */
+            if (g_str_has_suffix(dent, "." G_MODULE_SUFFIX) ||
+                    g_str_has_suffix(dent, ".dylib"))
+            {
+                /* get the full path name, then dlopen the library and see
+                 * if it has the appropriate symbols to be a gnc_module */
+                fullpath = g_build_filename((const gchar *)(current->data),
+                                            dent, (char*)NULL);
+                info     = gnc_module_get_info(fullpath);
+
+                if (info)
+                {
+                    module_info = g_list_prepend(module_info, info);
+                }
+                g_free(fullpath);
+            }
         }
-      }
-      g_dir_close(d);
+        g_dir_close(d);
 
-  }
-  /* free the search dir strings */
-  for(current = search_dirs; current; current=current->next) 
-  {
-    g_free(current->data);
-  }
-  g_list_free(current);
+    }
+    /* free the search dir strings */
+    for (current = search_dirs; current; current = current->next)
+    {
+        g_free(current->data);
+    }
+    g_list_free(current);
 }
 
 
 /*************************************************************
- *  gnc_module_system_modinfo 
+ *  gnc_module_system_modinfo
  *  return the list of module information
  *************************************************************/
 
 GList *
-gnc_module_system_modinfo(void) 
+gnc_module_system_modinfo(void)
 {
-  if(!loaded_modules) 
-  {
-    gnc_module_system_init();
-  }
-  
-  return module_info;
+    if (!loaded_modules)
+    {
+        gnc_module_system_init();
+    }
+
+    return module_info;
 }
 
 
@@ -259,34 +260,34 @@
 static gboolean
 gnc_module_get_symbol(GModule* gmodule, const char* symbol, gpointer res)
 {
-  gchar** strs;
-  gchar* munged_symbol;
-  gchar *basename;
-  gboolean ret;
+    gchar** strs;
+    gchar* munged_symbol;
+    gchar *basename;
+    gboolean ret;
 
-  g_return_val_if_fail(gmodule, FALSE);
-  g_return_val_if_fail(symbol, FALSE);
+    g_return_val_if_fail(gmodule, FALSE);
+    g_return_val_if_fail(symbol, FALSE);
 
-  /* Separate the file from its extension */
-  /* Note: This currently does not work with versioned libtool dlls,
-   * as they are named like libgncmodbaz-0.dll */
-  basename = g_path_get_basename(g_module_name(gmodule));
-  strs = g_strsplit(basename, ".", 2);
-  g_free(basename);
+    /* Separate the file from its extension */
+    /* Note: This currently does not work with versioned libtool dlls,
+     * as they are named like libgncmodbaz-0.dll */
+    basename = g_path_get_basename(g_module_name(gmodule));
+    strs = g_strsplit(basename, ".", 2);
+    g_free(basename);
 
-  /* Translate any dashes to underscores */
-  g_strdelimit(strs[0], "-", '_');
+    /* Translate any dashes to underscores */
+    g_strdelimit(strs[0], "-", '_');
 
-  /* Create the symbol <filename>_<symbol> and retrieve that symbol */
-  munged_symbol = g_strdup_printf("%s_%s", strs[0], symbol);
-  ret = g_module_symbol(gmodule, munged_symbol, res);
+    /* Create the symbol <filename>_<symbol> and retrieve that symbol */
+    munged_symbol = g_strdup_printf("%s_%s", strs[0], symbol);
+    ret = g_module_symbol(gmodule, munged_symbol, res);
 
-  /* printf("(%d) Looking for symbol %s\n", ret, munged_symbol); */
+    /* printf("(%d) Looking for symbol %s\n", ret, munged_symbol); */
 
-  /* Free everything */
-  g_strfreev(strs);
-  g_free(munged_symbol);
-  return ret;
+    /* Free everything */
+    g_strfreev(strs);
+    g_free(munged_symbol);
+    return ret;
 }
 
 /*************************************************************
@@ -298,148 +299,152 @@
 static GNCModuleInfo *
 gnc_module_get_info(const char * fullpath)
 {
-  GModule *gmodule;
-  gpointer modsysver;
-  GNCModuleInfo *info = NULL;
-  gpointer initfunc, pathfunc, descripfunc, iface, revision, age;
-  gchar * (* f_path)(void);
-  gchar * (* f_descrip)(void);
+    GModule *gmodule;
+    gpointer modsysver;
+    GNCModuleInfo *info = NULL;
+    gpointer initfunc, pathfunc, descripfunc, iface, revision, age;
+    gchar * (* f_path)(void);
+    gchar * (* f_descrip)(void);
 
-/*   g_debug("(init) dlopening '%s'\n", fullpath); */
-  gmodule = g_module_open(fullpath, G_MODULE_BIND_MASK);
-  if (gmodule == NULL) {
-      g_warning("Failed to dlopen() '%s': %s\n", fullpath, g_module_error());
-      return NULL;
-  }
+    /*   g_debug("(init) dlopening '%s'\n", fullpath); */
+    gmodule = g_module_open(fullpath, G_MODULE_BIND_MASK);
+    if (gmodule == NULL)
+    {
+        g_warning("Failed to dlopen() '%s': %s\n", fullpath, g_module_error());
+        return NULL;
+    }
 
-  /* the modsysver tells us what the expected symbols and their
-   * types are */
-  if (!gnc_module_get_symbol(gmodule, "gnc_module_system_interface", &modsysver)) {
-/*       g_debug("Module '%s' does not contain 'gnc_module_system_interface'\n", */
-/*                 fullpath); */
-      goto get_info_close;
-  }
+    /* the modsysver tells us what the expected symbols and their
+     * types are */
+    if (!gnc_module_get_symbol(gmodule, "gnc_module_system_interface", &modsysver))
+    {
+        /*       g_debug("Module '%s' does not contain 'gnc_module_system_interface'\n", */
+        /*                 fullpath); */
+        goto get_info_close;
+    }
 
-  if (*(int *)modsysver != 0) {
-      g_warning("Module '%s' requires newer module system\n", fullpath);
-      goto get_info_close;
-  }
+    if (*(int *)modsysver != 0)
+    {
+        g_warning("Module '%s' requires newer module system\n", fullpath);
+        goto get_info_close;
+    }
 
-  if (!gnc_module_get_symbol(gmodule, "gnc_module_init", &initfunc) ||
-      !gnc_module_get_symbol(gmodule, "gnc_module_path", &pathfunc) ||
-      !gnc_module_get_symbol(gmodule, "gnc_module_description", &descripfunc) ||
-      !gnc_module_get_symbol(gmodule, "gnc_module_current", &iface) ||
-      !gnc_module_get_symbol(gmodule, "gnc_module_revision", &revision) ||
-      !gnc_module_get_symbol(gmodule, "gnc_module_age", &age)) {
-    g_warning("Module '%s' does not match module signature\n", fullpath);
-    goto get_info_close;
-  }
+    if (!gnc_module_get_symbol(gmodule, "gnc_module_init", &initfunc) ||
+            !gnc_module_get_symbol(gmodule, "gnc_module_path", &pathfunc) ||
+            !gnc_module_get_symbol(gmodule, "gnc_module_description", &descripfunc) ||
+            !gnc_module_get_symbol(gmodule, "gnc_module_current", &iface) ||
+            !gnc_module_get_symbol(gmodule, "gnc_module_revision", &revision) ||
+            !gnc_module_get_symbol(gmodule, "gnc_module_age", &age))
+    {
+        g_warning("Module '%s' does not match module signature\n", fullpath);
+        goto get_info_close;
+    }
 
-  /* we have found a gnc_module. */
-  info = g_new0(GNCModuleInfo, 1);
-  f_path                   = pathfunc;
-  f_descrip                = descripfunc;
-  info->module_path        = f_path();
-  info->module_description = f_descrip();
-  info->module_filepath    = g_strdup(fullpath);
-  info->module_interface   = *(int *)iface;
-  info->module_age         = *(int *)age;
-  info->module_revision    = *(int *)revision;
+    /* we have found a gnc_module. */
+    info = g_new0(GNCModuleInfo, 1);
+    f_path                   = pathfunc;
+    f_descrip                = descripfunc;
+    info->module_path        = f_path();
+    info->module_description = f_descrip();
+    info->module_filepath    = g_strdup(fullpath);
+    info->module_interface   = *(int *)iface;
+    info->module_age         = *(int *)age;
+    info->module_revision    = *(int *)revision;
 
 
 get_info_close:
-/*   g_debug("(init) closing '%s'\n", fullpath); */
-  g_module_close(gmodule);
+    /*   g_debug("(init) closing '%s'\n", fullpath); */
+    g_module_close(gmodule);
 
-  return info;
+    return info;
 }
 
 
 /*************************************************************
- * gnc_module_locate 
+ * gnc_module_locate
  * find the best matching module for the name, interface pair
  *************************************************************/
 
-static GNCModuleInfo * 
-gnc_module_locate(const gchar * module_name, int iface) 
+static GNCModuleInfo *
+gnc_module_locate(const gchar * module_name, int iface)
 {
-  GNCModuleInfo * best    = NULL;
-  GNCModuleInfo * current = NULL;
-  GList * lptr;
+    GNCModuleInfo * best    = NULL;
+    GNCModuleInfo * current = NULL;
+    GList * lptr;
 
-  if(!loaded_modules) 
-  {
-    gnc_module_system_init();
-  }
-  
-  for(lptr = module_info; lptr; lptr = lptr->next) 
-  {
-    current = lptr->data;
-    if(!strcmp(module_name, current->module_path) &&
-       (iface >= (current->module_interface - current->module_age)) &&
-       (iface <= current->module_interface)) 
+    if (!loaded_modules)
     {
-      if(best) 
-      {
-        if((current->module_interface > best->module_interface) ||
-           ((current->module_interface == best->module_interface) &&
-            (current->module_age > best->module_age)) ||
-           ((current->module_interface == best->module_interface) &&
-            (current->module_age == best->module_age) &&
-            (current->module_revision > best->module_revision))) 
+        gnc_module_system_init();
+    }
+
+    for (lptr = module_info; lptr; lptr = lptr->next)
+    {
+        current = lptr->data;
+        if (!strcmp(module_name, current->module_path) &&
+                (iface >= (current->module_interface - current->module_age)) &&
+                (iface <= current->module_interface))
         {
-          best = current;
+            if (best)
+            {
+                if ((current->module_interface > best->module_interface) ||
+                        ((current->module_interface == best->module_interface) &&
+                         (current->module_age > best->module_age)) ||
+                        ((current->module_interface == best->module_interface) &&
+                         (current->module_age == best->module_age) &&
+                         (current->module_revision > best->module_revision)))
+                {
+                    best = current;
+                }
+            }
+            else
+            {
+                best = current;
+            }
         }
-      }
-      else 
-      {
-        best = current;
-      }
-    } 
-  }
-  return best;
+    }
+    return best;
 }
 
 static void
-list_loaded (gpointer k, gpointer v, gpointer data) 
+list_loaded (gpointer k, gpointer v, gpointer data)
 {
-  GList ** l = data;
-  *l = g_list_prepend(*l, v);
+    GList ** l = data;
+    *l = g_list_prepend(*l, v);
 }
 
 static GNCLoadedModule *
 gnc_module_check_loaded(const char * module_name, gint iface)
 {
-  GNCModuleInfo * modinfo = gnc_module_locate(module_name, iface);
-  GList * modules = NULL;
-  GList * p = NULL;
-  GNCLoadedModule * rv = NULL;
+    GNCModuleInfo * modinfo = gnc_module_locate(module_name, iface);
+    GList * modules = NULL;
+    GList * p = NULL;
+    GNCLoadedModule * rv = NULL;
 
-  if (modinfo == NULL)
-  {
-    return NULL;
-  }
+    if (modinfo == NULL)
+    {
+        return NULL;
+    }
 
-  if (!loaded_modules)
-  {
-    gnc_module_system_init();
-  }
+    if (!loaded_modules)
+    {
+        gnc_module_system_init();
+    }
 
-  /* turn the loaded-modules table into a list */
-  g_hash_table_foreach(loaded_modules, list_loaded, &modules);
+    /* turn the loaded-modules table into a list */
+    g_hash_table_foreach(loaded_modules, list_loaded, &modules);
 
-  /* walk the list to see if the file we want is already open */
-  for (p=modules; p; p=p->next)
-  {
-    GNCLoadedModule * lm = p->data;
-    if (!strcmp(lm->filename, modinfo->module_filepath))
+    /* walk the list to see if the file we want is already open */
+    for (p = modules; p; p = p->next)
     {
-      rv = lm;
-      break;
+        GNCLoadedModule * lm = p->data;
+        if (!strcmp(lm->filename, modinfo->module_filepath))
+        {
+            rv = lm;
+            break;
+        }
     }
-  }
-  g_list_free(modules);
-  return rv;
+    g_list_free(modules);
+    return rv;
 }
 
 
@@ -452,121 +457,122 @@
 gnc_module_load_common(char * module_name, gint iface, gboolean optional)
 {
 
-  GNCLoadedModule * info;
-  GModule         * gmodule;
-  GNCModuleInfo   * modinfo;
+    GNCLoadedModule * info;
+    GModule         * gmodule;
+    GNCModuleInfo   * modinfo;
 
-  if(!loaded_modules)
-  {
-    gnc_module_system_init();
-  }
+    if (!loaded_modules)
+    {
+        gnc_module_system_init();
+    }
 
-  info = gnc_module_check_loaded(module_name, iface);
+    info = gnc_module_check_loaded(module_name, iface);
 
-  /* if the module's already loaded, just increment its use count.
-   * otherwise, load it and check for the initializer
-   * "gnc_module_init".  if we find that, assume it's a gnucash module
-   * and run the function. */
+    /* if the module's already loaded, just increment its use count.
+     * otherwise, load it and check for the initializer
+     * "gnc_module_init".  if we find that, assume it's a gnucash module
+     * and run the function. */
 
-  if (info)
-  {
-    /* module already loaded ... call the init thunk */
-    if (info->init_func)
+    if (info)
     {
-      if (info->init_func(info->load_count))
-      {
-        info->load_count++;
-        return info;
-      }
-      else
-      {
-        g_warning ("module init failed: %s", module_name);
+        /* module already loaded ... call the init thunk */
+        if (info->init_func)
+        {
+            if (info->init_func(info->load_count))
+            {
+                info->load_count++;
+                return info;
+            }
+            else
+            {
+                g_warning ("module init failed: %s", module_name);
+                return NULL;
+            }
+        }
+        else
+        {
+            g_warning ("module has no init func: %s", module_name);
+            return NULL;
+        }
+        /* NOTREACHED */
+        g_error("internal error");
         return NULL;
-      }
     }
-    else {
-      g_warning ("module has no init func: %s", module_name);
-      return NULL;
-    }
-    /* NOTREACHED */
-    g_error("internal error");
-    return NULL;
-  }
 
-  modinfo = gnc_module_locate(module_name, iface);
-  if (!modinfo)
-  {
-    if (optional)
+    modinfo = gnc_module_locate(module_name, iface);
+    if (!modinfo)
     {
-      g_message ("Could not locate optional module %s interface v.%d",
-	module_name, iface);
+        if (optional)
+        {
+            g_message ("Could not locate optional module %s interface v.%d",
+                       module_name, iface);
+        }
+        else
+        {
+            g_warning ("Could not locate module %s interface v.%d",
+                       module_name, iface);
+        }
+        return NULL;
     }
-    else
-    {
-      g_warning ("Could not locate module %s interface v.%d",
-	module_name, iface);
-    }
-    return NULL;
-  }
 
-/*     if (modinfo) */
-/*       g_debug("(init) loading '%s' from '%s'\n", module_name, */
-/*               modinfo->module_filepath); */
+    /*     if (modinfo) */
+    /*       g_debug("(init) loading '%s' from '%s'\n", module_name, */
+    /*               modinfo->module_filepath); */
 
-  if ((gmodule = g_module_open(modinfo->module_filepath, 0)) != NULL)
-  {
-    gpointer initfunc;
-
-    if (gnc_module_get_symbol(gmodule, "gnc_module_init", &initfunc))
+    if ((gmodule = g_module_open(modinfo->module_filepath, 0)) != NULL)
     {
-      /* stick it in the hash table */
-      info = g_new0(GNCLoadedModule, 1);
-      info->gmodule    = gmodule;
-      info->filename   = g_strdup(modinfo->module_filepath);
-      info->load_count = 1;
-      info->init_func  = initfunc;
-      g_hash_table_insert(loaded_modules, info, info);
+        gpointer initfunc;
 
-      /* now call its init function.  this should load any dependent
-       * modules, too.  If it doesn't return TRUE unload the module. */
-      if (!info->init_func(0))
-      {
-	/* init failed. unload the module. */
-	g_warning ("Initialization failed for module %s\n", module_name);
-	g_hash_table_remove(loaded_modules, info);
-	g_free(info->filename);
-	g_free(info);
-	/* g_module_close(module); */
-	return NULL;
-      }
+        if (gnc_module_get_symbol(gmodule, "gnc_module_init", &initfunc))
+        {
+            /* stick it in the hash table */
+            info = g_new0(GNCLoadedModule, 1);
+            info->gmodule    = gmodule;
+            info->filename   = g_strdup(modinfo->module_filepath);
+            info->load_count = 1;
+            info->init_func  = initfunc;
+            g_hash_table_insert(loaded_modules, info, info);
 
-      return info;
+            /* now call its init function.  this should load any dependent
+             * modules, too.  If it doesn't return TRUE unload the module. */
+            if (!info->init_func(0))
+            {
+                /* init failed. unload the module. */
+                g_warning ("Initialization failed for module %s\n", module_name);
+                g_hash_table_remove(loaded_modules, info);
+                g_free(info->filename);
+                g_free(info);
+                /* g_module_close(module); */
+                return NULL;
+            }
+
+            return info;
+        }
+        else
+        {
+            g_warning ("Module %s (%s) is not a gnc-module.\n", module_name,
+                       modinfo->module_filepath);
+            //lt_dlclose(handle);
+        }
+        return info;
     }
-    else
-    {
-      g_warning ("Module %s (%s) is not a gnc-module.\n", module_name,
-		 modinfo->module_filepath);
-      //lt_dlclose(handle);
-    }
-    return info;
-  }
 
-  g_warning ("Failed to open module %s: %s\n", module_name, g_module_error());
+    g_warning ("Failed to open module %s: %s\n", module_name, g_module_error());
 
-  return NULL;
+    return NULL;
 }
 
 
-GNCModule 
-gnc_module_load(char * module_name, gint iface) 
+GNCModule
+gnc_module_load(char * module_name, gint iface)
 {
-  return gnc_module_load_common(module_name, iface, FALSE);
+    return gnc_module_load_common(module_name, iface, FALSE);
 }
 
-GNCModule 
-gnc_module_load_optional(char * module_name, gint iface) 
+GNCModule
+gnc_module_load_optional(char * module_name, gint iface)
 {
-  return gnc_module_load_common(module_name, iface, TRUE);
+    return gnc_module_load_common(module_name, iface, TRUE);
 }
 
 /*************************************************************
@@ -577,40 +583,40 @@
 int
 gnc_module_unload(GNCModule module)
 {
-  GNCLoadedModule * info;
+    GNCLoadedModule * info;
 
-  if(!loaded_modules)
-  {
-    gnc_module_system_init();
-  }
-
-  if ((info = g_hash_table_lookup(loaded_modules, module)) != NULL)
-  {
-    gpointer unload_thunk;
-    int unload_val = TRUE;
-
-    info->load_count--;
-    if (gnc_module_get_symbol(info->gmodule, "gnc_module_end", &unload_thunk))
+    if (!loaded_modules)
     {
-      int (* thunk)(int) = unload_thunk;
-      unload_val = thunk(info->load_count);
+        gnc_module_system_init();
     }
 
-    /* actually unload the module if necessary */
-    if (info->load_count == 0)
+    if ((info = g_hash_table_lookup(loaded_modules, module)) != NULL)
     {
-      /* now close the module and free the struct */
-      /* g_debug("(unload) closing %s\n", info->filename); */
-      /* g_module_close(info->gmodule); */
-      g_hash_table_remove(loaded_modules, module);
-      g_free(info);
+        gpointer unload_thunk;
+        int unload_val = TRUE;
+
+        info->load_count--;
+        if (gnc_module_get_symbol(info->gmodule, "gnc_module_end", &unload_thunk))
+        {
+            int (* thunk)(int) = unload_thunk;
+            unload_val = thunk(info->load_count);
+        }
+
+        /* actually unload the module if necessary */
+        if (info->load_count == 0)
+        {
+            /* now close the module and free the struct */
+            /* g_debug("(unload) closing %s\n", info->filename); */
+            /* g_module_close(info->gmodule); */
+            g_hash_table_remove(loaded_modules, module);
+            g_free(info);
+        }
+        return unload_val;
     }
-    return unload_val;
-  }
-  else
-  {
-    g_warning ("Failed to unload module %p (it is not loaded)\n", module);
-    return 0;
-  }
+    else
+    {
+        g_warning ("Failed to unload module %p (it is not loaded)\n", module);
+        return 0;
+    }
 }
 

Modified: gnucash/trunk/src/gnc-module/gnc-module.h
===================================================================
--- gnucash/trunk/src/gnc-module/gnc-module.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/gnc-module.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -12,20 +12,21 @@
 
 #define DEFAULT_MODULE_PATH "/usr/local/gnucash/lib/modules"
 
-/* the basics: initialize the module system, refresh its module 
+/* the basics: initialize the module system, refresh its module
  * database, and get a list of all known modules */
 void            gnc_module_system_init(void);
 void            gnc_module_system_refresh(void);
 GList         * gnc_module_system_modinfo(void);
 
 /* load and unload a module.  gnc_module_system_init() must be called
- * before loading and unloading. 
+ * before loading and unloading.
  *
  * Note/FIXME: There seems to be no real reason for why the argument
  * module_name is not a const gchar?! It certainly should be const
  * (because of passing string literals), and from a quick glance it is
  * also only used in a const way. */
-/*@ dependent @*/ GNCModule       gnc_module_load(gchar * module_name, gint iface);
+/*@ dependent @*/
+GNCModule       gnc_module_load(gchar * module_name, gint iface);
 GNCModule       gnc_module_load_optional(gchar * module_name, gint iface);
 int             gnc_module_unload(GNCModule mod);
 

Modified: gnucash/trunk/src/gnc-module/test/misc-mods/agedver.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/misc-mods/agedver.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/misc-mods/agedver.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -15,16 +15,19 @@
 int libagedver_gnc_module_revision = 0;
 
 char *
-libagedver_gnc_module_path(void) {
-  return g_strdup("gnucash/agedver");
+libagedver_gnc_module_path(void)
+{
+    return g_strdup("gnucash/agedver");
 }
 
 char *
-libagedver_gnc_module_description(void) {
-  return g_strdup("this is a frequently extended module");
+libagedver_gnc_module_description(void)
+{
+    return g_strdup("this is a frequently extended module");
 }
 
 int
-libagedver_gnc_module_init(int refcount) {
-  return TRUE;
+libagedver_gnc_module_init(int refcount)
+{
+    return TRUE;
 }

Modified: gnucash/trunk/src/gnc-module/test/misc-mods/futuremodsys.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/misc-mods/futuremodsys.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/misc-mods/futuremodsys.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -17,16 +17,19 @@
 
 
 char *
-libfuturemodsys_gnc_module_path(void) {
-  return g_strdup("gnucash/futuremodsys");
+libfuturemodsys_gnc_module_path(void)
+{
+    return g_strdup("gnucash/futuremodsys");
 }
 
 char *
-libfuturemodsys_gnc_module_description(void) {
-  return g_strdup("this is a broken future module");
+libfuturemodsys_gnc_module_description(void)
+{
+    return g_strdup("this is a broken future module");
 }
 
 int
-libfuturemodsys_gnc_module_init(int refcount) {
-  return TRUE;
+libfuturemodsys_gnc_module_init(int refcount)
+{
+    return TRUE;
 }

Modified: gnucash/trunk/src/gnc-module/test/misc-mods/incompatdep.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/misc-mods/incompatdep.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/misc-mods/incompatdep.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -17,23 +17,26 @@
 
 
 char *
-libincompatdep_gnc_module_path(void) {
-  return g_strdup("gnucash/incompatdep");
+libincompatdep_gnc_module_path(void)
+{
+    return g_strdup("gnucash/incompatdep");
 }
 
 char *
-libincompatdep_gnc_module_description(void) {
-  return g_strdup("this is a broken module");
+libincompatdep_gnc_module_description(void)
+{
+    return g_strdup("this is a broken module");
 }
 
 int
-libincompatdep_gnc_module_init(int refcount) {
-  if (gnc_module_load("gnucash/foo", 25))
-  {
-    return TRUE;
-  }
-  else
-  {
-    return FALSE;
-  }
+libincompatdep_gnc_module_init(int refcount)
+{
+    if (gnc_module_load("gnucash/foo", 25))
+    {
+        return TRUE;
+    }
+    else
+    {
+        return FALSE;
+    }
 }

Modified: gnucash/trunk/src/gnc-module/test/mod-bar/bar.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/mod-bar/bar.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/mod-bar/bar.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -7,6 +7,7 @@
 #include "bar.h"
 
 int
-bar_hello(void) {
-  return 1;
+bar_hello(void)
+{
+    return 1;
 }

Modified: gnucash/trunk/src/gnc-module/test/mod-bar/gnc-mod-bar.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/mod-bar/gnc-mod-bar.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/mod-bar/gnc-mod-bar.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -18,23 +18,26 @@
 int libgncmodbar_gnc_module_revision = 0;
 
 char *
-libgncmodbar_gnc_module_path(void) {
-  return g_strdup("gnucash/bar");
+libgncmodbar_gnc_module_path(void)
+{
+    return g_strdup("gnucash/bar");
 }
 
 char *
-libgncmodbar_gnc_module_description(void) {
-  return g_strdup("this is a bar module");
+libgncmodbar_gnc_module_description(void)
+{
+    return g_strdup("this is a bar module");
 }
 
 int
-libgncmodbar_gnc_module_init(int refcount) {
-  /* publish the wrapped Scheme bindings for libbar */
-  scm_init_sw_bar_module();
-  scm_c_eval_string("(use-modules (sw_bar))");
+libgncmodbar_gnc_module_init(int refcount)
+{
+    /* publish the wrapped Scheme bindings for libbar */
+    scm_init_sw_bar_module();
+    scm_c_eval_string("(use-modules (sw_bar))");
 
-  /* use the Scheme "bar" module */
-  scm_c_eval_string("(use-modules (gnucash bar))");
+    /* use the Scheme "bar" module */
+    scm_c_eval_string("(use-modules (gnucash bar))");
 
-  return TRUE;
+    return TRUE;
 }

Modified: gnucash/trunk/src/gnc-module/test/mod-baz/baz.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/mod-baz/baz.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/mod-baz/baz.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -6,8 +6,9 @@
 #include "foo.h"
 
 int
-baz_hello(void) {
-  foo_hello();  
-  return 1;
+baz_hello(void)
+{
+    foo_hello();
+    return 1;
 }
 

Modified: gnucash/trunk/src/gnc-module/test/mod-baz/gnc-mod-baz.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/mod-baz/gnc-mod-baz.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/mod-baz/gnc-mod-baz.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -19,29 +19,34 @@
 int libgncmodbaz_gnc_module_revision = 0;
 
 char *
-libgncmodbaz_gnc_module_path(void) {
-  return g_strdup("gnucash/baz");
+libgncmodbaz_gnc_module_path(void)
+{
+    return g_strdup("gnucash/baz");
 }
 
 char *
-libgncmodbaz_gnc_module_description(void) {
-  return g_strdup("this is the baz module");
+libgncmodbaz_gnc_module_description(void)
+{
+    return g_strdup("this is the baz module");
 }
 
 int
-libgncmodbaz_gnc_module_init(int refcount) {
-  /* load libfoo */
-  if(gnc_module_load("gnucash/foo", 0)) {
-    /* publish the wrapped Scheme bindings for libbaz */
-    scm_init_sw_baz_module();
-    scm_c_eval_string("(use-modules (sw_baz))");
+libgncmodbaz_gnc_module_init(int refcount)
+{
+    /* load libfoo */
+    if (gnc_module_load("gnucash/foo", 0))
+    {
+        /* publish the wrapped Scheme bindings for libbaz */
+        scm_init_sw_baz_module();
+        scm_c_eval_string("(use-modules (sw_baz))");
 
-    /* use the Scheme "baz" module */
-    scm_c_eval_string("(use-modules (gnucash baz))");
+        /* use the Scheme "baz" module */
+        scm_c_eval_string("(use-modules (gnucash baz))");
 
-    return TRUE;
-  }
-  else {
-    return FALSE;
-  }
+        return TRUE;
+    }
+    else
+    {
+        return FALSE;
+    }
 }

Modified: gnucash/trunk/src/gnc-module/test/mod-foo/foo.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/mod-foo/foo.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/mod-foo/foo.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -7,6 +7,7 @@
 #include "foo.h"
 
 int
-foo_hello(void) {
-  return 10;
+foo_hello(void)
+{
+    return 10;
 }

Modified: gnucash/trunk/src/gnc-module/test/mod-foo/gnc-mod-foo.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/mod-foo/gnc-mod-foo.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/mod-foo/gnc-mod-foo.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -18,23 +18,26 @@
 int libgncmodfoo_gnc_module_revision = 0;
 
 char *
-libgncmodfoo_gnc_module_path(void) {
-  return g_strdup("gnucash/foo");
+libgncmodfoo_gnc_module_path(void)
+{
+    return g_strdup("gnucash/foo");
 }
 
 char *
-libgncmodfoo_gnc_module_description(void) {
-  return g_strdup("this is a foo module");
+libgncmodfoo_gnc_module_description(void)
+{
+    return g_strdup("this is a foo module");
 }
 
 int
-libgncmodfoo_gnc_module_init(int refcount) {
-  /* publish the wrapped Scheme bindings for libfoo */
-  scm_init_sw_foo_module();
-  scm_c_eval_string("(use-modules (sw_foo))");
+libgncmodfoo_gnc_module_init(int refcount)
+{
+    /* publish the wrapped Scheme bindings for libfoo */
+    scm_init_sw_foo_module();
+    scm_c_eval_string("(use-modules (sw_foo))");
 
-  /* use the Scheme "foo" module */
-  scm_c_eval_string("(use-modules (gnucash foo))");
+    /* use the Scheme "foo" module */
+    scm_c_eval_string("(use-modules (gnucash foo))");
 
-  return TRUE;
+    return TRUE;
 }

Modified: gnucash/trunk/src/gnc-module/test/test-agedver.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/test-agedver.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/test-agedver.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -7,27 +7,29 @@
 static void
 guile_main(void *closure, int argc, char ** argv)
 {
-  GNCModule foo;
+    GNCModule foo;
 
-  printf("  test-agedver.c:  asking for an old but supported interface ...");
+    printf("  test-agedver.c:  asking for an old but supported interface ...");
 
-  gnc_module_system_init();
+    gnc_module_system_init();
 
-  foo = gnc_module_load("gnucash/agedver", 5);
-  
-  if(foo) {
-    printf("  ok\n");
-    exit(0);
-  }
-  else {
-    printf(" failed\n");
-    exit(-1);
-  }
+    foo = gnc_module_load("gnucash/agedver", 5);
+
+    if (foo)
+    {
+        printf("  ok\n");
+        exit(0);
+    }
+    else
+    {
+        printf(" failed\n");
+        exit(-1);
+    }
 }
 
 int
 main(int argc, char ** argv)
 {
-  scm_boot_guile(argc, argv, guile_main, NULL);
-  return 0;
+    scm_boot_guile(argc, argv, guile_main, NULL);
+    return 0;
 }

Modified: gnucash/trunk/src/gnc-module/test/test-dynload.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/test-dynload.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/test-dynload.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -13,39 +13,43 @@
 static void
 guile_main(void *closure, int argc, char ** argv)
 {
-  GModule *gmodule;
+    GModule *gmodule;
 
-  printf("  test-dynload.c: testing dynamic linking of libgnc-module ...");
-  gmodule = g_module_open("libgnc-module", 0);
+    printf("  test-dynload.c: testing dynamic linking of libgnc-module ...");
+    gmodule = g_module_open("libgnc-module", 0);
 
-  /* Maybe MacOS? */
-  if (!gmodule)
-    gmodule = g_module_open("libgnc-module.dylib", 0);
+    /* Maybe MacOS? */
+    if (!gmodule)
+        gmodule = g_module_open("libgnc-module.dylib", 0);
 
-  if (gmodule) {
-    gpointer ptr;
-    if (g_module_symbol(gmodule, "gnc_module_system_init", &ptr)) {
-      void (* fn)(void) = ptr;
-      fn();
-      printf(" OK\n");
-      exit(0);
+    if (gmodule)
+    {
+        gpointer ptr;
+        if (g_module_symbol(gmodule, "gnc_module_system_init", &ptr))
+        {
+            void (* fn)(void) = ptr;
+            fn();
+            printf(" OK\n");
+            exit(0);
+        }
+        else
+        {
+            printf(" failed to find gnc_module_system_init\n");
+            exit(-1);
+        }
     }
-    else {
-      printf(" failed to find gnc_module_system_init\n");
-      exit(-1);
+    else
+    {
+        printf(" failed to open library.\n");
+        printf("%s\n", g_module_error());
+        exit(-1);
     }
-  }
-  else {
-    printf(" failed to open library.\n");
-    printf("%s\n", g_module_error());
-    exit(-1);
-  }
 }
 
 int
 main(int argc, char ** argv)
 {
-  scm_boot_guile(argc, argv, guile_main, NULL);
-  return 0;
+    scm_boot_guile(argc, argv, guile_main, NULL);
+    return 0;
 }
 

Modified: gnucash/trunk/src/gnc-module/test/test-incompatdep.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/test-incompatdep.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/test-incompatdep.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -7,27 +7,29 @@
 static void
 guile_main(void *closure, int argc, char ** argv)
 {
-  GNCModule foo;
+    GNCModule foo;
 
-  printf("  test-incompatdep.c:  loading a module with bad deps ...\n");
+    printf("  test-incompatdep.c:  loading a module with bad deps ...\n");
 
-  gnc_module_system_init();
+    gnc_module_system_init();
 
-  foo = gnc_module_load("gnucash/incompatdep", 0);
-  
-  if(!foo) {
-    printf("  ok\n");
-    exit(0);
-  }
-  else {
-    printf("  oops! loaded incompatible module\n");
-    exit(-1);
-  }
+    foo = gnc_module_load("gnucash/incompatdep", 0);
+
+    if (!foo)
+    {
+        printf("  ok\n");
+        exit(0);
+    }
+    else
+    {
+        printf("  oops! loaded incompatible module\n");
+        exit(-1);
+    }
 }
 
 int
 main(int argc, char ** argv)
 {
-  scm_boot_guile(argc, argv, guile_main, NULL);
-  return 0;
+    scm_boot_guile(argc, argv, guile_main, NULL);
+    return 0;
 }

Modified: gnucash/trunk/src/gnc-module/test/test-load-c.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/test-load-c.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/test-load-c.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -8,31 +8,33 @@
 static void
 guile_main(void *closure, int argc, char ** argv)
 {
-  GNCModule foo;
+    GNCModule foo;
 
-  printf("  test-load-c.c: testing module load/unload from C ... ");
+    printf("  test-load-c.c: testing module load/unload from C ... ");
 
-  gnc_module_system_init();
+    gnc_module_system_init();
 
-  foo = gnc_module_load("gnucash/foo", 0);
-  
-  if(!foo) {
-    printf("  Failed to load foo\n");
-    exit(-1);
-  }
+    foo = gnc_module_load("gnucash/foo", 0);
 
-  if(!gnc_module_unload(foo)) {
-    printf("  Failed to unload foo\n");
-    exit(-1);
-  }
-  printf(" successful.\n");
+    if (!foo)
+    {
+        printf("  Failed to load foo\n");
+        exit(-1);
+    }
 
-  exit(0);
+    if (!gnc_module_unload(foo))
+    {
+        printf("  Failed to unload foo\n");
+        exit(-1);
+    }
+    printf(" successful.\n");
+
+    exit(0);
 }
 
 int
 main(int argc, char ** argv)
 {
-  scm_boot_guile(argc, argv, guile_main, NULL);
-  return 0;
+    scm_boot_guile(argc, argv, guile_main, NULL);
+    return 0;
 }

Modified: gnucash/trunk/src/gnc-module/test/test-modsysver.c
===================================================================
--- gnucash/trunk/src/gnc-module/test/test-modsysver.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/gnc-module/test/test-modsysver.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -7,27 +7,29 @@
 static void
 guile_main(void *closure, int argc, char ** argv)
 {
-  GNCModule foo;
+    GNCModule foo;
 
-  printf("  test-modsysver.c: checking for a module we shouldn't find ...\n");
+    printf("  test-modsysver.c: checking for a module we shouldn't find ...\n");
 
-  gnc_module_system_init();
+    gnc_module_system_init();
 
-  foo = gnc_module_load("gnucash/futuremodsys", 0);
-  
-  if(!foo) {
-    printf("  ok\n");
-    exit(0);
-  }
-  else {
-    printf("  oops! loaded incompatible module\n");
-    exit(-1);
-  }
+    foo = gnc_module_load("gnucash/futuremodsys", 0);
+
+    if (!foo)
+    {
+        printf("  ok\n");
+        exit(0);
+    }
+    else
+    {
+        printf("  oops! loaded incompatible module\n");
+        exit(-1);
+    }
 }
 
 int
 main(int argc, char ** argv)
 {
-  scm_boot_guile(argc, argv, guile_main, NULL);
-  return 0;
+    scm_boot_guile(argc, argv, guile_main, NULL);
+    return 0;
 }

Modified: gnucash/trunk/src/libqof/backend/file/qof-backend-qsf.h
===================================================================
--- gnucash/trunk/src/libqof/backend/file/qof-backend-qsf.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/libqof/backend/file/qof-backend-qsf.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -20,7 +20,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
- 
+
 /** @addtogroup Backend
     @{ */
 /** @addtogroup QSF QOF Serialisation Format
@@ -28,7 +28,7 @@
 This is the public interface of the qof-backend-qsf library.
 
 QSF - QOF Serialization Format is an XML serialization format
-i.e. it lays out a QOF object in a series of XML tags. The format will  
+i.e. it lays out a QOF object in a series of XML tags. The format will
 consist of two component formats:
 
 qof-qsf for the QSF object data and
@@ -40,16 +40,16 @@
 can be converted using XSL or other standard tools. For more information on maps,
 see http://code.neil.williamsleesmill.me.uk/map.html
 
-QSF object files will contain user data and are to be exported from QOF applications 
-under user control or they can be hand-edited. QSF maps contain application data and 
-can be created by application developers from application source code. Tools may be 
-created later to generate maps interactively but maps require application support as 
-well as an understanding of QOF objects in the import and output applications and are 
+QSF object files will contain user data and are to be exported from QOF applications
+under user control or they can be hand-edited. QSF maps contain application data and
+can be created by application developers from application source code. Tools may be
+created later to generate maps interactively but maps require application support as
+well as an understanding of QOF objects in the import and output applications and are
 intended to remain within the scope of application developers rather than users.
 
-A QSF file written by one QOF application will need an appropriate QSF map before the 
-data can be accessed by a different application using QOF. Any QSF objects that are 
-not defined in the map will be ignored. QSF files written and accessed by the same 
+A QSF file written by one QOF application will need an appropriate QSF map before the
+data can be accessed by a different application using QOF. Any QSF objects that are
+not defined in the map will be ignored. QSF files written and accessed by the same
 application can use maps if necessary or can simply import the QSF data as a whole.
 
 Unless specifically mentioned otherwise, all defined strings are case-sensitive.
@@ -59,20 +59,20 @@
 http://code.neil.williamsleesmill.me.uk/qsf.html
 
 QSF itself is now being built into the QOF library for use with pilot-link to allow
-Palm objects to be described in QOF, written to XML as QSF and imported directly into 
-GnuCash and other QOF-compliant applications. As a generic format, it does not depend 
+Palm objects to be described in QOF, written to XML as QSF and imported directly into
+GnuCash and other QOF-compliant applications. As a generic format, it does not depend
 on any pre-defined objects.  Instead, QSF is a simple container for all QOF objects.
 
-QSF grew from the qof_book_merge code base and uses the qof_book_merge code that is now 
-part of QOF. Any QofBook generated by QSF still needs to be merged into the existing 
+QSF grew from the qof_book_merge code base and uses the qof_book_merge code that is now
+part of QOF. Any QofBook generated by QSF still needs to be merged into the existing
 application data using qof_book_merge. See ::BookMerge.
 
-QSF can be used as an export or offline storage format for QOF applications (although 
-long term storage may be best performed using separate (non-XML) methods, depending 
+QSF can be used as an export or offline storage format for QOF applications (although
+long term storage may be best performed using separate (non-XML) methods, depending
 on the application).
 
-QSF is designed to cope with partial QofBooks at the QofObject level. There is no 
-requirement for specific objects to always be defined, as long as each QOF object 
+QSF is designed to cope with partial QofBooks at the QofObject level. There is no
+requirement for specific objects to always be defined, as long as each QOF object
 specified is fully defined, no orphan or missing parameters are allowed. Part of the
 handling for partial books requires a storage mechanism for references to entities
 that are not within reach of the current book. This requires a little extra coding
@@ -80,23 +80,23 @@
 written out, the reference can be included. When the file is imported back in, a
 little extra code then rebuilds those references during the merge.
 
-Copying entites from an existing QofBook using the qof_instance_copy routines will 
+Copying entites from an existing QofBook using the qof_instance_copy routines will
 automatically create the reference table. If your QOF objects use references to other
 entities, books that are created manually also need to create a reference table.
 
-Work is continuing on supporting QSF in GnuCash and QOF. QSF is a very open format - 
-the majority of the work will be in standardising object types and creating maps that 
-convert between objects. Applications that read QSF should ignore any objects that do 
-not match the available maps and warn the user about missing data. 
+Work is continuing on supporting QSF in GnuCash and QOF. QSF is a very open format -
+the majority of the work will be in standardising object types and creating maps that
+convert between objects. Applications that read QSF should ignore any objects that do
+not match the available maps and warn the user about missing data.
 
-Anyone is free to create their own QSF objects, subject to the GNU GPL. It is intended 
-that QSF can be used as the flexible, open and free format for QOF data - providing 
-all that is lacking from a typical CSV export with all the validation benefits of XML 
-and the complex data handling of QOF. The QSF object and map formats remain under the 
+Anyone is free to create their own QSF objects, subject to the GNU GPL. It is intended
+that QSF can be used as the flexible, open and free format for QOF data - providing
+all that is lacking from a typical CSV export with all the validation benefits of XML
+and the complex data handling of QOF. The QSF object and map formats remain under the
 GNU GPL licence and QSF is free software.
 
 \todo
-	- Adding more map support, some parts of the map are still not coded. equals, 
+	- Adding more map support, some parts of the map are still not coded. equals,
 		variables and the conditional logic may not be up to the task of the
 		datebook repetition calculations.
 
@@ -107,7 +107,7 @@
 		qsf-xml.c
 	- QSF Map : Validation, processing and conversion routines.
 		qsf-xml-map.c
-		
+
 To work with QSF, your QOF objects must have:
 	- a create: function in the QofObject definition
 	- a foreach: function in the QofObject definition
@@ -115,13 +115,13 @@
 		qof_class_register and containing all necessary parameters
 		to reconstruct this object without any further information.
 	- Logical distinction between those parameters that should be
-		set (have a QofAccessFunc and QofSetterFunc) and those that 
+		set (have a QofAccessFunc and QofSetterFunc) and those that
 		should only be calculated (only a QofAccessFunc).
 
 If you begin your QSF session with ::QOF_STDOUT as the book_id,
 QSF will write to STDOUT - usually a terminal. This is used by QOF
 applications to provide data streaming. If you don't want terminal
-output, take care to check the path given to 
+output, take care to check the path given to
 ::qof_session_begin - don't try to change it later!
 
 The XML is validated against the QSF object schema before being
@@ -142,7 +142,7 @@
 #include "qoflog.h"
 #include "qofbackend.h"
 
-/** \brief Describe this backend to the application. 
+/** \brief Describe this backend to the application.
 
 Sets QSF Backend Version 0.2, access method = file:
 
@@ -174,12 +174,12 @@
 */
 #define QSF_COMPRESS    "compression_level"
 
-/** \brief selected QSF maps 
+/** \brief selected QSF maps
 
 \b Type: GList* (KVP_TYPE_GLIST) of const char* (QOF_TYPE_STRING) values.
 
 Defaults to the pre-installed QSF map(s) but may be overridden
-by the application to pass full path(s) of user selected 
+by the application to pass full path(s) of user selected
 QSF map file(s).
 
 If you override the list, it is advisable to only specify the single

Modified: gnucash/trunk/src/libqof/backend/file/qsf-backend.c
===================================================================
--- gnucash/trunk/src/libqof/backend/file/qsf-backend.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/libqof/backend/file/qsf-backend.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -49,169 +49,196 @@
 
 struct QSFBackend_s
 {
-	QofBackend be;
-	qsf_param *params;
-	gchar *fullpath;
+    QofBackend be;
+    qsf_param *params;
+    gchar *fullpath;
 };
 
 typedef struct QSFBackend_s QSFBackend;
 
 static void option_cb (QofBackendOption *option, gpointer data)
 {
-	qsf_param *params;
+    qsf_param *params;
 
-	params = (qsf_param*)data;
-	g_return_if_fail(params);
-	if(0 == safe_strcmp(QSF_COMPRESS, option->option_name)) {
-		params->use_gz_level = (*(gint64*)option->value);
-	        DEBUG (" gz=%" G_GINT64_FORMAT,params->use_gz_level);
-	}
-	if (0 == safe_strcmp(QSF_MAP_FILES, option->option_name)) {
-		params->map_files = g_list_copy((GList*)option->value);
-	}
-	if (0 == safe_strcmp(QSF_ENCODING, option->option_name)) {
-		params->encoding = g_strdup(option->value);
-		DEBUG (" encoding=%s", params->encoding);
-	}
+    params = (qsf_param*)data;
+    g_return_if_fail(params);
+    if (0 == safe_strcmp(QSF_COMPRESS, option->option_name))
+    {
+        params->use_gz_level = (*(gint64*)option->value);
+        DEBUG (" gz=%" G_GINT64_FORMAT, params->use_gz_level);
+    }
+    if (0 == safe_strcmp(QSF_MAP_FILES, option->option_name))
+    {
+        params->map_files = g_list_copy((GList*)option->value);
+    }
+    if (0 == safe_strcmp(QSF_ENCODING, option->option_name))
+    {
+        params->encoding = g_strdup(option->value);
+        DEBUG (" encoding=%s", params->encoding);
+    }
 }
 
 static void
 qsf_load_config(QofBackend *be, KvpFrame *config)
 {
-	QSFBackend *qsf_be;
-	qsf_param  *params;
+    QSFBackend *qsf_be;
+    qsf_param  *params;
 
-	ENTER (" ");
-	qsf_be = (QSFBackend*)be;
-	g_return_if_fail(qsf_be->params);
-	params = qsf_be->params;
-	qof_backend_option_foreach(config, option_cb, params);
-	LEAVE (" ");
+    ENTER (" ");
+    qsf_be = (QSFBackend*)be;
+    g_return_if_fail(qsf_be->params);
+    params = qsf_be->params;
+    qof_backend_option_foreach(config, option_cb, params);
+    LEAVE (" ");
 }
 
 static KvpFrame*
 qsf_get_config(QofBackend *be)
 {
-	QofBackendOption *option;
-	QSFBackend *qsf_be;
-	qsf_param *params;
+    QofBackendOption *option;
+    QSFBackend *qsf_be;
+    qsf_param *params;
 
-	if(!be) { return NULL; }
-	ENTER (" ");
-	qsf_be = (QSFBackend*)be;
-	g_return_val_if_fail(qsf_be->params, NULL);
-	params = qsf_be->params;
-	qof_backend_prepare_frame(be);
-	option = g_new0(QofBackendOption, 1);
-	option->option_name = QSF_COMPRESS;
-	option->description = _("Level of compression to use: 0 for none, 9 for highest.");
-	option->tooltip = _("QOF can compress QSF XML files using gzip. "
-		"Note that compression is not used when outputting to STDOUT.");
-	option->type = KVP_TYPE_GINT64;
-	option->value = (gpointer)&params->use_gz_level;
-	qof_backend_prepare_option(be, option);
-	g_free(option);
-	option = g_new0(QofBackendOption, 1);
-	option->option_name = QSF_MAP_FILES;
-	option->description = _("List of QSF map files to use for this session.");
-	option->tooltip = _("QOF can convert objects within QSF XML files "
-		"using a map of the changes required.");
-	option->type = KVP_TYPE_GLIST;
-	option->value = (gpointer)params->map_files;
-	qof_backend_prepare_option(be, option);
-	g_free(option);
-	option = g_new0(QofBackendOption, 1);
-	option->option_name = QSF_ENCODING;
-	option->description = _("String encoding to use when writing the XML file.");
-	option->tooltip = _("QSF defaults to UTF-8. Other encodings are supported by "
-			"passing the string encoding in this option.");
-	option->type = KVP_TYPE_STRING;
-	option->value = (gpointer)params->encoding;
-	qof_backend_prepare_option(be, option);
-	g_free(option);
-	LEAVE (" ");
-	return qof_backend_complete_frame(be);
+    if (!be)
+    {
+        return NULL;
+    }
+    ENTER (" ");
+    qsf_be = (QSFBackend*)be;
+    g_return_val_if_fail(qsf_be->params, NULL);
+    params = qsf_be->params;
+    qof_backend_prepare_frame(be);
+    option = g_new0(QofBackendOption, 1);
+    option->option_name = QSF_COMPRESS;
+    option->description = _("Level of compression to use: 0 for none, 9 for highest.");
+    option->tooltip = _("QOF can compress QSF XML files using gzip. "
+                        "Note that compression is not used when outputting to STDOUT.");
+    option->type = KVP_TYPE_GINT64;
+    option->value = (gpointer) & params->use_gz_level;
+    qof_backend_prepare_option(be, option);
+    g_free(option);
+    option = g_new0(QofBackendOption, 1);
+    option->option_name = QSF_MAP_FILES;
+    option->description = _("List of QSF map files to use for this session.");
+    option->tooltip = _("QOF can convert objects within QSF XML files "
+                        "using a map of the changes required.");
+    option->type = KVP_TYPE_GLIST;
+    option->value = (gpointer)params->map_files;
+    qof_backend_prepare_option(be, option);
+    g_free(option);
+    option = g_new0(QofBackendOption, 1);
+    option->option_name = QSF_ENCODING;
+    option->description = _("String encoding to use when writing the XML file.");
+    option->tooltip = _("QSF defaults to UTF-8. Other encodings are supported by "
+                        "passing the string encoding in this option.");
+    option->type = KVP_TYPE_STRING;
+    option->value = (gpointer)params->encoding;
+    qof_backend_prepare_option(be, option);
+    g_free(option);
+    LEAVE (" ");
+    return qof_backend_complete_frame(be);
 }
 
 GList**
 qsf_map_prepare_list(GList **maps)
 {
-	*maps = g_list_prepend(*maps, "pilot-qsf-GnuCashInvoice.xml");
-	*maps = g_list_prepend(*maps, "pilot-qsf-gncCustomer.xml");
-	return maps;
+    *maps = g_list_prepend(*maps, "pilot-qsf-GnuCashInvoice.xml");
+    *maps = g_list_prepend(*maps, "pilot-qsf-gncCustomer.xml");
+    return maps;
 }
 
 static void
 qsf_param_init(qsf_param *params)
 {
-	Timespec *qsf_ts;
-	gchar qsf_time_string[QSF_DATE_LENGTH];
-	gchar qsf_enquiry_date[QSF_DATE_LENGTH];
-	gchar qsf_time_match[QSF_DATE_LENGTH];
-	gchar qsf_time_now[QSF_DATE_LENGTH];
-	time_t qsf_time_now_t;
-	gchar *qsf_time_precision;
+    Timespec *qsf_ts;
+    gchar qsf_time_string[QSF_DATE_LENGTH];
+    gchar qsf_enquiry_date[QSF_DATE_LENGTH];
+    gchar qsf_time_match[QSF_DATE_LENGTH];
+    gchar qsf_time_now[QSF_DATE_LENGTH];
+    time_t qsf_time_now_t;
+    gchar *qsf_time_precision;
 
-	g_return_if_fail(params != NULL);
-	params->count = 0;
-	params->use_gz_level = 0;
-	params->supported_types = NULL;
-	params->file_type = QSF_UNDEF;
-	params->qsf_ns = NULL;
-	params->output_doc = NULL;
-	params->output_node = NULL;
-	params->lister = NULL;
-	params->full_kvp_path = NULL;
-	params->map_ns = NULL;
-	params->map_files = NULL;
-	params->map_path = NULL;
-	params->encoding = "UTF-8";
-	params->qsf_object_list = NULL;
-	params->qsf_parameter_hash = g_hash_table_new(g_str_hash, g_str_equal);
-	params->qsf_default_hash = g_hash_table_new(g_str_hash, g_str_equal);
-	params->qsf_define_hash = g_hash_table_new(g_str_hash, g_str_equal);
-	params->qsf_calculate_hash = g_hash_table_new(g_str_hash, g_str_equal);
-	params->referenceList = NULL;
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_STRING);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_GUID);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_BOOLEAN);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_NUMERIC);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_DATE);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_INT32);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_INT64);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_DOUBLE);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_CHAR);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_KVP);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_COLLECT);
-	params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_CHOICE);
-	qsf_time_precision = "%j";
-	qsf_time_now_t = time(NULL);
-	qsf_ts = g_new(Timespec, 1);
-	timespecFromTime_t(qsf_ts, qsf_time_now_t);
-	qof_strftime(qsf_enquiry_date, QSF_DATE_LENGTH, QSF_XSD_TIME, gmtime(&qsf_time_now_t));
-	qof_strftime(qsf_time_match, QSF_DATE_LENGTH, qsf_time_precision, gmtime(&qsf_time_now_t));
-	qof_strftime(qsf_time_string, QSF_DATE_LENGTH, "%F", gmtime(&qsf_time_now_t));
-	qof_strftime(qsf_time_now, QSF_DATE_LENGTH, QSF_XSD_TIME, gmtime(&qsf_time_now_t));
-	g_hash_table_insert(params->qsf_default_hash, "qsf_enquiry_date", qsf_enquiry_date);
-	g_hash_table_insert(params->qsf_default_hash, "qsf_time_now", &qsf_time_now_t);
-	g_hash_table_insert(params->qsf_default_hash, "qsf_time_string", qsf_time_string);
-	/* default map files */
-	params->map_files = *qsf_map_prepare_list(&params->map_files);
+    g_return_if_fail(params != NULL);
+    params->count = 0;
+    params->use_gz_level = 0;
+    params->supported_types = NULL;
+    params->file_type = QSF_UNDEF;
+    params->qsf_ns = NULL;
+    params->output_doc = NULL;
+    params->output_node = NULL;
+    params->lister = NULL;
+    params->full_kvp_path = NULL;
+    params->map_ns = NULL;
+    params->map_files = NULL;
+    params->map_path = NULL;
+    params->encoding = "UTF-8";
+    params->qsf_object_list = NULL;
+    params->qsf_parameter_hash = g_hash_table_new(g_str_hash, g_str_equal);
+    params->qsf_default_hash = g_hash_table_new(g_str_hash, g_str_equal);
+    params->qsf_define_hash = g_hash_table_new(g_str_hash, g_str_equal);
+    params->qsf_calculate_hash = g_hash_table_new(g_str_hash, g_str_equal);
+    params->referenceList = NULL;
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_STRING);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_GUID);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_BOOLEAN);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_NUMERIC);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_DATE);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_INT32);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_INT64);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_DOUBLE);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_CHAR);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_KVP);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_COLLECT);
+    params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_CHOICE);
+    qsf_time_precision = "%j";
+    qsf_time_now_t = time(NULL);
+    qsf_ts = g_new(Timespec, 1);
+    timespecFromTime_t(qsf_ts, qsf_time_now_t);
+    qof_strftime(qsf_enquiry_date, QSF_DATE_LENGTH, QSF_XSD_TIME, gmtime(&qsf_time_now_t));
+    qof_strftime(qsf_time_match, QSF_DATE_LENGTH, qsf_time_precision, gmtime(&qsf_time_now_t));
+    qof_strftime(qsf_time_string, QSF_DATE_LENGTH, "%F", gmtime(&qsf_time_now_t));
+    qof_strftime(qsf_time_now, QSF_DATE_LENGTH, QSF_XSD_TIME, gmtime(&qsf_time_now_t));
+    g_hash_table_insert(params->qsf_default_hash, "qsf_enquiry_date", qsf_enquiry_date);
+    g_hash_table_insert(params->qsf_default_hash, "qsf_time_now", &qsf_time_now_t);
+    g_hash_table_insert(params->qsf_default_hash, "qsf_time_string", qsf_time_string);
+    /* default map files */
+    params->map_files = *qsf_map_prepare_list(&params->map_files);
 }
 
-static gboolean 
+static gboolean
 qsf_determine_file_type(const gchar *path)
 {
-	struct stat sbuf;
+    struct stat sbuf;
 
-	if (!path) { return TRUE; }
-	if (0 == safe_strcmp(path, QOF_STDOUT)) { return TRUE; }
-	if (g_stat(path, &sbuf) <0)  { return FALSE; }
-	if (sbuf.st_size == 0)       { return TRUE; }
-	if(is_our_qsf_object(path))  { return TRUE; }
-	else if(is_qsf_object(path)) { return TRUE; }
-	else if(is_qsf_map(path))    { return TRUE; }
-	return FALSE;
+    if (!path)
+    {
+        return TRUE;
+    }
+    if (0 == safe_strcmp(path, QOF_STDOUT))
+    {
+        return TRUE;
+    }
+    if (g_stat(path, &sbuf) < 0)
+    {
+        return FALSE;
+    }
+    if (sbuf.st_size == 0)
+    {
+        return TRUE;
+    }
+    if (is_our_qsf_object(path))
+    {
+        return TRUE;
+    }
+    else if (is_qsf_object(path))
+    {
+        return TRUE;
+    }
+    else if (is_qsf_map(path))
+    {
+        return TRUE;
+    }
+    return FALSE;
 }
 
 /* GnuCash does LOTS of filesystem work, QSF is going to leave most of it to libxml2. :-)
@@ -219,116 +246,134 @@
 */
 static void
 qsf_session_begin(QofBackend *be, QofSession *session, const gchar *book_path,
-                   gboolean ignore_lock, gboolean create_if_nonexistent)
+                  gboolean ignore_lock, gboolean create_if_nonexistent)
 {
-	QSFBackend *qsf_be;
-	gchar *p, *path;
+    QSFBackend *qsf_be;
+    gchar *p, *path;
 
-	PINFO (" ignore_lock=%d create_if_nonexistent=%d", ignore_lock, create_if_nonexistent);
-	g_return_if_fail(be != NULL);
-	qsf_be = (QSFBackend*)be;
-	g_return_if_fail(qsf_be->params != NULL);
-	qsf_be->fullpath = NULL;
-	if(book_path == NULL)
-	{
-		/* use stdout */
-		qof_backend_set_error(be, ERR_BACKEND_NO_ERR);
-		return;
-	}
-	if (g_str_has_prefix (book_path, "file:")) {
-		qsf_be->fullpath = g_strdup (book_path + 5);
-	} else if (g_str_has_prefix (book_path, "qsf:")) {
-		qsf_be->fullpath = g_strdup (book_path + 4);
-	} else {
-		qsf_be->fullpath = g_strdup (book_path);
-	}
-	if(create_if_nonexistent)
-	{
+    PINFO (" ignore_lock=%d create_if_nonexistent=%d", ignore_lock, create_if_nonexistent);
+    g_return_if_fail(be != NULL);
+    qsf_be = (QSFBackend*)be;
+    g_return_if_fail(qsf_be->params != NULL);
+    qsf_be->fullpath = NULL;
+    if (book_path == NULL)
+    {
+        /* use stdout */
+        qof_backend_set_error(be, ERR_BACKEND_NO_ERR);
+        return;
+    }
+    if (g_str_has_prefix (book_path, "file:"))
+    {
+        qsf_be->fullpath = g_strdup (book_path + 5);
+    }
+    else if (g_str_has_prefix (book_path, "qsf:"))
+    {
+        qsf_be->fullpath = g_strdup (book_path + 4);
+    }
+    else
+    {
+        qsf_be->fullpath = g_strdup (book_path);
+    }
+    if (create_if_nonexistent)
+    {
         FILE *f;
 
         f = g_fopen(qsf_be->fullpath, "a+");
-        if(f) {fclose(f); }
-		else
-		{
-			qof_backend_set_error(be, ERR_BACKEND_READONLY);
-			return;
-		}
-	}
-	qof_backend_set_error(be, ERR_BACKEND_NO_ERR);
+        if (f)
+        {
+            fclose(f);
+        }
+        else
+        {
+            qof_backend_set_error(be, ERR_BACKEND_READONLY);
+            return;
+        }
+    }
+    qof_backend_set_error(be, ERR_BACKEND_NO_ERR);
 }
 
-static void 
+static void
 qsf_free_params(qsf_param *params)
 {
-	g_hash_table_destroy(params->qsf_calculate_hash);
-	g_hash_table_destroy(params->qsf_default_hash);
-	if(params->referenceList) {
-		g_list_free(params->referenceList);
-	}
-	g_slist_free(params->supported_types);
-	if(params->map_ns) { xmlFreeNs(params->map_ns); }
+    g_hash_table_destroy(params->qsf_calculate_hash);
+    g_hash_table_destroy(params->qsf_default_hash);
+    if (params->referenceList)
+    {
+        g_list_free(params->referenceList);
+    }
+    g_slist_free(params->supported_types);
+    if (params->map_ns)
+    {
+        xmlFreeNs(params->map_ns);
+    }
 }
 
 static void
 qsf_session_end( QofBackend *be)
 {
-	QSFBackend *qsf_be;
+    QSFBackend *qsf_be;
 
-	qsf_be = (QSFBackend*)be;
-	g_return_if_fail(qsf_be != NULL);
-	qsf_free_params(qsf_be->params);
-	g_free(qsf_be->fullpath);
-	qsf_be->fullpath = NULL;
-	xmlCleanupParser();
+    qsf_be = (QSFBackend*)be;
+    g_return_if_fail(qsf_be != NULL);
+    qsf_free_params(qsf_be->params);
+    g_free(qsf_be->fullpath);
+    qsf_be->fullpath = NULL;
+    xmlCleanupParser();
 }
 
 static void
 qsf_destroy_backend (QofBackend *be)
 {
-	qof_backend_destroy(be);
-	g_free(be);
+    qof_backend_destroy(be);
+    g_free(be);
 }
 
 static void
 ent_ref_cb (QofInstance* ent, gpointer user_data)
 {
-	qsf_param *params;
-	QofInstanceReference *ref;
-	void (*reference_setter) (QofInstance*, QofInstance*);
-	QofInstance *reference;
-	QofCollection *coll;
-	QofIdType type;
+    qsf_param *params;
+    QofInstanceReference *ref;
+    void (*reference_setter) (QofInstance*, QofInstance*);
+    QofInstance *reference;
+    QofCollection *coll;
+    QofIdType type;
 
-	params = (qsf_param*)user_data;
-	g_return_if_fail(params);
-	while(params->referenceList)
-	{
-		ref = (QofInstanceReference*)params->referenceList->data;
-		if(qof_object_is_choice(ent->e_type)) { type = ref->choice_type; }
-		else { type = ref->type; }
-		coll = qof_book_get_collection(params->book, type);
-		reference = qof_collection_lookup_entity(coll, ref->ref_guid);
-		reference_setter = (void(*)(QofInstance*, QofInstance*))ref->param->param_setfcn;
-		if(reference_setter != NULL)
-		{
-			qof_begin_edit((QofInstance*)ent);
-			qof_begin_edit((QofInstance*)reference);
-			reference_setter(ent, reference);
-			qof_commit_edit((QofInstance*)ent);
-			qof_commit_edit((QofInstance*)reference);
-		}
-		params->referenceList = g_list_next(params->referenceList);
-	}
+    params = (qsf_param*)user_data;
+    g_return_if_fail(params);
+    while (params->referenceList)
+    {
+        ref = (QofInstanceReference*)params->referenceList->data;
+        if (qof_object_is_choice(ent->e_type))
+        {
+            type = ref->choice_type;
+        }
+        else
+        {
+            type = ref->type;
+        }
+        coll = qof_book_get_collection(params->book, type);
+        reference = qof_collection_lookup_entity(coll, ref->ref_guid);
+        reference_setter = (void(*)(QofInstance*, QofInstance*))ref->param->param_setfcn;
+        if (reference_setter != NULL)
+        {
+            qof_begin_edit((QofInstance*)ent);
+            qof_begin_edit((QofInstance*)reference);
+            reference_setter(ent, reference);
+            qof_commit_edit((QofInstance*)ent);
+            qof_commit_edit((QofInstance*)reference);
+        }
+        params->referenceList = g_list_next(params->referenceList);
+    }
 }
 
 static void
 insert_ref_cb(QofObject *obj, gpointer user_data)
 {
-	qsf_param *params;
+    qsf_param *params;
 
-	params = (qsf_param*)user_data;
-	g_return_if_fail(params);
-	qof_object_foreach(obj->e_type, params->book, ent_ref_cb, params);
+    params = (qsf_param*)user_data;
+    g_return_if_fail(params);
+    qof_object_foreach(obj->e_type, params->book, ent_ref_cb, params);
 }
 
 /*================================================
@@ -338,41 +383,47 @@
 static gboolean
 qsfdoc_to_qofbook(xmlDocPtr doc, qsf_param *params)
 {
-	QofInstance *inst;
-	struct qsf_node_iterate iter;
-	QofBook *book;
-	GList *object_list;
-	xmlNodePtr qsf_root;
-	xmlNsPtr qsf_ns;
+    QofInstance *inst;
+    struct qsf_node_iterate iter;
+    QofBook *book;
+    GList *object_list;
+    xmlNodePtr qsf_root;
+    xmlNsPtr qsf_ns;
 
-	g_return_val_if_fail(params != NULL, FALSE);
-	g_return_val_if_fail(params->input_doc != NULL, FALSE);
-	g_return_val_if_fail(params->book != NULL, FALSE);
-	g_return_val_if_fail(params->file_type == OUR_QSF_OBJ, FALSE);
-	qsf_root = xmlDocGetRootElement(params->input_doc);
-	if(!qsf_root) { return FALSE; }
-	qsf_ns = qsf_root->ns;
-	iter.ns = qsf_ns;
-	book = params->book;
-	params->referenceList = (GList*)qof_book_get_data(book, ENTITYREFERENCE);
-	qsf_node_foreach(qsf_root, qsf_book_node_handler, &iter, params);
-	object_list = g_list_copy(params->qsf_object_list);
-	while(object_list != NULL)
-	{
-		params->object_set = object_list->data;
-		object_list = g_list_next(object_list);
-		params->qsf_parameter_hash = params->object_set->parameters;
-		if(!qof_class_is_registered(params->object_set->object_type)) { continue; }
-		inst = (QofInstance*)qof_object_new_instance(params->object_set->object_type, book);
-		g_return_val_if_fail(inst != NULL, FALSE);
-		params->qsf_ent = inst;
-		qof_begin_edit(inst);
-		g_hash_table_foreach(params->qsf_parameter_hash, qsf_object_commitCB, params);
-		qof_commit_edit(inst);
-	}
-	qof_object_foreach_type(insert_ref_cb, params);
-	qof_book_set_data(book, ENTITYREFERENCE, params->referenceList);
-	return TRUE;
+    g_return_val_if_fail(params != NULL, FALSE);
+    g_return_val_if_fail(params->input_doc != NULL, FALSE);
+    g_return_val_if_fail(params->book != NULL, FALSE);
+    g_return_val_if_fail(params->file_type == OUR_QSF_OBJ, FALSE);
+    qsf_root = xmlDocGetRootElement(params->input_doc);
+    if (!qsf_root)
+    {
+        return FALSE;
+    }
+    qsf_ns = qsf_root->ns;
+    iter.ns = qsf_ns;
+    book = params->book;
+    params->referenceList = (GList*)qof_book_get_data(book, ENTITYREFERENCE);
+    qsf_node_foreach(qsf_root, qsf_book_node_handler, &iter, params);
+    object_list = g_list_copy(params->qsf_object_list);
+    while (object_list != NULL)
+    {
+        params->object_set = object_list->data;
+        object_list = g_list_next(object_list);
+        params->qsf_parameter_hash = params->object_set->parameters;
+        if (!qof_class_is_registered(params->object_set->object_type))
+        {
+            continue;
+        }
+        inst = (QofInstance*)qof_object_new_instance(params->object_set->object_type, book);
+        g_return_val_if_fail(inst != NULL, FALSE);
+        params->qsf_ent = inst;
+        qof_begin_edit(inst);
+        g_hash_table_foreach(params->qsf_parameter_hash, qsf_object_commitCB, params);
+        qof_commit_edit(inst);
+    }
+    qof_object_foreach_type(insert_ref_cb, params);
+    qof_book_set_data(book, ENTITYREFERENCE, params->referenceList);
+    return TRUE;
 }
 
 /* QofBackend routine to load from file - needs a map.
@@ -380,57 +431,62 @@
 static gboolean
 load_qsf_object(QofBook *book, const gchar *fullpath, qsf_param *params)
 {
-	xmlNodePtr qsf_root, map_root;
-	xmlDocPtr mapDoc, foreign_doc;
-	gchar *map_path, *map_file;
+    xmlNodePtr qsf_root, map_root;
+    xmlDocPtr mapDoc, foreign_doc;
+    gchar *map_path, *map_file;
 
-	map_file = params->map_path;
-	mapDoc = NULL;
-	/* use selected map */
-	if(!map_file) {
-		qof_backend_set_error(params->be, ERR_QSF_NO_MAP);
-		return FALSE; 
-	}
-	foreign_doc = xmlParseFile(fullpath);
-	if (foreign_doc == NULL) {
-		qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
-		return FALSE;
-	}
-	qsf_root = NULL;
-	qsf_root = xmlDocGetRootElement(foreign_doc);
-	params->qsf_ns = qsf_root->ns;
-	params->book = book;
-	map_path = g_strdup_printf("%s/%s", QSF_SCHEMA_DIR, map_file);
-	if(!map_path) {
-		qof_backend_set_error(params->be, ERR_QSF_NO_MAP);
-		return FALSE; 
-	}
-	mapDoc = xmlParseFile(map_path);
-	if(!mapDoc) {
-		qof_backend_set_error(params->be, ERR_QSF_NO_MAP);
-		return FALSE;
-	}
-	map_root = xmlDocGetRootElement(mapDoc);
-	params->map_ns = map_root->ns;
-	params->input_doc = qsf_object_convert(mapDoc, qsf_root, params);
-	qsfdoc_to_qofbook(params->input_doc, params);
-	return TRUE;
+    map_file = params->map_path;
+    mapDoc = NULL;
+    /* use selected map */
+    if (!map_file)
+    {
+        qof_backend_set_error(params->be, ERR_QSF_NO_MAP);
+        return FALSE;
+    }
+    foreign_doc = xmlParseFile(fullpath);
+    if (foreign_doc == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
+        return FALSE;
+    }
+    qsf_root = NULL;
+    qsf_root = xmlDocGetRootElement(foreign_doc);
+    params->qsf_ns = qsf_root->ns;
+    params->book = book;
+    map_path = g_strdup_printf("%s/%s", QSF_SCHEMA_DIR, map_file);
+    if (!map_path)
+    {
+        qof_backend_set_error(params->be, ERR_QSF_NO_MAP);
+        return FALSE;
+    }
+    mapDoc = xmlParseFile(map_path);
+    if (!mapDoc)
+    {
+        qof_backend_set_error(params->be, ERR_QSF_NO_MAP);
+        return FALSE;
+    }
+    map_root = xmlDocGetRootElement(mapDoc);
+    params->map_ns = map_root->ns;
+    params->input_doc = qsf_object_convert(mapDoc, qsf_root, params);
+    qsfdoc_to_qofbook(params->input_doc, params);
+    return TRUE;
 }
 
 static gboolean
 load_our_qsf_object(QofBook *book, const gchar *fullpath, qsf_param *params)
 {
-	xmlNodePtr qsf_root;
+    xmlNodePtr qsf_root;
 
-	params->input_doc = xmlParseFile(fullpath);
-	if (params->input_doc == NULL) {
-		qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
-		return FALSE;
-	}
-	qsf_root = NULL;
-	qsf_root = xmlDocGetRootElement(params->input_doc);
-	params->qsf_ns = qsf_root->ns;
-	return qsfdoc_to_qofbook(params->input_doc, params);
+    params->input_doc = xmlParseFile(fullpath);
+    if (params->input_doc == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
+        return FALSE;
+    }
+    qsf_root = NULL;
+    qsf_root = xmlDocGetRootElement(params->input_doc);
+    params->qsf_ns = qsf_root->ns;
+    return qsfdoc_to_qofbook(params->input_doc, params);
 }
 
 /* Determine the type of QSF and load it into the QofBook
@@ -438,94 +494,107 @@
 - is_our_qsf_object, OUR_QSF_OBJ, QSF object file using only QOF objects known
 	to the calling process.	No map is required.
 - is_qsf_object, IS_QSF_OBJ, QSF object file that may or may not have a QSF map
-	to convert external objects. This temporary type will be set to HAVE_QSF_MAP 
-	if a suitable map exists, or an error value returned: ERR_QSF_NO_MAP, 
-	ERR_QSF_BAD_MAP or ERR_QSF_WRONG_MAP. This allows the calling process to inform 
+	to convert external objects. This temporary type will be set to HAVE_QSF_MAP
+	if a suitable map exists, or an error value returned: ERR_QSF_NO_MAP,
+	ERR_QSF_BAD_MAP or ERR_QSF_WRONG_MAP. This allows the calling process to inform
 	the user that the QSF itself is valid but a suitable map cannot be found.
-- is_qsf_map, IS_QSF_MAP, QSF map file. In the backend, this generates 
-	ERR_QSF_MAP_NOT_OBJ but	it can be used internally when processing maps to 
+- is_qsf_map, IS_QSF_MAP, QSF map file. In the backend, this generates
+	ERR_QSF_MAP_NOT_OBJ but	it can be used internally when processing maps to
 	match a QSF object.
 
 returns NULL on error, otherwise a pointer to the QofBook. Use
 	the qof_book_merge API to merge the new data into the current
-	QofBook. 
+	QofBook.
 */
 static void
 qsf_file_type(QofBackend *be, QofBook *book, QofBackendLoadType loadType)
 {
-	QSFBackend *qsf_be;
-	qsf_param *params;
-	FILE *f;
-	gchar *path;
-	gboolean result;
+    QSFBackend *qsf_be;
+    qsf_param *params;
+    FILE *f;
+    gchar *path;
+    gboolean result;
 
-	g_return_if_fail(be != NULL);
-	g_return_if_fail(book != NULL);
-	qsf_be = (QSFBackend*) be;
-	g_return_if_fail(qsf_be != NULL);
-	g_return_if_fail(qsf_be->fullpath != NULL);
-	g_return_if_fail(qsf_be->params != NULL);
-	params = qsf_be->params;
-	params->book = book;
-	path = g_strdup(qsf_be->fullpath);
-	f = g_fopen(path, "r");
-	if(!f) { qof_backend_set_error(be, ERR_FILEIO_READ_ERROR); }
-	fclose(f);
-	params->filepath = g_strdup(path);
-	qof_backend_get_error(be);
-	result = is_our_qsf_object_be(params);
-	if(result) {
-		params->file_type = OUR_QSF_OBJ;
-		result = load_our_qsf_object(book, path, params);
-		if(!result) { qof_backend_set_error(be, ERR_FILEIO_PARSE_ERROR); }
-		return;
-	}
-	else if(is_qsf_object_be(params)) {
-		params->file_type = IS_QSF_OBJ;
-		result = load_qsf_object(book, path, params);
-		if(!result) { qof_backend_set_error(be, ERR_FILEIO_PARSE_ERROR); }
-		return;
-	}
-	if(result == FALSE) {
-		if(is_qsf_map_be(params)) {
-		params->file_type = IS_QSF_MAP;
-		qof_backend_set_error(be, ERR_QSF_MAP_NOT_OBJ);
-		}
-	}
+    g_return_if_fail(be != NULL);
+    g_return_if_fail(book != NULL);
+    qsf_be = (QSFBackend*) be;
+    g_return_if_fail(qsf_be != NULL);
+    g_return_if_fail(qsf_be->fullpath != NULL);
+    g_return_if_fail(qsf_be->params != NULL);
+    params = qsf_be->params;
+    params->book = book;
+    path = g_strdup(qsf_be->fullpath);
+    f = g_fopen(path, "r");
+    if (!f)
+    {
+        qof_backend_set_error(be, ERR_FILEIO_READ_ERROR);
+    }
+    fclose(f);
+    params->filepath = g_strdup(path);
+    qof_backend_get_error(be);
+    result = is_our_qsf_object_be(params);
+    if (result)
+    {
+        params->file_type = OUR_QSF_OBJ;
+        result = load_our_qsf_object(book, path, params);
+        if (!result)
+        {
+            qof_backend_set_error(be, ERR_FILEIO_PARSE_ERROR);
+        }
+        return;
+    }
+    else if (is_qsf_object_be(params))
+    {
+        params->file_type = IS_QSF_OBJ;
+        result = load_qsf_object(book, path, params);
+        if (!result)
+        {
+            qof_backend_set_error(be, ERR_FILEIO_PARSE_ERROR);
+        }
+        return;
+    }
+    if (result == FALSE)
+    {
+        if (is_qsf_map_be(params))
+        {
+            params->file_type = IS_QSF_MAP;
+            qof_backend_set_error(be, ERR_QSF_MAP_NOT_OBJ);
+        }
+    }
 }
 
 static void
 qsf_object_sequence(QofParam *qof_param, gpointer data)
 {
-	qsf_param *params;
-	GSList *checklist, *result;
+    qsf_param *params;
+    GSList *checklist, *result;
 
-	g_return_if_fail(data != NULL);
-	params = (qsf_param*) data;
-	result = NULL;
-	checklist = NULL;
-	params->knowntype = FALSE;
-	checklist = g_slist_copy(params->supported_types);
-	for(result = checklist; result != NULL; result = result->next)
-	{
-		if(0 == safe_strcmp((QofIdType)result->data, qof_param->param_type))
-		{
-			params->knowntype = TRUE;
-		}
-	}
-	g_slist_free(checklist);
-	if(0 == safe_strcmp(qof_param->param_type, params->qof_type))
-	{
-		params->qsf_sequence = g_slist_append(params->qsf_sequence, qof_param);
-		params->knowntype = TRUE;
-	}
-	/* handle params->qof_type = QOF_TYPE_GUID and qof_param->param_type != known type */
-	if(0 == safe_strcmp(params->qof_type, QOF_TYPE_GUID)
-		&& (params->knowntype == FALSE))
-	{
-		params->qsf_sequence = g_slist_append(params->qsf_sequence, qof_param);
-		params->knowntype = TRUE;
-	}
+    g_return_if_fail(data != NULL);
+    params = (qsf_param*) data;
+    result = NULL;
+    checklist = NULL;
+    params->knowntype = FALSE;
+    checklist = g_slist_copy(params->supported_types);
+    for (result = checklist; result != NULL; result = result->next)
+    {
+        if (0 == safe_strcmp((QofIdType)result->data, qof_param->param_type))
+        {
+            params->knowntype = TRUE;
+        }
+    }
+    g_slist_free(checklist);
+    if (0 == safe_strcmp(qof_param->param_type, params->qof_type))
+    {
+        params->qsf_sequence = g_slist_append(params->qsf_sequence, qof_param);
+        params->knowntype = TRUE;
+    }
+    /* handle params->qof_type = QOF_TYPE_GUID and qof_param->param_type != known type */
+    if (0 == safe_strcmp(params->qof_type, QOF_TYPE_GUID)
+            && (params->knowntype == FALSE))
+    {
+        params->qsf_sequence = g_slist_append(params->qsf_sequence, qof_param);
+        params->knowntype = TRUE;
+    }
 }
 
 /* receives each entry from supported_types in sequence
@@ -535,125 +604,198 @@
 static void
 qsf_supported_parameters(gpointer type, gpointer user_data)
 {
-	qsf_param *params;
+    qsf_param *params;
 
-	g_return_if_fail(user_data != NULL);
-	params = (qsf_param*) user_data;
-	params->qof_type = (QofIdType)type;
-	params->knowntype = FALSE;
-	qof_class_param_foreach(params->qof_obj_type, qsf_object_sequence, params);
+    g_return_if_fail(user_data != NULL);
+    params = (qsf_param*) user_data;
+    params->qof_type = (QofIdType)type;
+    params->knowntype = FALSE;
+    qof_class_param_foreach(params->qof_obj_type, qsf_object_sequence, params);
 }
 
 static KvpValueType
 qsf_to_kvp_helper(const char *type_string)
 {
-	if(0 == safe_strcmp(QOF_TYPE_INT64,   type_string)) { return KVP_TYPE_GINT64;   }
-	if(0 == safe_strcmp(QOF_TYPE_DOUBLE,  type_string)) { return KVP_TYPE_DOUBLE;   }
-	if(0 == safe_strcmp(QOF_TYPE_NUMERIC, type_string)) { return KVP_TYPE_NUMERIC;  }
-	if(0 == safe_strcmp(QOF_TYPE_STRING,  type_string)) { return KVP_TYPE_STRING;   }
-	if(0 == safe_strcmp(QOF_TYPE_GUID,    type_string)) { return KVP_TYPE_GUID;     }
-	if(0 == safe_strcmp(QOF_TYPE_DATE,    type_string)) { return KVP_TYPE_TIMESPEC; }
-	if(0 == safe_strcmp(QSF_TYPE_BINARY,  type_string)) { return KVP_TYPE_BINARY;   }
-	if(0 == safe_strcmp(QSF_TYPE_GLIST,   type_string)) { return KVP_TYPE_GLIST;    }
-	if(0 == safe_strcmp(QSF_TYPE_FRAME,   type_string)) { return KVP_TYPE_FRAME;    }
-	return 0;
+    if (0 == safe_strcmp(QOF_TYPE_INT64,   type_string))
+    {
+        return KVP_TYPE_GINT64;
+    }
+    if (0 == safe_strcmp(QOF_TYPE_DOUBLE,  type_string))
+    {
+        return KVP_TYPE_DOUBLE;
+    }
+    if (0 == safe_strcmp(QOF_TYPE_NUMERIC, type_string))
+    {
+        return KVP_TYPE_NUMERIC;
+    }
+    if (0 == safe_strcmp(QOF_TYPE_STRING,  type_string))
+    {
+        return KVP_TYPE_STRING;
+    }
+    if (0 == safe_strcmp(QOF_TYPE_GUID,    type_string))
+    {
+        return KVP_TYPE_GUID;
+    }
+    if (0 == safe_strcmp(QOF_TYPE_DATE,    type_string))
+    {
+        return KVP_TYPE_TIMESPEC;
+    }
+    if (0 == safe_strcmp(QSF_TYPE_BINARY,  type_string))
+    {
+        return KVP_TYPE_BINARY;
+    }
+    if (0 == safe_strcmp(QSF_TYPE_GLIST,   type_string))
+    {
+        return KVP_TYPE_GLIST;
+    }
+    if (0 == safe_strcmp(QSF_TYPE_FRAME,   type_string))
+    {
+        return KVP_TYPE_FRAME;
+    }
+    return 0;
 }
 
 static QofIdTypeConst
 kvp_value_to_qof_type_helper(KvpValueType n)
 {
-	switch(n)
-	{
-		case KVP_TYPE_GINT64   : { return QOF_TYPE_INT64;   break; }
-		case KVP_TYPE_DOUBLE   : { return QOF_TYPE_DOUBLE;  break; }
-		case KVP_TYPE_NUMERIC  : { return QOF_TYPE_NUMERIC; break; }
-		case KVP_TYPE_STRING   : { return QOF_TYPE_STRING;  break; }
-		case KVP_TYPE_GUID     : { return QOF_TYPE_GUID;    break; }
-		case KVP_TYPE_TIMESPEC : { return QOF_TYPE_DATE;    break; }
-		case KVP_TYPE_BINARY   : { return QSF_TYPE_BINARY;  break; }
-		case KVP_TYPE_GLIST    : { return QSF_TYPE_GLIST;   break; }
-		case KVP_TYPE_FRAME    : { return QSF_TYPE_FRAME;   break; }
-		default : { return NULL; }
-	}
+    switch (n)
+    {
+    case KVP_TYPE_GINT64   :
+    {
+        return QOF_TYPE_INT64;
+        break;
+    }
+    case KVP_TYPE_DOUBLE   :
+    {
+        return QOF_TYPE_DOUBLE;
+        break;
+    }
+    case KVP_TYPE_NUMERIC  :
+    {
+        return QOF_TYPE_NUMERIC;
+        break;
+    }
+    case KVP_TYPE_STRING   :
+    {
+        return QOF_TYPE_STRING;
+        break;
+    }
+    case KVP_TYPE_GUID     :
+    {
+        return QOF_TYPE_GUID;
+        break;
+    }
+    case KVP_TYPE_TIMESPEC :
+    {
+        return QOF_TYPE_DATE;
+        break;
+    }
+    case KVP_TYPE_BINARY   :
+    {
+        return QSF_TYPE_BINARY;
+        break;
+    }
+    case KVP_TYPE_GLIST    :
+    {
+        return QSF_TYPE_GLIST;
+        break;
+    }
+    case KVP_TYPE_FRAME    :
+    {
+        return QSF_TYPE_FRAME;
+        break;
+    }
+    default :
+    {
+        return NULL;
+    }
+    }
 }
 
 
 static void
 qsf_from_kvp_helper(const gchar *path, KvpValue *content, gpointer data)
 {
-	qsf_param *params;
-	QofParam *qof_param;
-	xmlNodePtr node;
-	KvpValueType n;
-	gchar *full_path;
+    qsf_param *params;
+    QofParam *qof_param;
+    xmlNodePtr node;
+    KvpValueType n;
+    gchar *full_path;
 
-	params = (qsf_param*)data;
-	qof_param = params->qof_param;
-	full_path = NULL;
-	g_return_if_fail(params && path && content);
-	ENTER (" ");
-	n = kvp_value_get_type(content);
-	switch(n)
-	{
-		case KVP_TYPE_GINT64   :
-		case KVP_TYPE_DOUBLE   :
-		case KVP_TYPE_NUMERIC  :
-		case KVP_TYPE_STRING   :
-		case KVP_TYPE_GUID     :
-		case KVP_TYPE_TIMESPEC :
-		case KVP_TYPE_BINARY   :
-		case KVP_TYPE_GLIST    :
-		{
-			node = xmlAddChild(params->output_node, xmlNewNode(params->qsf_ns,
-				BAD_CAST qof_param->param_type));
-			xmlNodeAddContent(node, BAD_CAST kvp_value_to_bare_string(content));
-			xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
-			full_path = g_strconcat(params->full_kvp_path, "/", path, NULL);
-			xmlNewProp(node, BAD_CAST QSF_OBJECT_KVP, BAD_CAST full_path);
-			xmlNewProp(node, BAD_CAST QSF_OBJECT_VALUE, 
-				BAD_CAST kvp_value_to_qof_type_helper(n));
-			PINFO (" set %s", kvp_value_to_qof_type_helper(n));
-			break;
-		}
-		case KVP_TYPE_FRAME:
-		{
-			if(!params->full_kvp_path) { params->full_kvp_path = g_strdup(path); }
-			else { 
-				params->full_kvp_path = g_strconcat(params->full_kvp_path, 
-					"/", path, NULL);
-			}
-			PINFO (" full=%s, path=%s ", params->full_kvp_path, path);
-			kvp_frame_for_each_slot(kvp_value_get_frame(content), 
-				qsf_from_kvp_helper, params);
-			g_free(params->full_kvp_path);
-			params->full_kvp_path = NULL;
-			break;
-		}
-		default:
-		{
-			PERR (" unsupported value = %d", kvp_value_get_type(content));
-			break;
-		}
-	}
-	LEAVE (" ");
+    params = (qsf_param*)data;
+    qof_param = params->qof_param;
+    full_path = NULL;
+    g_return_if_fail(params && path && content);
+    ENTER (" ");
+    n = kvp_value_get_type(content);
+    switch (n)
+    {
+    case KVP_TYPE_GINT64   :
+    case KVP_TYPE_DOUBLE   :
+    case KVP_TYPE_NUMERIC  :
+    case KVP_TYPE_STRING   :
+    case KVP_TYPE_GUID     :
+    case KVP_TYPE_TIMESPEC :
+    case KVP_TYPE_BINARY   :
+    case KVP_TYPE_GLIST    :
+    {
+        node = xmlAddChild(params->output_node, xmlNewNode(params->qsf_ns,
+                           BAD_CAST qof_param->param_type));
+        xmlNodeAddContent(node, BAD_CAST kvp_value_to_bare_string(content));
+        xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
+        full_path = g_strconcat(params->full_kvp_path, "/", path, NULL);
+        xmlNewProp(node, BAD_CAST QSF_OBJECT_KVP, BAD_CAST full_path);
+        xmlNewProp(node, BAD_CAST QSF_OBJECT_VALUE,
+                   BAD_CAST kvp_value_to_qof_type_helper(n));
+        PINFO (" set %s", kvp_value_to_qof_type_helper(n));
+        break;
+    }
+    case KVP_TYPE_FRAME:
+    {
+        if (!params->full_kvp_path)
+        {
+            params->full_kvp_path = g_strdup(path);
+        }
+        else
+        {
+            params->full_kvp_path = g_strconcat(params->full_kvp_path,
+                                                "/", path, NULL);
+        }
+        PINFO (" full=%s, path=%s ", params->full_kvp_path, path);
+        kvp_frame_for_each_slot(kvp_value_get_frame(content),
+                                qsf_from_kvp_helper, params);
+        g_free(params->full_kvp_path);
+        params->full_kvp_path = NULL;
+        break;
+    }
+    default:
+    {
+        PERR (" unsupported value = %d", kvp_value_get_type(content));
+        break;
+    }
+    }
+    LEAVE (" ");
 }
 
 static void
 qsf_from_coll_cb (QofInstance *ent, gpointer user_data)
 {
-	qsf_param *params;
-	QofParam *qof_param;
-	xmlNodePtr node;
-	gchar qsf_guid[GUID_ENCODING_LENGTH + 1];
+    qsf_param *params;
+    QofParam *qof_param;
+    xmlNodePtr node;
+    gchar qsf_guid[GUID_ENCODING_LENGTH + 1];
 
-	params = (qsf_param*)user_data;
-	if(!ent || !params) { return; }
-	qof_param = params->qof_param;
-	guid_to_string_buff(qof_instance_get_guid(ent), qsf_guid);
-	node = xmlAddChild(params->output_node, xmlNewNode(params->qsf_ns,
-		BAD_CAST qof_param->param_type));
-	xmlNodeAddContent(node, BAD_CAST qsf_guid);
-	xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
+    params = (qsf_param*)user_data;
+    if (!ent || !params)
+    {
+        return;
+    }
+    qof_param = params->qof_param;
+    guid_to_string_buff(qof_instance_get_guid(ent), qsf_guid);
+    node = xmlAddChild(params->output_node, xmlNewNode(params->qsf_ns,
+                       BAD_CAST qof_param->param_type));
+    xmlNodeAddContent(node, BAD_CAST qsf_guid);
+    xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
 }
 
 /******* reference handling ***********/
@@ -661,91 +803,107 @@
 static gint
 qof_reference_list_cb(gconstpointer a, gconstpointer b)
 {
-	const QofInstanceReference *aa;
-	const QofInstanceReference *bb;
+    const QofInstanceReference *aa;
+    const QofInstanceReference *bb;
 
-	aa = (QofInstanceReference*) a;
-	bb = (QofInstanceReference*) b;
-	if(aa == NULL) { return 1; }
-	g_return_val_if_fail((bb != NULL), 1);
-	g_return_val_if_fail((aa->type != NULL), 1);
-	if((0 == guid_compare(bb->ent_guid, aa->ent_guid))
-		&&(0 == safe_strcmp(bb->type, aa->type))
-		&&(0 == safe_strcmp(bb->param->param_name, aa->param->param_name)))
-	{
-		return 0;
-	}
-	return 1;
+    aa = (QofInstanceReference*) a;
+    bb = (QofInstanceReference*) b;
+    if (aa == NULL)
+    {
+        return 1;
+    }
+    g_return_val_if_fail((bb != NULL), 1);
+    g_return_val_if_fail((aa->type != NULL), 1);
+    if ((0 == guid_compare(bb->ent_guid, aa->ent_guid))
+            && (0 == safe_strcmp(bb->type, aa->type))
+            && (0 == safe_strcmp(bb->param->param_name, aa->param->param_name)))
+    {
+        return 0;
+    }
+    return 1;
 }
 
 static QofInstanceReference*
 qof_reference_lookup(GList *referenceList, QofInstanceReference *find)
 {
-	GList *single_ref;
-	QofInstanceReference *ent_ref;
+    GList *single_ref;
+    QofInstanceReference *ent_ref;
 
-	if(referenceList == NULL) { return NULL; }
-	g_return_val_if_fail(find != NULL, NULL);
-	single_ref = NULL;
-	ent_ref = NULL;
-	single_ref = g_list_find_custom(referenceList, find, qof_reference_list_cb);
-	if(single_ref == NULL) { return ent_ref; }
-	ent_ref = (QofInstanceReference*)single_ref->data;
-	g_list_free(single_ref);
-	return ent_ref;
+    if (referenceList == NULL)
+    {
+        return NULL;
+    }
+    g_return_val_if_fail(find != NULL, NULL);
+    single_ref = NULL;
+    ent_ref = NULL;
+    single_ref = g_list_find_custom(referenceList, find, qof_reference_list_cb);
+    if (single_ref == NULL)
+    {
+        return ent_ref;
+    }
+    ent_ref = (QofInstanceReference*)single_ref->data;
+    g_list_free(single_ref);
+    return ent_ref;
 }
 
 static void
 reference_list_lookup(gpointer data, gpointer user_data)
 {
-	QofInstance *ent;
-	QofParam *ref_param;
-	QofInstanceReference *reference, *starter;
-	qsf_param  *params;
-	const GUID *guid;
-	xmlNodePtr node, object_node;
-	xmlNsPtr ns;
-	GList *copy_list;
-	gchar qsf_guid[GUID_ENCODING_LENGTH + 1], *ref_name;
+    QofInstance *ent;
+    QofParam *ref_param;
+    QofInstanceReference *reference, *starter;
+    qsf_param  *params;
+    const GUID *guid;
+    xmlNodePtr node, object_node;
+    xmlNsPtr ns;
+    GList *copy_list;
+    gchar qsf_guid[GUID_ENCODING_LENGTH + 1], *ref_name;
 
-	params = (qsf_param*)user_data;
-	ref_param = (QofParam*)data;
-	object_node = params->output_node;
-	ent = params->qsf_ent;
-	g_return_if_fail(ent);
-	ns = params->qsf_ns;
-	starter = g_new(QofInstanceReference, 1);
-	starter->ent_guid = qof_instance_get_guid(ent);
-	starter->type = g_strdup(ent->e_type);
-	starter->param = ref_param;
-	starter->ref_guid = NULL;
-	copy_list = g_list_copy(params->referenceList);
-	reference = qof_reference_lookup(copy_list, starter);
-	g_free(starter);
-	if(reference != NULL) {
-		if((ref_param->param_getfcn == NULL)||(ref_param->param_setfcn == NULL))
-		{
-			return;
-		}
-		ref_name = g_strdup(reference->param->param_name);
-		node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST QOF_TYPE_GUID));
-		guid_to_string_buff(reference->ref_guid, qsf_guid);
-		xmlNodeAddContent(node, BAD_CAST qsf_guid);
-		xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST ref_name);
-		g_free(ref_name);
-	}
-	else {
-		ent = QOF_INSTANCE(ref_param->param_getfcn(ent, ref_param));
-		if(!ent) { return; }
-		if((0 == safe_strcmp(ref_param->param_type, QOF_TYPE_COLLECT)) ||
-			(0 == safe_strcmp(ref_param->param_type, QOF_TYPE_CHOICE)))
-		{ return; }
-		node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST QOF_TYPE_GUID));
-		guid = qof_instance_get_guid(ent);
-		guid_to_string_buff(guid, qsf_guid);
-		xmlNodeAddContent(node, BAD_CAST qsf_guid);
-		xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST ref_param->param_name);
-	}
+    params = (qsf_param*)user_data;
+    ref_param = (QofParam*)data;
+    object_node = params->output_node;
+    ent = params->qsf_ent;
+    g_return_if_fail(ent);
+    ns = params->qsf_ns;
+    starter = g_new(QofInstanceReference, 1);
+    starter->ent_guid = qof_instance_get_guid(ent);
+    starter->type = g_strdup(ent->e_type);
+    starter->param = ref_param;
+    starter->ref_guid = NULL;
+    copy_list = g_list_copy(params->referenceList);
+    reference = qof_reference_lookup(copy_list, starter);
+    g_free(starter);
+    if (reference != NULL)
+    {
+        if ((ref_param->param_getfcn == NULL) || (ref_param->param_setfcn == NULL))
+        {
+            return;
+        }
+        ref_name = g_strdup(reference->param->param_name);
+        node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST QOF_TYPE_GUID));
+        guid_to_string_buff(reference->ref_guid, qsf_guid);
+        xmlNodeAddContent(node, BAD_CAST qsf_guid);
+        xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST ref_name);
+        g_free(ref_name);
+    }
+    else
+    {
+        ent = QOF_INSTANCE(ref_param->param_getfcn(ent, ref_param));
+        if (!ent)
+        {
+            return;
+        }
+        if ((0 == safe_strcmp(ref_param->param_type, QOF_TYPE_COLLECT)) ||
+                (0 == safe_strcmp(ref_param->param_type, QOF_TYPE_CHOICE)))
+        {
+            return;
+        }
+        node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST QOF_TYPE_GUID));
+        guid = qof_instance_get_guid(ent);
+        guid_to_string_buff(guid, qsf_guid);
+        xmlNodeAddContent(node, BAD_CAST qsf_guid);
+        xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST ref_param->param_name);
+    }
 }
 
 /*=====================================
@@ -755,138 +913,148 @@
 static void
 qsf_entity_foreach(QofInstance *ent, gpointer data)
 {
-	qsf_param  *params;
-	GSList     *param_list, *supported;
-	GList      *ref;
-	xmlNodePtr node, object_node;
-	xmlNsPtr   ns;
-	gchar      *string_buffer;
-	QofParam   *qof_param;
-	QofInstance  *choice_ent;
-	KvpFrame   *qsf_kvp;
-	QofCollection *qsf_coll;
-	gint        param_count;
-	gboolean   own_guid;
-	const GUID *cm_guid;
-	gchar       cm_sa[GUID_ENCODING_LENGTH + 1];
+    qsf_param  *params;
+    GSList     *param_list, *supported;
+    GList      *ref;
+    xmlNodePtr node, object_node;
+    xmlNsPtr   ns;
+    gchar      *string_buffer;
+    QofParam   *qof_param;
+    QofInstance  *choice_ent;
+    KvpFrame   *qsf_kvp;
+    QofCollection *qsf_coll;
+    gint        param_count;
+    gboolean   own_guid;
+    const GUID *cm_guid;
+    gchar       cm_sa[GUID_ENCODING_LENGTH + 1];
 
-	g_return_if_fail(ent != NULL);
-	g_return_if_fail(data != NULL);
-	params = (qsf_param*)data;
-	param_count = ++params->count;
-	ns = params->qsf_ns;
-	qsf_kvp = kvp_frame_new();
-	own_guid = FALSE;
-	choice_ent = NULL;
-	object_node = xmlNewChild(params->book_node, params->qsf_ns,
-		BAD_CAST QSF_OBJECT_TAG, NULL);
-	xmlNewProp(object_node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST ent->e_type);
-	string_buffer = g_strdup_printf("%i", param_count);
-	xmlNewProp(object_node, BAD_CAST QSF_OBJECT_COUNT, BAD_CAST string_buffer);
-	g_free(string_buffer);
-	param_list = g_slist_copy(params->qsf_sequence);
-	while(param_list != NULL) {
-		qof_param = (QofParam*)param_list->data;
-		g_return_if_fail(qof_param != NULL);
-		if(0 == safe_strcmp(qof_param->param_type, QOF_TYPE_GUID))
-		{
-			if(!own_guid)
-			{
-				cm_guid = qof_instance_get_guid(ent);
-				node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST QOF_TYPE_GUID));
-				guid_to_string_buff(cm_guid, cm_sa);
-				string_buffer = g_strdup(cm_sa);
-				xmlNodeAddContent(node, BAD_CAST string_buffer);
-				xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE , BAD_CAST QOF_PARAM_GUID);
-				g_free(string_buffer);
-				own_guid = TRUE;
-			}
-			params->qsf_ent = ent;
-			params->output_node = object_node;
-			ref = qof_class_get_referenceList(ent->e_type);
-			if(ref != NULL) {
-				g_list_foreach(ref, reference_list_lookup, params);
-			}
-		}
-		if(0 == safe_strcmp(qof_param->param_type, QOF_TYPE_COLLECT))
-		{
-			qsf_coll = qof_param->param_getfcn(ent, qof_param);
-			if(qsf_coll) {
-				params->qof_param = qof_param;
-				params->output_node = object_node;
-				if(qof_collection_count(qsf_coll) > 0) {
-					qof_collection_foreach(qsf_coll, qsf_from_coll_cb, params);
-				}
-			}
-			param_list = g_slist_next(param_list);
-			continue;
-		}
-		if(0 == safe_strcmp(qof_param->param_type, QOF_TYPE_CHOICE))
-		{
-			/** \todo use the reference list here. */
-			choice_ent = QOF_INSTANCE(qof_param->param_getfcn(ent, qof_param));
-			if(!choice_ent) {
-				param_list = g_slist_next(param_list);
-				continue;
-			}
-			node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST qof_param->param_type));
-			cm_guid = qof_instance_get_guid(choice_ent);
-			guid_to_string_buff(cm_guid, cm_sa);
-			string_buffer = g_strdup(cm_sa);
-			xmlNodeAddContent(node, BAD_CAST string_buffer);
-			xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
-			xmlNewProp(node, BAD_CAST "name", BAD_CAST choice_ent->e_type);
-			g_free(string_buffer);
-			param_list = g_slist_next(param_list);
-			continue;
-		}
-		if(0 == safe_strcmp(qof_param->param_type, QOF_TYPE_KVP))
-		{
-			qsf_kvp = (KvpFrame*)qof_param->param_getfcn(ent,qof_param);
-			if(kvp_frame_is_empty(qsf_kvp))	{ LEAVE(" "); return; }
-			params->qof_param = qof_param;
-			params->output_node = object_node;
-			kvp_frame_for_each_slot(qsf_kvp, qsf_from_kvp_helper, params);
-		}
-		if((qof_param->param_setfcn != NULL) && (qof_param->param_getfcn != NULL))
-		{
-			for( supported = g_slist_copy(params->supported_types);
-				supported != NULL; supported = g_slist_next(supported))
-			{
-				if(0 == safe_strcmp((const gchar*)supported->data, (const gchar*)qof_param->param_type))
-				{
-					node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST qof_param->param_type));
-					string_buffer = g_strdup(qof_book_merge_param_as_string(qof_param, ent));
-					xmlNodeAddContent(node, BAD_CAST string_buffer);
-					xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
-					g_free(string_buffer);
-				}
-			}
-		}
-		param_list = g_slist_next(param_list);
-	}
+    g_return_if_fail(ent != NULL);
+    g_return_if_fail(data != NULL);
+    params = (qsf_param*)data;
+    param_count = ++params->count;
+    ns = params->qsf_ns;
+    qsf_kvp = kvp_frame_new();
+    own_guid = FALSE;
+    choice_ent = NULL;
+    object_node = xmlNewChild(params->book_node, params->qsf_ns,
+                              BAD_CAST QSF_OBJECT_TAG, NULL);
+    xmlNewProp(object_node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST ent->e_type);
+    string_buffer = g_strdup_printf("%i", param_count);
+    xmlNewProp(object_node, BAD_CAST QSF_OBJECT_COUNT, BAD_CAST string_buffer);
+    g_free(string_buffer);
+    param_list = g_slist_copy(params->qsf_sequence);
+    while (param_list != NULL)
+    {
+        qof_param = (QofParam*)param_list->data;
+        g_return_if_fail(qof_param != NULL);
+        if (0 == safe_strcmp(qof_param->param_type, QOF_TYPE_GUID))
+        {
+            if (!own_guid)
+            {
+                cm_guid = qof_instance_get_guid(ent);
+                node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST QOF_TYPE_GUID));
+                guid_to_string_buff(cm_guid, cm_sa);
+                string_buffer = g_strdup(cm_sa);
+                xmlNodeAddContent(node, BAD_CAST string_buffer);
+                xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE , BAD_CAST QOF_PARAM_GUID);
+                g_free(string_buffer);
+                own_guid = TRUE;
+            }
+            params->qsf_ent = ent;
+            params->output_node = object_node;
+            ref = qof_class_get_referenceList(ent->e_type);
+            if (ref != NULL)
+            {
+                g_list_foreach(ref, reference_list_lookup, params);
+            }
+        }
+        if (0 == safe_strcmp(qof_param->param_type, QOF_TYPE_COLLECT))
+        {
+            qsf_coll = qof_param->param_getfcn(ent, qof_param);
+            if (qsf_coll)
+            {
+                params->qof_param = qof_param;
+                params->output_node = object_node;
+                if (qof_collection_count(qsf_coll) > 0)
+                {
+                    qof_collection_foreach(qsf_coll, qsf_from_coll_cb, params);
+                }
+            }
+            param_list = g_slist_next(param_list);
+            continue;
+        }
+        if (0 == safe_strcmp(qof_param->param_type, QOF_TYPE_CHOICE))
+        {
+            /** \todo use the reference list here. */
+            choice_ent = QOF_INSTANCE(qof_param->param_getfcn(ent, qof_param));
+            if (!choice_ent)
+            {
+                param_list = g_slist_next(param_list);
+                continue;
+            }
+            node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST qof_param->param_type));
+            cm_guid = qof_instance_get_guid(choice_ent);
+            guid_to_string_buff(cm_guid, cm_sa);
+            string_buffer = g_strdup(cm_sa);
+            xmlNodeAddContent(node, BAD_CAST string_buffer);
+            xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
+            xmlNewProp(node, BAD_CAST "name", BAD_CAST choice_ent->e_type);
+            g_free(string_buffer);
+            param_list = g_slist_next(param_list);
+            continue;
+        }
+        if (0 == safe_strcmp(qof_param->param_type, QOF_TYPE_KVP))
+        {
+            qsf_kvp = (KvpFrame*)qof_param->param_getfcn(ent, qof_param);
+            if (kvp_frame_is_empty(qsf_kvp))
+            {
+                LEAVE(" ");
+                return;
+            }
+            params->qof_param = qof_param;
+            params->output_node = object_node;
+            kvp_frame_for_each_slot(qsf_kvp, qsf_from_kvp_helper, params);
+        }
+        if ((qof_param->param_setfcn != NULL) && (qof_param->param_getfcn != NULL))
+        {
+            for ( supported = g_slist_copy(params->supported_types);
+                    supported != NULL; supported = g_slist_next(supported))
+            {
+                if (0 == safe_strcmp((const gchar*)supported->data, (const gchar*)qof_param->param_type))
+                {
+                    node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST qof_param->param_type));
+                    string_buffer = g_strdup(qof_book_merge_param_as_string(qof_param, ent));
+                    xmlNodeAddContent(node, BAD_CAST string_buffer);
+                    xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
+                    g_free(string_buffer);
+                }
+            }
+        }
+        param_list = g_slist_next(param_list);
+    }
 }
 
 static void
 qsf_foreach_obj_type(QofObject *qsf_obj, gpointer data)
 {
-	qsf_param *params;
-	QofBook *book;
-	GSList *support;
+    qsf_param *params;
+    QofBook *book;
+    GSList *support;
 
-	g_return_if_fail(data != NULL);
-	params = (qsf_param*) data;
-	/* Skip unsupported objects */
-	if((qsf_obj->create == NULL)||(qsf_obj->foreach == NULL)){
-		PINFO (" qsf_obj QOF support failed %s", qsf_obj->e_type);
-		return;
-	}
-	params->qof_obj_type = qsf_obj->e_type;
-	params->qsf_sequence = NULL;
-	book = params->book;
-	support = g_slist_copy(params->supported_types);
-	g_slist_foreach(support,qsf_supported_parameters, params);
-	qof_object_foreach(qsf_obj->e_type, book, qsf_entity_foreach, params);
+    g_return_if_fail(data != NULL);
+    params = (qsf_param*) data;
+    /* Skip unsupported objects */
+    if ((qsf_obj->create == NULL) || (qsf_obj->foreach == NULL))
+    {
+        PINFO (" qsf_obj QOF support failed %s", qsf_obj->e_type);
+        return;
+    }
+    params->qof_obj_type = qsf_obj->e_type;
+    params->qsf_sequence = NULL;
+    book = params->book;
+    support = g_slist_copy(params->supported_types);
+    g_slist_foreach(support, qsf_supported_parameters, params);
+    qof_object_foreach(qsf_obj->e_type, book, qsf_entity_foreach, params);
 }
 
 /*=====================================================
@@ -896,151 +1064,155 @@
 static xmlDocPtr
 qofbook_to_qsf(QofBook *book, qsf_param *params)
 {
-	xmlNodePtr top_node, node;
-	xmlDocPtr doc;
-	gchar buffer[GUID_ENCODING_LENGTH + 1];
-	const GUID *book_guid;
+    xmlNodePtr top_node, node;
+    xmlDocPtr doc;
+    gchar buffer[GUID_ENCODING_LENGTH + 1];
+    const GUID *book_guid;
 
-	g_return_val_if_fail(book != NULL, NULL);
-	params->book = book;
-	params->referenceList = 
-		g_list_copy((GList*)qof_book_get_data(book, ENTITYREFERENCE));
-	doc = xmlNewDoc(BAD_CAST QSF_XML_VERSION);
-	top_node = xmlNewNode(NULL, BAD_CAST QSF_ROOT_TAG);
-	xmlDocSetRootElement(doc, top_node);
-	xmlSetNs(top_node, xmlNewNs(top_node, BAD_CAST QSF_DEFAULT_NS, NULL));
-	params->qsf_ns = top_node->ns;
-	node = xmlNewChild(top_node, params->qsf_ns, BAD_CAST QSF_BOOK_TAG, NULL);
-	params->book_node = node;
-	xmlNewProp(node, BAD_CAST QSF_BOOK_COUNT, BAD_CAST "1");
-	book_guid = qof_book_get_guid(book);
-	guid_to_string_buff(book_guid, buffer);
-	xmlNewChild(params->book_node, params->qsf_ns, 
-		BAD_CAST QSF_BOOK_GUID, BAD_CAST buffer);
-	params->output_doc = doc;
-	params->book_node = node;
-	qof_object_foreach_type(qsf_foreach_obj_type, params);
-	return params->output_doc;
+    g_return_val_if_fail(book != NULL, NULL);
+    params->book = book;
+    params->referenceList =
+        g_list_copy((GList*)qof_book_get_data(book, ENTITYREFERENCE));
+    doc = xmlNewDoc(BAD_CAST QSF_XML_VERSION);
+    top_node = xmlNewNode(NULL, BAD_CAST QSF_ROOT_TAG);
+    xmlDocSetRootElement(doc, top_node);
+    xmlSetNs(top_node, xmlNewNs(top_node, BAD_CAST QSF_DEFAULT_NS, NULL));
+    params->qsf_ns = top_node->ns;
+    node = xmlNewChild(top_node, params->qsf_ns, BAD_CAST QSF_BOOK_TAG, NULL);
+    params->book_node = node;
+    xmlNewProp(node, BAD_CAST QSF_BOOK_COUNT, BAD_CAST "1");
+    book_guid = qof_book_get_guid(book);
+    guid_to_string_buff(book_guid, buffer);
+    xmlNewChild(params->book_node, params->qsf_ns,
+                BAD_CAST QSF_BOOK_GUID, BAD_CAST buffer);
+    params->output_doc = doc;
+    params->book_node = node;
+    qof_object_foreach_type(qsf_foreach_obj_type, params);
+    return params->output_doc;
 }
 
 static void
 write_qsf_from_book(const char *path, QofBook *book, qsf_param *params)
 {
-	xmlDocPtr qsf_doc;
-	gint write_result;
-	QofBackend *be;
+    xmlDocPtr qsf_doc;
+    gint write_result;
+    QofBackend *be;
 
-	be = qof_book_get_backend(book);
-	qsf_doc = qofbook_to_qsf(book, params);
-	write_result = 0;
-	DEBUG (" use_gz_level=%" G_GINT64_FORMAT " encoding=%s", 
-		params->use_gz_level, params->encoding);
-	if((params->use_gz_level > 0) && (params->use_gz_level <= 9)) 
-	{
-		xmlSetDocCompressMode(qsf_doc, params->use_gz_level); 
-	}
-	g_return_if_fail(qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, qsf_doc) == TRUE);
-	write_result = xmlSaveFormatFileEnc(path, qsf_doc, params->encoding, 1);
-	if(write_result < 0) 
-	{
-		qof_backend_set_error(be, ERR_FILEIO_WRITE_ERROR);
-		return;
-	}
-	xmlFreeDoc(qsf_doc);
+    be = qof_book_get_backend(book);
+    qsf_doc = qofbook_to_qsf(book, params);
+    write_result = 0;
+    DEBUG (" use_gz_level=%" G_GINT64_FORMAT " encoding=%s",
+           params->use_gz_level, params->encoding);
+    if ((params->use_gz_level > 0) && (params->use_gz_level <= 9))
+    {
+        xmlSetDocCompressMode(qsf_doc, params->use_gz_level);
+    }
+    g_return_if_fail(qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, qsf_doc) == TRUE);
+    write_result = xmlSaveFormatFileEnc(path, qsf_doc, params->encoding, 1);
+    if (write_result < 0)
+    {
+        qof_backend_set_error(be, ERR_FILEIO_WRITE_ERROR);
+        return;
+    }
+    xmlFreeDoc(qsf_doc);
 }
 
 static void
 write_qsf_to_stdout(QofBook *book, qsf_param *params)
 {
-	xmlDocPtr qsf_doc;
+    xmlDocPtr qsf_doc;
 
-	qsf_doc = qofbook_to_qsf(book, params);
-	g_return_if_fail(qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, qsf_doc) == TRUE);
-	DEBUG (" use_gz_level=%" G_GINT64_FORMAT " encoding=%s", 
-		params->use_gz_level, params->encoding);
-	xmlSaveFormatFileEnc("-", qsf_doc, params->encoding, 1);
-	fprintf(stdout, "\n");
-	xmlFreeDoc(qsf_doc);
+    qsf_doc = qofbook_to_qsf(book, params);
+    g_return_if_fail(qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, qsf_doc) == TRUE);
+    DEBUG (" use_gz_level=%" G_GINT64_FORMAT " encoding=%s",
+           params->use_gz_level, params->encoding);
+    xmlSaveFormatFileEnc("-", qsf_doc, params->encoding, 1);
+    fprintf(stdout, "\n");
+    xmlFreeDoc(qsf_doc);
 }
 
 static void
 qsf_write_file(QofBackend *be, QofBook *book)
 {
-	QSFBackend *qsf_be;
-	qsf_param *params;
-	char *path;
+    QSFBackend *qsf_be;
+    qsf_param *params;
+    char *path;
 
-	qsf_be = (QSFBackend*)be;
-	params = qsf_be->params;
-	/* if fullpath is blank, book_id was set to QOF_STDOUT */
-	if (!qsf_be->fullpath || (*qsf_be->fullpath == '\0')) {
-		write_qsf_to_stdout(book, params);
-		return;
-	}
-	path = strdup(qsf_be->fullpath);
-	write_qsf_from_book(path, book, params);
-	g_free(path);
+    qsf_be = (QSFBackend*)be;
+    params = qsf_be->params;
+    /* if fullpath is blank, book_id was set to QOF_STDOUT */
+    if (!qsf_be->fullpath || (*qsf_be->fullpath == '\0'))
+    {
+        write_qsf_to_stdout(book, params);
+        return;
+    }
+    path = strdup(qsf_be->fullpath);
+    write_qsf_from_book(path, book, params);
+    g_free(path);
 }
 
 KvpValue*
 string_to_kvp_value(const gchar *content, KvpValueType type)
 {
-	gchar        *tail;
-	gint64      cm_i64;
-	double      cm_double;
-	gnc_numeric cm_numeric;
-	GUID        *cm_guid;
-	struct tm   kvp_time;
-	time_t      kvp_time_t;
-	Timespec    cm_date;
+    gchar        *tail;
+    gint64      cm_i64;
+    double      cm_double;
+    gnc_numeric cm_numeric;
+    GUID        *cm_guid;
+    struct tm   kvp_time;
+    time_t      kvp_time_t;
+    Timespec    cm_date;
 
-	switch(type) {
-	  case KVP_TYPE_GINT64:
-		errno = 0;
-		cm_i64 = strtoll(content, &tail, 0);
-		if(errno == 0) {
-			return kvp_value_new_gint64(cm_i64);
-		}
-		break;
-	  case KVP_TYPE_DOUBLE:
-  		errno = 0;
-		cm_double = strtod(content, &tail);
-		if(errno == 0) {
-			return kvp_value_new_double(cm_double);
-		}
-		break;
-	  case KVP_TYPE_NUMERIC:
-		string_to_gnc_numeric(content, &cm_numeric);
-		return kvp_value_new_gnc_numeric(cm_numeric);
-		break;
-	  case KVP_TYPE_STRING:
-		return kvp_value_new_string(content);
-		break;
-	  case KVP_TYPE_GUID:
-		cm_guid = g_new(GUID, 1);
-		if(TRUE == string_to_guid(content, cm_guid))
-		{
-			return kvp_value_new_guid(cm_guid);
-		}
-		break;
-	  case KVP_TYPE_TIMESPEC:
-		strptime(content, QSF_XSD_TIME, &kvp_time);
-		kvp_time_t = mktime(&kvp_time);
-		timespecFromTime_t(&cm_date, kvp_time_t);
-		return kvp_value_new_timespec(cm_date);
-		break;
-	  case KVP_TYPE_BINARY:
+    switch (type)
+    {
+    case KVP_TYPE_GINT64:
+        errno = 0;
+        cm_i64 = strtoll(content, &tail, 0);
+        if (errno == 0)
+        {
+            return kvp_value_new_gint64(cm_i64);
+        }
+        break;
+    case KVP_TYPE_DOUBLE:
+        errno = 0;
+        cm_double = strtod(content, &tail);
+        if (errno == 0)
+        {
+            return kvp_value_new_double(cm_double);
+        }
+        break;
+    case KVP_TYPE_NUMERIC:
+        string_to_gnc_numeric(content, &cm_numeric);
+        return kvp_value_new_gnc_numeric(cm_numeric);
+        break;
+    case KVP_TYPE_STRING:
+        return kvp_value_new_string(content);
+        break;
+    case KVP_TYPE_GUID:
+        cm_guid = g_new(GUID, 1);
+        if (TRUE == string_to_guid(content, cm_guid))
+        {
+            return kvp_value_new_guid(cm_guid);
+        }
+        break;
+    case KVP_TYPE_TIMESPEC:
+        strptime(content, QSF_XSD_TIME, &kvp_time);
+        kvp_time_t = mktime(&kvp_time);
+        timespecFromTime_t(&cm_date, kvp_time_t);
+        return kvp_value_new_timespec(cm_date);
+        break;
+    case KVP_TYPE_BINARY:
 //		return kvp_value_new_binary(value->value.binary.data,
 //									value->value.binary.datasize);
-		break;
-	  case KVP_TYPE_GLIST:
+        break;
+    case KVP_TYPE_GLIST:
 //		return kvp_value_new_glist(value->value.list);
-		break;
-	  case KVP_TYPE_FRAME:
+        break;
+    case KVP_TYPE_FRAME:
 //		return kvp_value_new_frame(value->value.frame);
-		break;
-	}
-	return NULL;
+        break;
+    }
+    return NULL;
 }
 
 /* ======================================================
@@ -1049,217 +1221,273 @@
 void
 qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
 {
-	qsf_param          *params;
-	qsf_objects        *object_set;
-	xmlNodePtr         node;
-	QofInstanceReference *reference;
-	QofInstance          *qsf_ent;
-	QofBook            *targetBook;
-	const char         *qof_type, *parameter_name, *timechk;
-	QofIdType          obj_type, reference_type;
-	struct tm          qsf_time;
-	time_t             qsf_time_t;
-	gchar              *tail;
-	/* cm_ prefix used for variables that hold the data to commit */
-	gnc_numeric    cm_numeric;
-	double         cm_double;
-	gboolean       cm_boolean;
-	gint32         cm_i32;
-	gint64         cm_i64;
-	Timespec       cm_date;
-	gchar          *cm_char,  *(*char_getter)  (xmlNodePtr);
-	GUID           *cm_guid;
-	KvpFrame       *cm_kvp;
-	KvpValue       *cm_value;
-	KvpValueType   cm_type;
-	QofSetterFunc  cm_setter;
-	const QofParam *cm_param;
-	void (*string_setter)    (QofInstance*, const gchar*);
-	void (*date_setter)      (QofInstance*, Timespec);
-	void (*numeric_setter)   (QofInstance*, gnc_numeric);
-	void (*double_setter)    (QofInstance*, double);
-	void (*boolean_setter)   (QofInstance*, gboolean);
-	void (*i32_setter)       (QofInstance*, gint32);
-	void (*i64_setter)       (QofInstance*, gint64);
-	void (*char_setter)      (QofInstance*, gchar);
+    qsf_param          *params;
+    qsf_objects        *object_set;
+    xmlNodePtr         node;
+    QofInstanceReference *reference;
+    QofInstance          *qsf_ent;
+    QofBook            *targetBook;
+    const char         *qof_type, *parameter_name, *timechk;
+    QofIdType          obj_type, reference_type;
+    struct tm          qsf_time;
+    time_t             qsf_time_t;
+    gchar              *tail;
+    /* cm_ prefix used for variables that hold the data to commit */
+    gnc_numeric    cm_numeric;
+    double         cm_double;
+    gboolean       cm_boolean;
+    gint32         cm_i32;
+    gint64         cm_i64;
+    Timespec       cm_date;
+    gchar          *cm_char,  *(*char_getter)  (xmlNodePtr);
+    GUID           *cm_guid;
+    KvpFrame       *cm_kvp;
+    KvpValue       *cm_value;
+    KvpValueType   cm_type;
+    QofSetterFunc  cm_setter;
+    const QofParam *cm_param;
+    void (*string_setter)    (QofInstance*, const gchar*);
+    void (*date_setter)      (QofInstance*, Timespec);
+    void (*numeric_setter)   (QofInstance*, gnc_numeric);
+    void (*double_setter)    (QofInstance*, double);
+    void (*boolean_setter)   (QofInstance*, gboolean);
+    void (*i32_setter)       (QofInstance*, gint32);
+    void (*i64_setter)       (QofInstance*, gint64);
+    void (*char_setter)      (QofInstance*, gchar);
 
-	g_return_if_fail(data && value && key);
-	params = (qsf_param*)data;
-	node = (xmlNodePtr)value;
-	parameter_name = (const gchar*)key;
-	qof_type = (gchar*)node->name;
-	qsf_ent = params->qsf_ent;
-	targetBook = params->book;
-	memset (&qsf_time, '\0', sizeof(qsf_time));
-	cm_date.tv_nsec = 0;
-	cm_date.tv_sec = 0;
-	obj_type = (gchar*)xmlGetProp(node->parent, BAD_CAST QSF_OBJECT_TYPE);
-	if(0 == safe_strcasecmp(obj_type, parameter_name)) { return; }
-	cm_setter = qof_class_get_parameter_setter(obj_type, parameter_name);
-	cm_param = qof_class_get_parameter(obj_type, parameter_name);
-	object_set = params->object_set;
-	if(safe_strcmp(qof_type, QOF_TYPE_STRING) == 0)  {
-		string_setter = (void(*)(QofInstance*, const gchar*))cm_setter;
-		if(string_setter != NULL) { string_setter(qsf_ent, (gchar*)xmlNodeGetContent(node)); }
-	}
-	if(safe_strcmp(qof_type, QOF_TYPE_DATE) == 0) {
-		date_setter = (void(*)(QofInstance*, Timespec))cm_setter;
-		timechk = NULL;
-		timechk = strptime((char*)xmlNodeGetContent(node), QSF_XSD_TIME, &qsf_time);
-		g_return_if_fail(timechk != NULL);
-		qsf_time_t = mktime(&qsf_time);
-		if(qsf_time_t != -3600)
-		{
-			timespecFromTime_t(&cm_date, qsf_time_t);
-			if(date_setter != NULL) { date_setter(qsf_ent, cm_date); }
-		}
-	}
-	if((safe_strcmp(qof_type, QOF_TYPE_NUMERIC) == 0)  ||
-	(safe_strcmp(qof_type, QOF_TYPE_DEBCRED) == 0)) {
-		numeric_setter = (void(*)(QofInstance*, gnc_numeric))cm_setter;
-		string_to_gnc_numeric((char*)xmlNodeGetContent(node), &cm_numeric);
-		if(numeric_setter != NULL) { numeric_setter(qsf_ent, cm_numeric); }
-	}
-	if(safe_strcmp(qof_type, QOF_TYPE_GUID) == 0) {
-		cm_guid = g_new(GUID, 1);
-		if(TRUE != string_to_guid((char*)xmlNodeGetContent(node), cm_guid))
-		{
-			qof_backend_set_error(params->be, ERR_QSF_BAD_OBJ_GUID);
-			PINFO (" string to guid conversion failed for %s:%s:%s",
-				xmlNodeGetContent(node), obj_type, qof_type);
-			return;
-		}
-		reference_type = (char*)xmlGetProp(node, BAD_CAST QSF_OBJECT_TYPE);
-		if(0 == safe_strcmp(QOF_PARAM_GUID, reference_type))
-		{
-			qof_instance_set_guid(qsf_ent, cm_guid);
-		}
-		else {
-			reference = qof_instance_get_reference_from(qsf_ent, cm_param);
-			if(reference) {
-				params->referenceList = g_list_append(params->referenceList, reference);
-			}
-		}
-	}
-	if(safe_strcmp(qof_type, QOF_TYPE_INT32) == 0) {
-		errno = 0;
-		cm_i32 = (gint32)strtol ((char*)xmlNodeGetContent(node), &tail, 0);
-		if(errno == 0) {
-			i32_setter = (void(*)(QofInstance*, gint32))cm_setter;
-			if(i32_setter != NULL) { i32_setter(qsf_ent, cm_i32); }
-		}
-		else { qof_backend_set_error(params->be, ERR_QSF_OVERFLOW); }
-	}
-	if(safe_strcmp(qof_type, QOF_TYPE_INT64) == 0) {
-		errno = 0;
-		cm_i64 = strtoll((gchar*)xmlNodeGetContent(node), &tail, 0);
-		if(errno == 0) {
-			i64_setter = (void(*)(QofInstance*, gint64))cm_setter;
-			if(i64_setter != NULL) { i64_setter(qsf_ent, cm_i64); }
-		}
-		else { qof_backend_set_error(params->be, ERR_QSF_OVERFLOW); }
-	}
-	if(safe_strcmp(qof_type, QOF_TYPE_DOUBLE) == 0) {
-		errno = 0;
-		cm_double = strtod((gchar*)xmlNodeGetContent(node), &tail);
-		if(errno == 0) {
-			double_setter = (void(*)(QofInstance*, double))cm_setter;
-			if(double_setter != NULL) { double_setter(qsf_ent, cm_double); }
-		}
-	}
-	if(safe_strcmp(qof_type, QOF_TYPE_BOOLEAN) == 0){
-		if(0 == safe_strcasecmp((gchar*)xmlNodeGetContent(node), 
-				QSF_XML_BOOLEAN_TEST)) {
-			cm_boolean = TRUE;
-		}
-		else { cm_boolean = FALSE; }
-		boolean_setter = (void(*)(QofInstance*, gboolean))cm_setter;
-		if(boolean_setter != NULL) { boolean_setter(qsf_ent, cm_boolean); }
-	}
-	if(safe_strcmp(qof_type, QOF_TYPE_KVP) == 0) {
-		cm_type = qsf_to_kvp_helper((gchar*)xmlGetProp(node, BAD_CAST QSF_OBJECT_VALUE));
-		if(!cm_type) { return; }
-		cm_value = string_to_kvp_value((gchar*)xmlNodeGetContent(node), cm_type);
-		cm_kvp = (KvpFrame*)cm_param->param_getfcn(qsf_ent, cm_param);
-		cm_kvp = kvp_frame_set_value(cm_kvp, (gchar*)xmlGetProp(node, 
-			BAD_CAST QSF_OBJECT_KVP), cm_value);
-	}
-	if(safe_strcmp(qof_type, QOF_TYPE_COLLECT) == 0) {
-		QofCollection *qsf_coll;
-		QofIdType type;
-		QofInstanceReference *reference;
-		QofParam *copy_param;
-		/* retrieve the *type* of the collection, ignore any contents. */
-		qsf_coll = cm_param->param_getfcn(qsf_ent, cm_param);
-		type = qof_collection_get_type(qsf_coll);
-		cm_guid = g_new(GUID, 1);
-		if(TRUE != string_to_guid((gchar*)xmlNodeGetContent(node), cm_guid))
-		{
-			qof_backend_set_error(params->be, ERR_QSF_BAD_OBJ_GUID);
-			PINFO (" string to guid collect failed for %s", xmlNodeGetContent(node));
-			return;
-		}
-		/* create a QofInstanceReference with this type and GUID.
-		 there is only one entity each time.
-		 cm_guid contains the GUID of the reference.
-		 type is the type of the reference. */
-		reference = g_new0(QofInstanceReference, 1);
-		reference->type = g_strdup(qsf_ent->e_type);
-		reference->ref_guid = cm_guid;
-		reference->ent_guid = qof_instance_get_guid(qsf_ent);
-		copy_param = g_new0(QofParam, 1);
-		copy_param->param_name = g_strdup(cm_param->param_name);
-		copy_param->param_type = g_strdup(cm_param->param_type);
-		reference->param = copy_param;
-		params->referenceList = g_list_append(params->referenceList, reference);
-	}
-	if(safe_strcmp(qof_type, QOF_TYPE_CHAR) == 0) {
-		char_getter = (gchar * (*)(xmlNodePtr))xmlNodeGetContent;
-		cm_char = char_getter(node);
-		char_setter = (void(*)(QofInstance*, gchar))cm_setter;
-		if(char_setter != NULL) { char_setter(qsf_ent, *cm_char); }
-		xmlFree(cm_char);
-	}
+    g_return_if_fail(data && value && key);
+    params = (qsf_param*)data;
+    node = (xmlNodePtr)value;
+    parameter_name = (const gchar*)key;
+    qof_type = (gchar*)node->name;
+    qsf_ent = params->qsf_ent;
+    targetBook = params->book;
+    memset (&qsf_time, '\0', sizeof(qsf_time));
+    cm_date.tv_nsec = 0;
+    cm_date.tv_sec = 0;
+    obj_type = (gchar*)xmlGetProp(node->parent, BAD_CAST QSF_OBJECT_TYPE);
+    if (0 == safe_strcasecmp(obj_type, parameter_name))
+    {
+        return;
+    }
+    cm_setter = qof_class_get_parameter_setter(obj_type, parameter_name);
+    cm_param = qof_class_get_parameter(obj_type, parameter_name);
+    object_set = params->object_set;
+    if (safe_strcmp(qof_type, QOF_TYPE_STRING) == 0)
+    {
+        string_setter = (void(*)(QofInstance*, const gchar*))cm_setter;
+        if (string_setter != NULL)
+        {
+            string_setter(qsf_ent, (gchar*)xmlNodeGetContent(node));
+        }
+    }
+    if (safe_strcmp(qof_type, QOF_TYPE_DATE) == 0)
+    {
+        date_setter = (void(*)(QofInstance*, Timespec))cm_setter;
+        timechk = NULL;
+        timechk = strptime((char*)xmlNodeGetContent(node), QSF_XSD_TIME, &qsf_time);
+        g_return_if_fail(timechk != NULL);
+        qsf_time_t = mktime(&qsf_time);
+        if (qsf_time_t != -3600)
+        {
+            timespecFromTime_t(&cm_date, qsf_time_t);
+            if (date_setter != NULL)
+            {
+                date_setter(qsf_ent, cm_date);
+            }
+        }
+    }
+    if ((safe_strcmp(qof_type, QOF_TYPE_NUMERIC) == 0)  ||
+            (safe_strcmp(qof_type, QOF_TYPE_DEBCRED) == 0))
+    {
+        numeric_setter = (void(*)(QofInstance*, gnc_numeric))cm_setter;
+        string_to_gnc_numeric((char*)xmlNodeGetContent(node), &cm_numeric);
+        if (numeric_setter != NULL)
+        {
+            numeric_setter(qsf_ent, cm_numeric);
+        }
+    }
+    if (safe_strcmp(qof_type, QOF_TYPE_GUID) == 0)
+    {
+        cm_guid = g_new(GUID, 1);
+        if (TRUE != string_to_guid((char*)xmlNodeGetContent(node), cm_guid))
+        {
+            qof_backend_set_error(params->be, ERR_QSF_BAD_OBJ_GUID);
+            PINFO (" string to guid conversion failed for %s:%s:%s",
+                   xmlNodeGetContent(node), obj_type, qof_type);
+            return;
+        }
+        reference_type = (char*)xmlGetProp(node, BAD_CAST QSF_OBJECT_TYPE);
+        if (0 == safe_strcmp(QOF_PARAM_GUID, reference_type))
+        {
+            qof_instance_set_guid(qsf_ent, cm_guid);
+        }
+        else
+        {
+            reference = qof_instance_get_reference_from(qsf_ent, cm_param);
+            if (reference)
+            {
+                params->referenceList = g_list_append(params->referenceList, reference);
+            }
+        }
+    }
+    if (safe_strcmp(qof_type, QOF_TYPE_INT32) == 0)
+    {
+        errno = 0;
+        cm_i32 = (gint32)strtol ((char*)xmlNodeGetContent(node), &tail, 0);
+        if (errno == 0)
+        {
+            i32_setter = (void(*)(QofInstance*, gint32))cm_setter;
+            if (i32_setter != NULL)
+            {
+                i32_setter(qsf_ent, cm_i32);
+            }
+        }
+        else
+        {
+            qof_backend_set_error(params->be, ERR_QSF_OVERFLOW);
+        }
+    }
+    if (safe_strcmp(qof_type, QOF_TYPE_INT64) == 0)
+    {
+        errno = 0;
+        cm_i64 = strtoll((gchar*)xmlNodeGetContent(node), &tail, 0);
+        if (errno == 0)
+        {
+            i64_setter = (void(*)(QofInstance*, gint64))cm_setter;
+            if (i64_setter != NULL)
+            {
+                i64_setter(qsf_ent, cm_i64);
+            }
+        }
+        else
+        {
+            qof_backend_set_error(params->be, ERR_QSF_OVERFLOW);
+        }
+    }
+    if (safe_strcmp(qof_type, QOF_TYPE_DOUBLE) == 0)
+    {
+        errno = 0;
+        cm_double = strtod((gchar*)xmlNodeGetContent(node), &tail);
+        if (errno == 0)
+        {
+            double_setter = (void(*)(QofInstance*, double))cm_setter;
+            if (double_setter != NULL)
+            {
+                double_setter(qsf_ent, cm_double);
+            }
+        }
+    }
+    if (safe_strcmp(qof_type, QOF_TYPE_BOOLEAN) == 0)
+    {
+        if (0 == safe_strcasecmp((gchar*)xmlNodeGetContent(node),
+                                 QSF_XML_BOOLEAN_TEST))
+        {
+            cm_boolean = TRUE;
+        }
+        else
+        {
+            cm_boolean = FALSE;
+        }
+        boolean_setter = (void(*)(QofInstance*, gboolean))cm_setter;
+        if (boolean_setter != NULL)
+        {
+            boolean_setter(qsf_ent, cm_boolean);
+        }
+    }
+    if (safe_strcmp(qof_type, QOF_TYPE_KVP) == 0)
+    {
+        cm_type = qsf_to_kvp_helper((gchar*)xmlGetProp(node, BAD_CAST QSF_OBJECT_VALUE));
+        if (!cm_type)
+        {
+            return;
+        }
+        cm_value = string_to_kvp_value((gchar*)xmlNodeGetContent(node), cm_type);
+        cm_kvp = (KvpFrame*)cm_param->param_getfcn(qsf_ent, cm_param);
+        cm_kvp = kvp_frame_set_value(cm_kvp, (gchar*)xmlGetProp(node,
+                                     BAD_CAST QSF_OBJECT_KVP), cm_value);
+    }
+    if (safe_strcmp(qof_type, QOF_TYPE_COLLECT) == 0)
+    {
+        QofCollection *qsf_coll;
+        QofIdType type;
+        QofInstanceReference *reference;
+        QofParam *copy_param;
+        /* retrieve the *type* of the collection, ignore any contents. */
+        qsf_coll = cm_param->param_getfcn(qsf_ent, cm_param);
+        type = qof_collection_get_type(qsf_coll);
+        cm_guid = g_new(GUID, 1);
+        if (TRUE != string_to_guid((gchar*)xmlNodeGetContent(node), cm_guid))
+        {
+            qof_backend_set_error(params->be, ERR_QSF_BAD_OBJ_GUID);
+            PINFO (" string to guid collect failed for %s", xmlNodeGetContent(node));
+            return;
+        }
+        /* create a QofInstanceReference with this type and GUID.
+         there is only one entity each time.
+         cm_guid contains the GUID of the reference.
+         type is the type of the reference. */
+        reference = g_new0(QofInstanceReference, 1);
+        reference->type = g_strdup(qsf_ent->e_type);
+        reference->ref_guid = cm_guid;
+        reference->ent_guid = qof_instance_get_guid(qsf_ent);
+        copy_param = g_new0(QofParam, 1);
+        copy_param->param_name = g_strdup(cm_param->param_name);
+        copy_param->param_type = g_strdup(cm_param->param_type);
+        reference->param = copy_param;
+        params->referenceList = g_list_append(params->referenceList, reference);
+    }
+    if (safe_strcmp(qof_type, QOF_TYPE_CHAR) == 0)
+    {
+        char_getter = (gchar * (*)(xmlNodePtr))xmlNodeGetContent;
+        cm_char = char_getter(node);
+        char_setter = (void(*)(QofInstance*, gchar))cm_setter;
+        if (char_setter != NULL)
+        {
+            char_setter(qsf_ent, *cm_char);
+        }
+        xmlFree(cm_char);
+    }
 }
 
 static QofBackend*
 qsf_backend_new(void)
 {
-	QSFBackend *qsf_be;
-	QofBackend *be;
+    QSFBackend *qsf_be;
+    QofBackend *be;
 
-	qsf_be = g_new0(QSFBackend, 1);
-	be = (QofBackend*) qsf_be;
-	qof_backend_init(be);
-	qsf_be->params = g_new(qsf_param, 1);
-	qsf_be->params->be = be;
-	qsf_param_init(qsf_be->params);
-	qsf_be->be.session_begin = qsf_session_begin;
+    qsf_be = g_new0(QSFBackend, 1);
+    be = (QofBackend*) qsf_be;
+    qof_backend_init(be);
+    qsf_be->params = g_new(qsf_param, 1);
+    qsf_be->params->be = be;
+    qsf_param_init(qsf_be->params);
+    qsf_be->be.session_begin = qsf_session_begin;
 
-	be->session_end = qsf_session_end;
-	be->destroy_backend = qsf_destroy_backend;
-	be->load = qsf_file_type;
-	be->save_may_clobber_data = NULL;
-	/* The QSF backend will always load and save the entire QSF XML file. */
-	be->begin = NULL;
-	be->commit = NULL;
-	be->rollback = NULL;
-	/* QSF uses the built-in SQL, not a dedicated SQL server. */
-	be->compile_query = NULL;
-	be->free_query = NULL;
-	be->run_query = NULL;
-	be->counter = NULL;
-	/* The QSF backend is not multi-user. */
-	be->events_pending = NULL;
-	be->process_events = NULL;
+    be->session_end = qsf_session_end;
+    be->destroy_backend = qsf_destroy_backend;
+    be->load = qsf_file_type;
+    be->save_may_clobber_data = NULL;
+    /* The QSF backend will always load and save the entire QSF XML file. */
+    be->begin = NULL;
+    be->commit = NULL;
+    be->rollback = NULL;
+    /* QSF uses the built-in SQL, not a dedicated SQL server. */
+    be->compile_query = NULL;
+    be->free_query = NULL;
+    be->run_query = NULL;
+    be->counter = NULL;
+    /* The QSF backend is not multi-user. */
+    be->events_pending = NULL;
+    be->process_events = NULL;
 
-	be->sync = qsf_write_file;
-	/* use for maps, later. */
-	be->load_config = qsf_load_config;
-	be->get_config = qsf_get_config;
+    be->sync = qsf_write_file;
+    /* use for maps, later. */
+    be->load_config = qsf_load_config;
+    be->get_config = qsf_get_config;
 
-	qsf_be->fullpath = NULL;
-	return be;
+    qsf_be->fullpath = NULL;
+    return be;
 }
 
 /* The QOF method of loading each backend.
@@ -1268,31 +1496,31 @@
 static void
 qsf_provider_free (QofBackendProvider *prov)
 {
-	prov->provider_name = NULL;
-	prov->access_method = NULL;
-	g_free (prov);
+    prov->provider_name = NULL;
+    prov->access_method = NULL;
+    g_free (prov);
 }
 
 G_MODULE_EXPORT void
 qof_backend_module_init (void)
 {
-	QofBackendProvider *prov;
+    QofBackendProvider *prov;
 
-	prov = g_new0 (QofBackendProvider, 1);
-	prov->provider_name = "QSF Backend Version 0.2";
-	prov->access_method = "file";
-	prov->partial_book_supported = TRUE;
-	prov->backend_new = qsf_backend_new;
-	prov->check_data_type = qsf_determine_file_type;
-	prov->provider_free = qsf_provider_free;
-	qof_backend_register_provider (prov);
+    prov = g_new0 (QofBackendProvider, 1);
+    prov->provider_name = "QSF Backend Version 0.2";
+    prov->access_method = "file";
+    prov->partial_book_supported = TRUE;
+    prov->backend_new = qsf_backend_new;
+    prov->check_data_type = qsf_determine_file_type;
+    prov->provider_free = qsf_provider_free;
+    qof_backend_register_provider (prov);
 
-	prov = g_new0 (QofBackendProvider, 1);
-	prov->provider_name = "QSF Backend Version 0.2";
-	prov->access_method = "qsf";
-	prov->partial_book_supported = TRUE;
-	prov->backend_new = qsf_backend_new;
-	prov->check_data_type = qsf_determine_file_type;
-	prov->provider_free = qsf_provider_free;
-	qof_backend_register_provider (prov);
+    prov = g_new0 (QofBackendProvider, 1);
+    prov->provider_name = "QSF Backend Version 0.2";
+    prov->access_method = "qsf";
+    prov->partial_book_supported = TRUE;
+    prov->backend_new = qsf_backend_new;
+    prov->check_data_type = qsf_determine_file_type;
+    prov->provider_free = qsf_provider_free;
+    qof_backend_register_provider (prov);
 }

Modified: gnucash/trunk/src/libqof/backend/file/qsf-xml-map.c
===================================================================
--- gnucash/trunk/src/libqof/backend/file/qsf-xml-map.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/libqof/backend/file/qsf-xml-map.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -41,402 +41,446 @@
 
 static void
 qsf_date_default_handler(const gchar *default_name, GHashTable *qsf_default_hash,
-	xmlNodePtr parent_tag, xmlNodePtr import_node, xmlNsPtr ns)
+                         xmlNodePtr parent_tag, xmlNodePtr import_node, xmlNsPtr ns)
 {
-	xmlNodePtr output_parent;
-	time_t *qsf_time;
-	gchar date_as_string[QSF_DATE_LENGTH];
+    xmlNodePtr output_parent;
+    time_t *qsf_time;
+    gchar date_as_string[QSF_DATE_LENGTH];
 
-	output_parent = xmlAddChild(parent_tag, xmlNewNode(ns,
-		xmlGetProp(import_node, BAD_CAST QSF_OBJECT_TYPE)));
-	xmlNewProp(output_parent, BAD_CAST QSF_OBJECT_TYPE,
-		xmlGetProp(import_node, BAD_CAST MAP_VALUE_ATTR));
-	qsf_time = (time_t*)g_hash_table_lookup(qsf_default_hash, default_name);
-	qof_strftime(date_as_string, QSF_DATE_LENGTH, QSF_XSD_TIME, gmtime(qsf_time));
-	xmlNodeAddContent(output_parent, BAD_CAST date_as_string);
+    output_parent = xmlAddChild(parent_tag, xmlNewNode(ns,
+                                xmlGetProp(import_node, BAD_CAST QSF_OBJECT_TYPE)));
+    xmlNewProp(output_parent, BAD_CAST QSF_OBJECT_TYPE,
+               xmlGetProp(import_node, BAD_CAST MAP_VALUE_ATTR));
+    qsf_time = (time_t*)g_hash_table_lookup(qsf_default_hash, default_name);
+    qof_strftime(date_as_string, QSF_DATE_LENGTH, QSF_XSD_TIME, gmtime(qsf_time));
+    xmlNodeAddContent(output_parent, BAD_CAST date_as_string);
 }
 
 static void
 qsf_string_default_handler(const gchar *default_name, GHashTable *qsf_default_hash,
-	xmlNodePtr parent_tag, xmlNodePtr import_node, xmlNsPtr ns)
+                           xmlNodePtr parent_tag, xmlNodePtr import_node, xmlNsPtr ns)
 {
-	xmlNodePtr node;
-	xmlChar *output;
+    xmlNodePtr node;
+    xmlChar *output;
 
-	node = xmlAddChild(parent_tag,
-		xmlNewNode(ns, xmlGetProp(import_node, BAD_CAST QSF_OBJECT_TYPE)));
-	xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE,
-		xmlGetProp(import_node, BAD_CAST MAP_VALUE_ATTR));
-	output = (xmlChar *)g_hash_table_lookup(qsf_default_hash, default_name);
-	xmlNodeAddContent(node, output);
+    node = xmlAddChild(parent_tag,
+                       xmlNewNode(ns, xmlGetProp(import_node, BAD_CAST QSF_OBJECT_TYPE)));
+    xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE,
+               xmlGetProp(import_node, BAD_CAST MAP_VALUE_ATTR));
+    output = (xmlChar *)g_hash_table_lookup(qsf_default_hash, default_name);
+    xmlNodeAddContent(node, output);
 }
 
 static void
 qsf_map_validation_handler(xmlNodePtr child, xmlNsPtr ns, qsf_validator *valid)
 {
-	xmlChar *qof_version, *match;
-	GString *buff;
-	xmlNodePtr child_node;
-	xmlChar *obj_type;
+    xmlChar *qof_version, *match;
+    GString *buff;
+    xmlNodePtr child_node;
+    xmlChar *obj_type;
 
-	if (qsf_is_element(child, ns, MAP_DEFINITION_TAG)) {
-		qof_version = xmlGetProp(child, BAD_CAST MAP_QOF_VERSION);
-		buff = g_string_new(" ");
-		g_string_printf(buff, "%i", QSF_QOF_VERSION);
-		if(xmlStrcmp(qof_version, BAD_CAST buff->str) != 0)
-		{
-			valid->error_state = ERR_QSF_BAD_QOF_VERSION;
-			return;
-		}
-		for(child_node = child->children; child_node != NULL;
-			child_node = child_node->next)
-		{
-			if (qsf_is_element(child_node, ns, MAP_DEFINE_TAG)) {
-				g_hash_table_insert(valid->validation_table,
-					xmlGetProp(child_node, BAD_CAST MAP_E_TYPE),
-					xmlNodeGetContent(child_node));
-			}
-		}
-	}
-	if(qsf_is_element(child, ns, MAP_OBJECT_TAG)) {
-		match = NULL;
-		obj_type = xmlGetProp(child, BAD_CAST MAP_TYPE_ATTR);
-		match = BAD_CAST g_hash_table_lookup( valid->validation_table, obj_type);
-		if(match) {
-			valid->map_calculated_count++;
-			if(TRUE == qof_class_is_registered((QofIdTypeConst) obj_type))
-			{
-				valid->qof_registered_count++;
-				PINFO (" %s is to be calculated", obj_type);
-			}
-			else { PINFO (" %s to be mapped", obj_type); }
-		}
-	}
+    if (qsf_is_element(child, ns, MAP_DEFINITION_TAG))
+    {
+        qof_version = xmlGetProp(child, BAD_CAST MAP_QOF_VERSION);
+        buff = g_string_new(" ");
+        g_string_printf(buff, "%i", QSF_QOF_VERSION);
+        if (xmlStrcmp(qof_version, BAD_CAST buff->str) != 0)
+        {
+            valid->error_state = ERR_QSF_BAD_QOF_VERSION;
+            return;
+        }
+        for (child_node = child->children; child_node != NULL;
+                child_node = child_node->next)
+        {
+            if (qsf_is_element(child_node, ns, MAP_DEFINE_TAG))
+            {
+                g_hash_table_insert(valid->validation_table,
+                                    xmlGetProp(child_node, BAD_CAST MAP_E_TYPE),
+                                    xmlNodeGetContent(child_node));
+            }
+        }
+    }
+    if (qsf_is_element(child, ns, MAP_OBJECT_TAG))
+    {
+        match = NULL;
+        obj_type = xmlGetProp(child, BAD_CAST MAP_TYPE_ATTR);
+        match = BAD_CAST g_hash_table_lookup( valid->validation_table, obj_type);
+        if (match)
+        {
+            valid->map_calculated_count++;
+            if (TRUE == qof_class_is_registered((QofIdTypeConst) obj_type))
+            {
+                valid->qof_registered_count++;
+                PINFO (" %s is to be calculated", obj_type);
+            }
+            else
+            {
+                PINFO (" %s to be mapped", obj_type);
+            }
+        }
+    }
 }
 
 gboolean is_qsf_object_with_map_be(gchar *map_file, qsf_param *params)
 {
-	xmlDocPtr doc, map_doc;
-	gint valid_count, calc_count;
-	struct qsf_node_iterate iter;
-	xmlNodePtr map_root, object_root;
-	xmlNsPtr map_ns;
-	qsf_validator valid;
-	gchar *path;
-	gchar *map_path;
+    xmlDocPtr doc, map_doc;
+    gint valid_count, calc_count;
+    struct qsf_node_iterate iter;
+    xmlNodePtr map_root, object_root;
+    xmlNsPtr map_ns;
+    qsf_validator valid;
+    gchar *path;
+    gchar *map_path;
 
-	g_return_val_if_fail((params != NULL),FALSE);
-	PINFO (" mapfile=%s", map_file);
-	path = g_strdup(params->filepath);
-	map_path = g_strdup_printf("%s/%s", QSF_SCHEMA_DIR, map_file);
-	if(path == NULL) {
-		qof_backend_set_error(params->be, ERR_FILEIO_FILE_NOT_FOUND);
-		return FALSE;
-	}
-	doc = xmlParseFile(path);
-	if(doc == NULL) {
-		qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
-		return FALSE;
-	}
-	if(TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc)) {
-		qof_backend_set_error(params->be, ERR_QSF_INVALID_OBJ);
-		return FALSE;
-	}
-	object_root = xmlDocGetRootElement(doc);
-	if(map_path == NULL) {
-		qof_backend_set_error(params->be, ERR_FILEIO_FILE_NOT_FOUND);
-		return FALSE;
-	}
-	valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
-	map_doc = xmlParseFile(map_path);
-	if(map_doc == NULL) {
-		qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
-		return FALSE;
-	}
-	if(TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_MAP_SCHEMA, map_doc)) {
-		qof_backend_set_error(params->be, ERR_QSF_INVALID_MAP);
-		return FALSE;
-	}
-	map_root = xmlDocGetRootElement(map_doc);
-	valid.map_calculated_count = 0;
-	valid.valid_object_count = 0;
-	valid.qof_registered_count = 0;
-	valid.error_state = ERR_BACKEND_NO_ERR;
-	map_ns = map_root->ns;
-	iter.ns = object_root->ns;
-	qsf_valid_foreach(object_root, qsf_object_validation_handler, &iter, &valid);
-	iter.ns = map_ns;
-	qsf_valid_foreach(map_root, qsf_map_validation_handler, &iter, &valid);
-	if (valid.error_state != ERR_BACKEND_NO_ERR) {
-		qof_backend_set_error(params->be, valid.error_state);
-		g_hash_table_destroy(valid.validation_table);
-		return FALSE;
-	}
-	/* check all counted objects are valid */
-	/* Should be: 
-	the same number of valid object calculations as there are defined in the map.
-	And the number of calculations must match the number of unregistered
-	objects plus the number of registered objects defined. */
-	valid_count = g_hash_table_size(valid.validation_table) - valid.map_calculated_count;
-	calc_count  = valid.map_calculated_count - 
-        (valid.valid_object_count + valid.qof_registered_count);
-	if(valid_count == 0 && calc_count == 0) {
+    g_return_val_if_fail((params != NULL), FALSE);
+    PINFO (" mapfile=%s", map_file);
+    path = g_strdup(params->filepath);
+    map_path = g_strdup_printf("%s/%s", QSF_SCHEMA_DIR, map_file);
+    if (path == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_FILE_NOT_FOUND);
+        return FALSE;
+    }
+    doc = xmlParseFile(path);
+    if (doc == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
+        return FALSE;
+    }
+    if (TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc))
+    {
+        qof_backend_set_error(params->be, ERR_QSF_INVALID_OBJ);
+        return FALSE;
+    }
+    object_root = xmlDocGetRootElement(doc);
+    if (map_path == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_FILE_NOT_FOUND);
+        return FALSE;
+    }
+    valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
+    map_doc = xmlParseFile(map_path);
+    if (map_doc == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
+        return FALSE;
+    }
+    if (TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_MAP_SCHEMA, map_doc))
+    {
+        qof_backend_set_error(params->be, ERR_QSF_INVALID_MAP);
+        return FALSE;
+    }
+    map_root = xmlDocGetRootElement(map_doc);
+    valid.map_calculated_count = 0;
+    valid.valid_object_count = 0;
+    valid.qof_registered_count = 0;
+    valid.error_state = ERR_BACKEND_NO_ERR;
+    map_ns = map_root->ns;
+    iter.ns = object_root->ns;
+    qsf_valid_foreach(object_root, qsf_object_validation_handler, &iter, &valid);
+    iter.ns = map_ns;
+    qsf_valid_foreach(map_root, qsf_map_validation_handler, &iter, &valid);
+    if (valid.error_state != ERR_BACKEND_NO_ERR)
+    {
+        qof_backend_set_error(params->be, valid.error_state);
         g_hash_table_destroy(valid.validation_table);
-		qof_backend_get_error(params->be);
-		return TRUE;
-	}
-	qof_backend_set_error(params->be, ERR_QSF_WRONG_MAP);
-	/* the object is OK, only the map is wrong. */
-	PINFO (" Map is wrong. map:%d object:%d reg:%d size:%d result:%d",
-        valid.map_calculated_count, valid.valid_object_count, 
-        valid.qof_registered_count,
-        g_hash_table_size(valid.validation_table), valid_count);
-	if(valid_count != 0) {
-		PINFO (" size - map != 0. actual: %d.", valid_count);
-	}
-		if(calc_count != 0) {
-		PINFO (" map - (object + registered) != 0. Actual: %d.", calc_count);
-	}
-	g_hash_table_destroy(valid.validation_table);
-	return TRUE;
+        return FALSE;
+    }
+    /* check all counted objects are valid */
+    /* Should be:
+    the same number of valid object calculations as there are defined in the map.
+    And the number of calculations must match the number of unregistered
+    objects plus the number of registered objects defined. */
+    valid_count = g_hash_table_size(valid.validation_table) - valid.map_calculated_count;
+    calc_count  = valid.map_calculated_count -
+                  (valid.valid_object_count + valid.qof_registered_count);
+    if (valid_count == 0 && calc_count == 0)
+    {
+        g_hash_table_destroy(valid.validation_table);
+        qof_backend_get_error(params->be);
+        return TRUE;
+    }
+    qof_backend_set_error(params->be, ERR_QSF_WRONG_MAP);
+    /* the object is OK, only the map is wrong. */
+    PINFO (" Map is wrong. map:%d object:%d reg:%d size:%d result:%d",
+           valid.map_calculated_count, valid.valid_object_count,
+           valid.qof_registered_count,
+           g_hash_table_size(valid.validation_table), valid_count);
+    if (valid_count != 0)
+    {
+        PINFO (" size - map != 0. actual: %d.", valid_count);
+    }
+    if (calc_count != 0)
+    {
+        PINFO (" map - (object + registered) != 0. Actual: %d.", calc_count);
+    }
+    g_hash_table_destroy(valid.validation_table);
+    return TRUE;
 }
 
 gboolean is_qsf_object_with_map(const gchar *path, gchar *map_file)
 {
-	xmlDocPtr doc, map_doc;
-	gint valid_count;
-	struct qsf_node_iterate iter;
-	xmlNodePtr map_root, object_root;
-	xmlNsPtr map_ns;
-	qsf_validator valid;
-	gchar *map_path;
+    xmlDocPtr doc, map_doc;
+    gint valid_count;
+    struct qsf_node_iterate iter;
+    xmlNodePtr map_root, object_root;
+    xmlNsPtr map_ns;
+    qsf_validator valid;
+    gchar *map_path;
 
-	map_path = g_strdup_printf("%s/%s", QSF_SCHEMA_DIR, map_file);
-	if(path == NULL) {
-		return FALSE;
-	}
-	doc = xmlParseFile(path);
-	if(doc == NULL) {
-		return FALSE;
-	}
-	if(TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc)) {
-		return FALSE;
-	}
-	object_root = xmlDocGetRootElement(doc);
-	if(map_path == NULL) {
-		return FALSE;
-	}
-	valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
-	map_doc = xmlParseFile(map_path);
-	if(map_doc == NULL) {
-		return FALSE;
-	}
-	if(TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_MAP_SCHEMA, map_doc)) {
-		return FALSE;
-	}
-	map_root = xmlDocGetRootElement(map_doc);
-	valid.map_calculated_count = 0;
-	valid.valid_object_count = 0;
-	valid.error_state = ERR_BACKEND_NO_ERR;
-	map_ns = map_root->ns;
-	iter.ns = map_ns;
-	qsf_valid_foreach(map_root, qsf_map_validation_handler, &iter, &valid);
-	iter.ns = object_root->ns;
-	qsf_valid_foreach(object_root, qsf_object_validation_handler, &iter, &valid);
-	if (valid.error_state != ERR_BACKEND_NO_ERR) {
-		g_hash_table_destroy(valid.validation_table);
-		return FALSE;
-	}
-	valid_count = 0 - g_hash_table_size(valid.validation_table);
-	valid_count += valid.map_calculated_count;
-	valid_count += valid.valid_object_count;
-	g_hash_table_destroy(valid.validation_table);
-	if(valid_count == 0) {
-		return TRUE;
-	}
-	return FALSE;
+    map_path = g_strdup_printf("%s/%s", QSF_SCHEMA_DIR, map_file);
+    if (path == NULL)
+    {
+        return FALSE;
+    }
+    doc = xmlParseFile(path);
+    if (doc == NULL)
+    {
+        return FALSE;
+    }
+    if (TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc))
+    {
+        return FALSE;
+    }
+    object_root = xmlDocGetRootElement(doc);
+    if (map_path == NULL)
+    {
+        return FALSE;
+    }
+    valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
+    map_doc = xmlParseFile(map_path);
+    if (map_doc == NULL)
+    {
+        return FALSE;
+    }
+    if (TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_MAP_SCHEMA, map_doc))
+    {
+        return FALSE;
+    }
+    map_root = xmlDocGetRootElement(map_doc);
+    valid.map_calculated_count = 0;
+    valid.valid_object_count = 0;
+    valid.error_state = ERR_BACKEND_NO_ERR;
+    map_ns = map_root->ns;
+    iter.ns = map_ns;
+    qsf_valid_foreach(map_root, qsf_map_validation_handler, &iter, &valid);
+    iter.ns = object_root->ns;
+    qsf_valid_foreach(object_root, qsf_object_validation_handler, &iter, &valid);
+    if (valid.error_state != ERR_BACKEND_NO_ERR)
+    {
+        g_hash_table_destroy(valid.validation_table);
+        return FALSE;
+    }
+    valid_count = 0 - g_hash_table_size(valid.validation_table);
+    valid_count += valid.map_calculated_count;
+    valid_count += valid.valid_object_count;
+    g_hash_table_destroy(valid.validation_table);
+    if (valid_count == 0)
+    {
+        return TRUE;
+    }
+    return FALSE;
 }
 
 gboolean is_qsf_map_be(qsf_param *params)
 {
-	xmlDocPtr doc;
-	struct qsf_node_iterate iter;
-	qsf_validator valid;
-	xmlNodePtr map_root;
-	xmlNsPtr map_ns;
-	gchar *path;
+    xmlDocPtr doc;
+    struct qsf_node_iterate iter;
+    qsf_validator valid;
+    xmlNodePtr map_root;
+    xmlNsPtr map_ns;
+    gchar *path;
 
-	g_return_val_if_fail((params != NULL),FALSE);
-	qof_backend_get_error(params->be);
-	path = g_strdup(params->filepath);
-	if(path == NULL) {
-		qof_backend_set_error(params->be, ERR_FILEIO_FILE_NOT_FOUND);
-		return FALSE;
-	}
-	doc = xmlParseFile(path);
-	if(doc == NULL) {
-		qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
-		return FALSE;
-	}
-	if(TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_MAP_SCHEMA, doc)) {
-		qof_backend_set_error(params->be, ERR_QSF_INVALID_MAP);
-		return FALSE;
-	}
-	map_root = xmlDocGetRootElement(doc);
-	map_ns = map_root->ns;
-	iter.ns = map_ns;
-	valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
-	valid.error_state = ERR_BACKEND_NO_ERR;
-	qsf_valid_foreach(map_root, qsf_map_validation_handler, &iter, &valid);
-	if (valid.error_state != ERR_BACKEND_NO_ERR) {
-		qof_backend_set_error(params->be, valid.error_state);
-		g_hash_table_destroy(valid.validation_table);
-		return FALSE;
-	}
-	qof_backend_get_error(params->be);
-	g_hash_table_destroy(valid.validation_table);
-	return TRUE;
+    g_return_val_if_fail((params != NULL), FALSE);
+    qof_backend_get_error(params->be);
+    path = g_strdup(params->filepath);
+    if (path == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_FILE_NOT_FOUND);
+        return FALSE;
+    }
+    doc = xmlParseFile(path);
+    if (doc == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
+        return FALSE;
+    }
+    if (TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_MAP_SCHEMA, doc))
+    {
+        qof_backend_set_error(params->be, ERR_QSF_INVALID_MAP);
+        return FALSE;
+    }
+    map_root = xmlDocGetRootElement(doc);
+    map_ns = map_root->ns;
+    iter.ns = map_ns;
+    valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
+    valid.error_state = ERR_BACKEND_NO_ERR;
+    qsf_valid_foreach(map_root, qsf_map_validation_handler, &iter, &valid);
+    if (valid.error_state != ERR_BACKEND_NO_ERR)
+    {
+        qof_backend_set_error(params->be, valid.error_state);
+        g_hash_table_destroy(valid.validation_table);
+        return FALSE;
+    }
+    qof_backend_get_error(params->be);
+    g_hash_table_destroy(valid.validation_table);
+    return TRUE;
 }
 
 gboolean is_qsf_map(const gchar *path)
 {
-	xmlDocPtr doc;
-	struct qsf_node_iterate iter;
-	qsf_validator valid;
-	xmlNodePtr map_root;
-	xmlNsPtr map_ns;
+    xmlDocPtr doc;
+    struct qsf_node_iterate iter;
+    qsf_validator valid;
+    xmlNodePtr map_root;
+    xmlNsPtr map_ns;
 
-	g_return_val_if_fail((path != NULL),FALSE);
-	if(path == NULL) { return FALSE; }
-	doc = xmlParseFile(path);
-	if(doc == NULL) { return FALSE; }
-	if(TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_MAP_SCHEMA, doc)) {
-	    xmlFreeDoc(doc);
-		return FALSE;
-	}
-	map_root = xmlDocGetRootElement(doc);
-	map_ns = map_root->ns;
-	iter.ns = map_ns;
-	valid.error_state = ERR_BACKEND_NO_ERR;
-	valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
-	qsf_valid_foreach(map_root, qsf_map_validation_handler, &iter, &valid);
-	if (valid.error_state != ERR_BACKEND_NO_ERR) {
-		g_hash_table_destroy(valid.validation_table);
-		return FALSE;
-	}
-	g_hash_table_destroy(valid.validation_table);
-	return TRUE;
+    g_return_val_if_fail((path != NULL), FALSE);
+    if (path == NULL)
+    {
+        return FALSE;
+    }
+    doc = xmlParseFile(path);
+    if (doc == NULL)
+    {
+        return FALSE;
+    }
+    if (TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_MAP_SCHEMA, doc))
+    {
+        xmlFreeDoc(doc);
+        return FALSE;
+    }
+    map_root = xmlDocGetRootElement(doc);
+    map_ns = map_root->ns;
+    iter.ns = map_ns;
+    valid.error_state = ERR_BACKEND_NO_ERR;
+    valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
+    qsf_valid_foreach(map_root, qsf_map_validation_handler, &iter, &valid);
+    if (valid.error_state != ERR_BACKEND_NO_ERR)
+    {
+        g_hash_table_destroy(valid.validation_table);
+        return FALSE;
+    }
+    g_hash_table_destroy(valid.validation_table);
+    return TRUE;
 }
 
 
 static void
 qsf_map_default_handler(xmlNodePtr child, xmlNsPtr ns, qsf_param *params )
 {
-	xmlChar *qsf_enum;
-	gchar* iterate;
+    xmlChar *qsf_enum;
+    gchar* iterate;
 
-	g_return_if_fail(params->qsf_define_hash != NULL);
-	iterate = NULL;
-	if (qsf_is_element(child, ns, MAP_DEFINE_TAG)) {
+    g_return_if_fail(params->qsf_define_hash != NULL);
+    iterate = NULL;
+    if (qsf_is_element(child, ns, MAP_DEFINE_TAG))
+    {
         iterate = (gchar*)xmlGetProp(child, BAD_CAST MAP_ITERATE_ATTR);
-        if(qof_util_bool_to_int(iterate) == 1) 
+        if (qof_util_bool_to_int(iterate) == 1)
         {
             params->qof_foreach = (QofIdType)xmlGetProp(child, BAD_CAST MAP_E_TYPE);
         }
-		if(NULL == g_hash_table_lookup(params->qsf_define_hash,
-			xmlGetProp(child, BAD_CAST MAP_E_TYPE)))
-		{
-			g_hash_table_insert(params->qsf_define_hash,
-				xmlGetProp(child, BAD_CAST MAP_E_TYPE), params->child_node);
-		}
-		else {
-			qof_backend_set_error(params->be, ERR_QSF_BAD_MAP);
-			PERR (" ERR_QSF_BAD_MAP set");
-			return;
-		}
-	}
-	if(qsf_is_element(child, ns, MAP_DEFAULT_TAG)) {
-		if(qsf_strings_equal(xmlGetProp(child, BAD_CAST MAP_TYPE_ATTR), MAP_ENUM_TYPE))
-		{
-			qsf_enum = xmlNodeGetContent(child);
-			/** Use content to discriminate enums in QOF */
-			PERR (" enum todo incomplete");
-			/** \todo FIXME: the default enum value is not used
-			implemented properly or fully handled.
-			*/
-			if(NULL == g_hash_table_lookup(params->qsf_default_hash,
-				xmlNodeGetContent(child)))
-			{
-				g_hash_table_insert(params->qsf_default_hash,
-					xmlNodeGetContent(child), child);
-			}
-			else
-			{
-				qof_backend_set_error(params->be, ERR_QSF_BAD_MAP);
-				PERR (" ERR_QSF_BAD_MAP set");
-				return;
-			}
-		}
-		/** Non-enum defaults */
-		else {
-			if(NULL == g_hash_table_lookup(params->qsf_default_hash,
-					xmlGetProp(child, BAD_CAST MAP_NAME_ATTR)))
-			{
-				g_hash_table_insert(params->qsf_default_hash,
-					xmlGetProp(child, BAD_CAST MAP_NAME_ATTR), child);
-			}
-			else
-/*					if(0 != xmlHashAddEntry(params->default_map,
-				xmlGetProp(child_node, MAP_NAME_ATTR), child_node))*/
-			{
-				qof_backend_set_error(params->be, ERR_QSF_BAD_MAP);
-				PERR (" ERR_QSF_BAD_MAP set");
-				return;
-			}
-		}
-	}
+        if (NULL == g_hash_table_lookup(params->qsf_define_hash,
+                                        xmlGetProp(child, BAD_CAST MAP_E_TYPE)))
+        {
+            g_hash_table_insert(params->qsf_define_hash,
+                                xmlGetProp(child, BAD_CAST MAP_E_TYPE), params->child_node);
+        }
+        else
+        {
+            qof_backend_set_error(params->be, ERR_QSF_BAD_MAP);
+            PERR (" ERR_QSF_BAD_MAP set");
+            return;
+        }
+    }
+    if (qsf_is_element(child, ns, MAP_DEFAULT_TAG))
+    {
+        if (qsf_strings_equal(xmlGetProp(child, BAD_CAST MAP_TYPE_ATTR), MAP_ENUM_TYPE))
+        {
+            qsf_enum = xmlNodeGetContent(child);
+            /** Use content to discriminate enums in QOF */
+            PERR (" enum todo incomplete");
+            /** \todo FIXME: the default enum value is not used
+            implemented properly or fully handled.
+            */
+            if (NULL == g_hash_table_lookup(params->qsf_default_hash,
+                                            xmlNodeGetContent(child)))
+            {
+                g_hash_table_insert(params->qsf_default_hash,
+                                    xmlNodeGetContent(child), child);
+            }
+            else
+            {
+                qof_backend_set_error(params->be, ERR_QSF_BAD_MAP);
+                PERR (" ERR_QSF_BAD_MAP set");
+                return;
+            }
+        }
+        /** Non-enum defaults */
+        else
+        {
+            if (NULL == g_hash_table_lookup(params->qsf_default_hash,
+                                            xmlGetProp(child, BAD_CAST MAP_NAME_ATTR)))
+            {
+                g_hash_table_insert(params->qsf_default_hash,
+                                    xmlGetProp(child, BAD_CAST MAP_NAME_ATTR), child);
+            }
+            else
+                /*					if(0 != xmlHashAddEntry(params->default_map,
+                				xmlGetProp(child_node, MAP_NAME_ATTR), child_node))*/
+            {
+                qof_backend_set_error(params->be, ERR_QSF_BAD_MAP);
+                PERR (" ERR_QSF_BAD_MAP set");
+                return;
+            }
+        }
+    }
 }
 
 static void
 qsf_map_top_node_handler(xmlNodePtr child, xmlNsPtr ns, qsf_param *params)
 {
-	xmlChar	*qof_version;
-	GString *buff;
-	struct qsf_node_iterate iter;
+    xmlChar	*qof_version;
+    GString *buff;
+    struct qsf_node_iterate iter;
 
-	if(!params->qsf_define_hash) return;
-	if(!params->qsf_default_hash) return;
-	ENTER (" child=%s", child->name);
-	if(qsf_is_element(child, ns, MAP_DEFINITION_TAG)) {
-		qof_version = xmlGetProp(child, BAD_CAST MAP_QOF_VERSION);
-		buff = g_string_new(" ");
-		g_string_printf(buff, "%i", QSF_QOF_VERSION);
-		if(xmlStrcmp(qof_version, BAD_CAST buff->str) != 0) {
-			qof_backend_set_error(params->be, ERR_QSF_BAD_QOF_VERSION);
-			LEAVE (" ERR_QSF_BAD_QOF_VERSION set");
-			return;
-		}
-		iter.ns = ns;
-		qsf_node_foreach(child, qsf_map_default_handler, &iter, params);
-	}
-	LEAVE (" ");
+    if (!params->qsf_define_hash) return;
+    if (!params->qsf_default_hash) return;
+    ENTER (" child=%s", child->name);
+    if (qsf_is_element(child, ns, MAP_DEFINITION_TAG))
+    {
+        qof_version = xmlGetProp(child, BAD_CAST MAP_QOF_VERSION);
+        buff = g_string_new(" ");
+        g_string_printf(buff, "%i", QSF_QOF_VERSION);
+        if (xmlStrcmp(qof_version, BAD_CAST buff->str) != 0)
+        {
+            qof_backend_set_error(params->be, ERR_QSF_BAD_QOF_VERSION);
+            LEAVE (" ERR_QSF_BAD_QOF_VERSION set");
+            return;
+        }
+        iter.ns = ns;
+        qsf_node_foreach(child, qsf_map_default_handler, &iter, params);
+    }
+    LEAVE (" ");
 }
 
 static char*
 qsf_else_set_value(xmlNodePtr parent, GHashTable *default_hash,
-		gchar *content, xmlNsPtr map_ns)
+                   gchar *content, xmlNsPtr map_ns)
 {
-	xmlNodePtr cur_node;
+    xmlNodePtr cur_node;
 
-	content = NULL;
-	for(cur_node = parent->children; cur_node != NULL; cur_node = cur_node->next)
-	{
-		if(qsf_is_element(cur_node, map_ns, QSF_CONDITIONAL_SET)) {
-			content = (gchar*)xmlNodeGetContent(cur_node);
-			return content;
-		}
-	}
-	return NULL;
+    content = NULL;
+    for (cur_node = parent->children; cur_node != NULL; cur_node = cur_node->next)
+    {
+        if (qsf_is_element(cur_node, map_ns, QSF_CONDITIONAL_SET))
+        {
+            content = (gchar*)xmlNodeGetContent(cur_node);
+            return content;
+        }
+    }
+    return NULL;
 }
 
 /* Handles the set tag in the map.
@@ -445,374 +489,413 @@
 */
 static gchar*
 qsf_set_handler(xmlNodePtr parent, GHashTable *default_hash,
-	gchar *content, qsf_param *params)
+                gchar *content, qsf_param *params)
 {
-	xmlNodePtr cur_node, lookup_node;
+    xmlNodePtr cur_node, lookup_node;
 
-	ENTER (" lookup problem");
-	content = NULL;
-	for(cur_node = parent->children; cur_node != NULL; cur_node = cur_node->next)
-	{
-		if(qsf_is_element(cur_node, params->map_ns, QSF_CONDITIONAL_SET))
-		{
-			content = (gchar*)xmlGetProp(cur_node, BAD_CAST QSF_OPTION);
-			if(qsf_strings_equal(xmlGetProp(cur_node, BAD_CAST QSF_OPTION), "qsf_lookup_string"))
-			{
-				lookup_node = (xmlNodePtr) g_hash_table_lookup(default_hash,
-					xmlNodeGetContent(cur_node));
-				content = (gchar*)xmlGetProp(lookup_node, BAD_CAST MAP_VALUE_ATTR);
-				/** \todo FIXME: do the lookup. type is defined by output object. */
-				/* Find by name, get GUID, return GUID as string. */
-				g_message("Lookup %s in the receiving application\n", content );
-				LEAVE (" todo");
-				return content;
-			}
-			if(content)
-			{
-				lookup_node = (xmlNodePtr) g_hash_table_lookup(default_hash,
-					xmlNodeGetContent(cur_node));
-				content = (gchar*)xmlGetProp(lookup_node, BAD_CAST "value");
-				return content;
-			}
-			content = (gchar*)xmlGetProp(parent, BAD_CAST "boolean");
-			if(!content) {
-				/** \todo Check qsf_parameter_hash arguments */
-				lookup_node = (xmlNodePtr) g_hash_table_lookup(params->qsf_parameter_hash,
-					xmlGetProp(parent->parent, BAD_CAST MAP_TYPE_ATTR));
-				if(lookup_node) { return (gchar*)xmlNodeGetContent(lookup_node); }
-				LEAVE (" check arguments");
-				return (gchar*)xmlNodeGetContent(cur_node);
-			}
-		}
-	}
-	LEAVE (" null");
-	return NULL;
+    ENTER (" lookup problem");
+    content = NULL;
+    for (cur_node = parent->children; cur_node != NULL; cur_node = cur_node->next)
+    {
+        if (qsf_is_element(cur_node, params->map_ns, QSF_CONDITIONAL_SET))
+        {
+            content = (gchar*)xmlGetProp(cur_node, BAD_CAST QSF_OPTION);
+            if (qsf_strings_equal(xmlGetProp(cur_node, BAD_CAST QSF_OPTION), "qsf_lookup_string"))
+            {
+                lookup_node = (xmlNodePtr) g_hash_table_lookup(default_hash,
+                              xmlNodeGetContent(cur_node));
+                content = (gchar*)xmlGetProp(lookup_node, BAD_CAST MAP_VALUE_ATTR);
+                /** \todo FIXME: do the lookup. type is defined by output object. */
+                /* Find by name, get GUID, return GUID as string. */
+                g_message("Lookup %s in the receiving application\n", content );
+                LEAVE (" todo");
+                return content;
+            }
+            if (content)
+            {
+                lookup_node = (xmlNodePtr) g_hash_table_lookup(default_hash,
+                              xmlNodeGetContent(cur_node));
+                content = (gchar*)xmlGetProp(lookup_node, BAD_CAST "value");
+                return content;
+            }
+            content = (gchar*)xmlGetProp(parent, BAD_CAST "boolean");
+            if (!content)
+            {
+                /** \todo Check qsf_parameter_hash arguments */
+                lookup_node = (xmlNodePtr) g_hash_table_lookup(params->qsf_parameter_hash,
+                              xmlGetProp(parent->parent, BAD_CAST MAP_TYPE_ATTR));
+                if (lookup_node)
+                {
+                    return (gchar*)xmlNodeGetContent(lookup_node);
+                }
+                LEAVE (" check arguments");
+                return (gchar*)xmlNodeGetContent(cur_node);
+            }
+        }
+    }
+    LEAVE (" null");
+    return NULL;
 }
 
 static void
 qsf_calculate_else(xmlNodePtr param_node, xmlNodePtr child, qsf_param *params)
 {
-	xmlNodePtr export_node;
-	xmlChar *output_content, *object_data;
+    xmlNodePtr export_node;
+    xmlChar *output_content, *object_data;
 
-	if(qsf_is_element(param_node, params->map_ns, QSF_CONDITIONAL_ELSE)) {
-		if(params->boolean_calculation_done == 0) {
-			output_content = object_data = NULL;
-			output_content = BAD_CAST qsf_set_handler(param_node,
-				params->qsf_default_hash, (gchar*)output_content, params);
-			if(output_content == NULL) {
-				output_content = xmlGetProp(param_node, BAD_CAST MAP_TYPE_ATTR);
-				object_data = BAD_CAST qsf_else_set_value(param_node, params->qsf_default_hash,
-					(gchar*)output_content, params->map_ns);
-				output_content = BAD_CAST xmlGetProp( (xmlNodePtr) g_hash_table_lookup(
-					params->qsf_default_hash, object_data), BAD_CAST MAP_VALUE_ATTR);
-			}
-			if(object_data != NULL) {
-				export_node =(xmlNodePtr) g_hash_table_lookup(
-					params->qsf_parameter_hash,
-					xmlGetProp(params->child_node, BAD_CAST QSF_OBJECT_TYPE));
-				object_data = xmlNodeGetContent(export_node);
-			}
-			if(output_content != NULL) { object_data = output_content; }
-			export_node = xmlAddChild(params->lister, xmlNewNode(params->qsf_ns,
-				xmlGetProp(child, BAD_CAST QSF_OBJECT_TYPE)));
-			xmlNewProp(export_node, BAD_CAST QSF_OBJECT_TYPE,
-				xmlGetProp(child, BAD_CAST MAP_VALUE_ATTR));
-			xmlNodeAddContent(export_node, object_data);
-			params->boolean_calculation_done = 1;
-		}
-	}
+    if (qsf_is_element(param_node, params->map_ns, QSF_CONDITIONAL_ELSE))
+    {
+        if (params->boolean_calculation_done == 0)
+        {
+            output_content = object_data = NULL;
+            output_content = BAD_CAST qsf_set_handler(param_node,
+                             params->qsf_default_hash, (gchar*)output_content, params);
+            if (output_content == NULL)
+            {
+                output_content = xmlGetProp(param_node, BAD_CAST MAP_TYPE_ATTR);
+                object_data = BAD_CAST qsf_else_set_value(param_node, params->qsf_default_hash,
+                              (gchar*)output_content, params->map_ns);
+                output_content = BAD_CAST xmlGetProp( (xmlNodePtr) g_hash_table_lookup(
+                                                          params->qsf_default_hash, object_data), BAD_CAST MAP_VALUE_ATTR);
+            }
+            if (object_data != NULL)
+            {
+                export_node = (xmlNodePtr) g_hash_table_lookup(
+                                  params->qsf_parameter_hash,
+                                  xmlGetProp(params->child_node, BAD_CAST QSF_OBJECT_TYPE));
+                object_data = xmlNodeGetContent(export_node);
+            }
+            if (output_content != NULL)
+            {
+                object_data = output_content;
+            }
+            export_node = xmlAddChild(params->lister, xmlNewNode(params->qsf_ns,
+                                      xmlGetProp(child, BAD_CAST QSF_OBJECT_TYPE)));
+            xmlNewProp(export_node, BAD_CAST QSF_OBJECT_TYPE,
+                       xmlGetProp(child, BAD_CAST MAP_VALUE_ATTR));
+            xmlNodeAddContent(export_node, object_data);
+            params->boolean_calculation_done = 1;
+        }
+    }
 }
 
 static void
 qsf_set_format_value(xmlChar *format, gchar *qsf_time_now_as_string,
-	xmlNodePtr cur_node, qsf_param *params)
+                     xmlNodePtr cur_node, qsf_param *params)
 {
-	gint result;
-	xmlChar *content;
-	time_t *output;
-	struct tm *tmp;
-	time_t tester;
-	xmlNodePtr kl;
-	regex_t reg;
+    gint result;
+    xmlChar *content;
+    time_t *output;
+    struct tm *tmp;
+    time_t tester;
+    xmlNodePtr kl;
+    regex_t reg;
 
-	/** Comments retained - this behaves a little strangely */
+    /** Comments retained - this behaves a little strangely */
 
-	result = 0;
-	if(format == NULL) { return; }
-	ENTER (" ");
-	content = xmlNodeGetContent(cur_node);
-	output = (time_t*) g_hash_table_lookup(params->qsf_default_hash, content);
-	if(!output) {
-		/** No default time set, use the object time */
-		/** fill the time structs with temp data */
-		tester = time(NULL);
-		tmp = gmtime(&tester);
-		/** Lookup the object value to read */
-		/** \todo qsf_parameter_hash check correct arguments */
-		kl = (xmlNodePtr) g_hash_table_lookup(params->qsf_parameter_hash, content);
-		if(!kl) {
-			LEAVE (" no suitable date set.");
-			return;
-		}
-		/** Read the object value as a dateTime  */
-		strptime((char*)xmlNodeGetContent(kl), QSF_XSD_TIME, tmp);
-		if(!tmp) {
-			LEAVE (" empty date field in QSF object.\n");
-			return;
-		}
-		tester = mktime(tmp);
-		output = &tester;
-	}
-	result = regcomp(&reg, "%[a-zA-Z]", REG_EXTENDED|REG_NOSUB);
-	result = regexec(&reg, (gchar*)format,(size_t)0,NULL,0);
-	if(result == REG_NOMATCH) { format = BAD_CAST "%F"; }
-	regfree(&reg);
-	/** QSF_DATE_LENGTH preset for all internal and QSF_XSD_TIME string formats.
-	 */
-	qof_strftime(qsf_time_now_as_string, QSF_DATE_LENGTH, (char*)format, gmtime(output));
-	LEAVE (" ok");
+    result = 0;
+    if (format == NULL)
+    {
+        return;
+    }
+    ENTER (" ");
+    content = xmlNodeGetContent(cur_node);
+    output = (time_t*) g_hash_table_lookup(params->qsf_default_hash, content);
+    if (!output)
+    {
+        /** No default time set, use the object time */
+        /** fill the time structs with temp data */
+        tester = time(NULL);
+        tmp = gmtime(&tester);
+        /** Lookup the object value to read */
+        /** \todo qsf_parameter_hash check correct arguments */
+        kl = (xmlNodePtr) g_hash_table_lookup(params->qsf_parameter_hash, content);
+        if (!kl)
+        {
+            LEAVE (" no suitable date set.");
+            return;
+        }
+        /** Read the object value as a dateTime  */
+        strptime((char*)xmlNodeGetContent(kl), QSF_XSD_TIME, tmp);
+        if (!tmp)
+        {
+            LEAVE (" empty date field in QSF object.\n");
+            return;
+        }
+        tester = mktime(tmp);
+        output = &tester;
+    }
+    result = regcomp(&reg, "%[a-zA-Z]", REG_EXTENDED | REG_NOSUB);
+    result = regexec(&reg, (gchar*)format, (size_t)0, NULL, 0);
+    if (result == REG_NOMATCH)
+    {
+        format = BAD_CAST "%F";
+    }
+    regfree(&reg);
+    /** QSF_DATE_LENGTH preset for all internal and QSF_XSD_TIME string formats.
+     */
+    qof_strftime(qsf_time_now_as_string, QSF_DATE_LENGTH, (char*)format, gmtime(output));
+    LEAVE (" ok");
 }
 
 static void
 qsf_boolean_set_value(xmlNodePtr parent, qsf_param *params,
-		gchar *content, xmlNsPtr map_ns)
+                      gchar *content, xmlNsPtr map_ns)
 {
-	xmlNodePtr cur_node;
-	xmlChar *boolean_name;
+    xmlNodePtr cur_node;
+    xmlChar *boolean_name;
 
-	boolean_name = NULL;
-	for(cur_node = parent->children; cur_node != NULL; cur_node = cur_node->next) {
-		if(qsf_is_element(cur_node, map_ns, QSF_CONDITIONAL_SET)) {
-			boolean_name = xmlGetProp(cur_node, BAD_CAST QSF_FORMATTING_OPTION);
-			qsf_set_format_value(boolean_name, content, cur_node, params);
-		}
-	}
+    boolean_name = NULL;
+    for (cur_node = parent->children; cur_node != NULL; cur_node = cur_node->next)
+    {
+        if (qsf_is_element(cur_node, map_ns, QSF_CONDITIONAL_SET))
+        {
+            boolean_name = xmlGetProp(cur_node, BAD_CAST QSF_FORMATTING_OPTION);
+            qsf_set_format_value(boolean_name, content, cur_node, params);
+        }
+    }
 }
 
 static void
 qsf_calculate_conditional(xmlNodePtr param_node, xmlNodePtr child, qsf_param *params)
 {
-	xmlNodePtr export_node;
-	xmlChar *output_content;
+    xmlNodePtr export_node;
+    xmlChar *output_content;
 
-	output_content = NULL;
-	if(qsf_is_element(param_node, params->map_ns, QSF_CONDITIONAL)) {
-		if(params->boolean_calculation_done == 0) {
-		/* set handler */
-		output_content = BAD_CAST qsf_set_handler(param_node, params->qsf_default_hash,
-				(gchar*)output_content, params);
-		/* If the 'if' contains a boolean that has a default value */
-		if(output_content == NULL) {
-			if(NULL != xmlGetProp(param_node, BAD_CAST QSF_BOOLEAN_DEFAULT)) {
-			output_content = xmlGetProp( (xmlNodePtr) g_hash_table_lookup(
-				params->qsf_default_hash, xmlGetProp(param_node,
-				BAD_CAST QSF_BOOLEAN_DEFAULT) ), BAD_CAST MAP_VALUE_ATTR);
-			}
-			/* Is the default set to true? */
-			if( 0 == qsf_compare_tag_strings(output_content, QSF_XML_BOOLEAN_TEST))
-			{
-				qsf_boolean_set_value(param_node, params, (gchar*)output_content, params->map_ns);
-				export_node = xmlAddChild(params->lister, xmlNewNode(params->qsf_ns,
-					xmlGetProp(child, BAD_CAST QSF_OBJECT_TYPE)));
-				xmlNewProp(export_node, BAD_CAST QSF_OBJECT_TYPE,
-					xmlGetProp(child, BAD_CAST MAP_VALUE_ATTR));
-				xmlNodeAddContent(export_node, output_content);
-				params->boolean_calculation_done = 1;
-				}
-			}
-		}
-	}
+    output_content = NULL;
+    if (qsf_is_element(param_node, params->map_ns, QSF_CONDITIONAL))
+    {
+        if (params->boolean_calculation_done == 0)
+        {
+            /* set handler */
+            output_content = BAD_CAST qsf_set_handler(param_node, params->qsf_default_hash,
+                             (gchar*)output_content, params);
+            /* If the 'if' contains a boolean that has a default value */
+            if (output_content == NULL)
+            {
+                if (NULL != xmlGetProp(param_node, BAD_CAST QSF_BOOLEAN_DEFAULT))
+                {
+                    output_content = xmlGetProp( (xmlNodePtr) g_hash_table_lookup(
+                                                     params->qsf_default_hash, xmlGetProp(param_node,
+                                                                                          BAD_CAST QSF_BOOLEAN_DEFAULT) ), BAD_CAST MAP_VALUE_ATTR);
+                }
+                /* Is the default set to true? */
+                if ( 0 == qsf_compare_tag_strings(output_content, QSF_XML_BOOLEAN_TEST))
+                {
+                    qsf_boolean_set_value(param_node, params, (gchar*)output_content, params->map_ns);
+                    export_node = xmlAddChild(params->lister, xmlNewNode(params->qsf_ns,
+                                              xmlGetProp(child, BAD_CAST QSF_OBJECT_TYPE)));
+                    xmlNewProp(export_node, BAD_CAST QSF_OBJECT_TYPE,
+                               xmlGetProp(child, BAD_CAST MAP_VALUE_ATTR));
+                    xmlNodeAddContent(export_node, output_content);
+                    params->boolean_calculation_done = 1;
+                }
+            }
+        }
+    }
 }
 
 static void
 qsf_add_object_tag(qsf_param *params, gint count)
 {
-	xmlNodePtr extra_node;
-	GString *str;
-	xmlChar *property;
+    xmlNodePtr extra_node;
+    GString *str;
+    xmlChar *property;
 
-	str = g_string_new (" ");
-	g_string_printf(str, "%i", count);
-	extra_node = NULL;
-	extra_node = xmlAddChild(params->output_node,
-		xmlNewNode(params->qsf_ns, BAD_CAST QSF_OBJECT_TAG));
-	xmlNewProp(extra_node, BAD_CAST QSF_OBJECT_TYPE,
-		xmlGetProp(params->convert_node, BAD_CAST QSF_OBJECT_TYPE));
-	property = xmlCharStrdup(str->str);
-	xmlNewProp(extra_node, BAD_CAST QSF_OBJECT_COUNT, property);
-	params->lister = extra_node;
+    str = g_string_new (" ");
+    g_string_printf(str, "%i", count);
+    extra_node = NULL;
+    extra_node = xmlAddChild(params->output_node,
+                             xmlNewNode(params->qsf_ns, BAD_CAST QSF_OBJECT_TAG));
+    xmlNewProp(extra_node, BAD_CAST QSF_OBJECT_TYPE,
+               xmlGetProp(params->convert_node, BAD_CAST QSF_OBJECT_TYPE));
+    property = xmlCharStrdup(str->str);
+    xmlNewProp(extra_node, BAD_CAST QSF_OBJECT_COUNT, property);
+    params->lister = extra_node;
 }
 
 static gint
 identify_source_func(gconstpointer qsf_object, gconstpointer map)
 {
-	return safe_strcmp(((qsf_objects*)qsf_object)->object_type, (QofIdType)map);
+    return safe_strcmp(((qsf_objects*)qsf_object)->object_type, (QofIdType)map);
 }
 
 static void
 qsf_map_calculate_output(xmlNodePtr param_node, xmlNodePtr child, qsf_param *params)
 {
-	xmlNodePtr export_node;
-	xmlChar *output_content;
-	xmlNodePtr node;
-	GList *source;
+    xmlNodePtr export_node;
+    xmlChar *output_content;
+    xmlNodePtr node;
+    GList *source;
 
-	DEBUG (" %s", xmlNodeGetContent(param_node));
-	output_content = xmlNodeGetContent(param_node);
-	/* source refers to the source object that provides the data */
-	source = g_list_find_custom(params->qsf_object_list, 
-		BAD_CAST xmlGetProp(param_node, BAD_CAST MAP_OBJECT_ATTR),
-                                             identify_source_func);
-	if(!source) return;
-	params->object_set = source->data;
-	node = g_hash_table_lookup(params->object_set->parameters, output_content);
-	export_node = xmlAddChild(params->lister, xmlNewNode(params->qsf_ns,
-		xmlGetProp(child, BAD_CAST QSF_OBJECT_TYPE)));
-	xmlNewProp(export_node, BAD_CAST QSF_OBJECT_TYPE,
-		xmlGetProp(child, BAD_CAST MAP_VALUE_ATTR));
-	if(node) { xmlNodeAddContent(export_node, xmlNodeGetContent(node)); }
+    DEBUG (" %s", xmlNodeGetContent(param_node));
+    output_content = xmlNodeGetContent(param_node);
+    /* source refers to the source object that provides the data */
+    source = g_list_find_custom(params->qsf_object_list,
+                                BAD_CAST xmlGetProp(param_node, BAD_CAST MAP_OBJECT_ATTR),
+                                identify_source_func);
+    if (!source) return;
+    params->object_set = source->data;
+    node = g_hash_table_lookup(params->object_set->parameters, output_content);
+    export_node = xmlAddChild(params->lister, xmlNewNode(params->qsf_ns,
+                              xmlGetProp(child, BAD_CAST QSF_OBJECT_TYPE)));
+    xmlNewProp(export_node, BAD_CAST QSF_OBJECT_TYPE,
+               xmlGetProp(child, BAD_CAST MAP_VALUE_ATTR));
+    if (node)
+    {
+        xmlNodeAddContent(export_node, xmlNodeGetContent(node));
+    }
 }
 
 static void
 qsf_map_object_handler(xmlNodePtr child, xmlNsPtr ns, qsf_param *params)
 {
-	xmlNodePtr param_node;
-	xmlNsPtr map_ns, qsf_ns;
-	gint result;
+    xmlNodePtr param_node;
+    xmlNsPtr map_ns, qsf_ns;
+    gint result;
 
-	map_ns = ns;
-	qsf_ns = params->qsf_ns;
-	param_node = NULL;
-	result = 0;
-	if(child == NULL) { return; }
-	if(ns == NULL) { return; }
-	params->boolean_calculation_done = 0;
+    map_ns = ns;
+    qsf_ns = params->qsf_ns;
+    param_node = NULL;
+    result = 0;
+    if (child == NULL)
+    {
+        return;
+    }
+    if (ns == NULL)
+    {
+        return;
+    }
+    params->boolean_calculation_done = 0;
 
-	if(qsf_is_element(child, map_ns, MAP_CALCULATE_TAG)) {
-		params->boolean_calculation_done = 0;
+    if (qsf_is_element(child, map_ns, MAP_CALCULATE_TAG))
+    {
+        params->boolean_calculation_done = 0;
         /* read the child nodes to prepare the calculation. */
-		for(param_node = child->children; param_node != NULL;
-			param_node = param_node->next)
-		{
-			if(qsf_is_element(param_node, map_ns, QSF_CONDITIONAL_SET))
-			{
-				/* Map the pre-defined defaults */
-				if(0 == qsf_compare_tag_strings(
-					xmlNodeGetContent(param_node), "qsf_enquiry_date"))
-				{
-					qsf_string_default_handler("qsf_enquiry_date",
-						params->qsf_default_hash, params->lister, child, qsf_ns);
-				}
-				if(0 == qsf_compare_tag_strings(
-					xmlNodeGetContent(param_node), "qsf_time_now"))
-				{
-					qsf_date_default_handler("qsf_time_now",
-						params->qsf_default_hash, params->lister, child, qsf_ns);
-				}
-				if(0 == qsf_compare_tag_strings(
-					xmlNodeGetContent(param_node), "qsf_time_string"))
-				{
-					qsf_string_default_handler("qsf_time_string",
-						params->qsf_default_hash, params->lister, child, qsf_ns);
-				}
+        for (param_node = child->children; param_node != NULL;
+                param_node = param_node->next)
+        {
+            if (qsf_is_element(param_node, map_ns, QSF_CONDITIONAL_SET))
+            {
+                /* Map the pre-defined defaults */
+                if (0 == qsf_compare_tag_strings(
+                            xmlNodeGetContent(param_node), "qsf_enquiry_date"))
+                {
+                    qsf_string_default_handler("qsf_enquiry_date",
+                                               params->qsf_default_hash, params->lister, child, qsf_ns);
+                }
+                if (0 == qsf_compare_tag_strings(
+                            xmlNodeGetContent(param_node), "qsf_time_now"))
+                {
+                    qsf_date_default_handler("qsf_time_now",
+                                             params->qsf_default_hash, params->lister, child, qsf_ns);
+                }
+                if (0 == qsf_compare_tag_strings(
+                            xmlNodeGetContent(param_node), "qsf_time_string"))
+                {
+                    qsf_string_default_handler("qsf_time_string",
+                                               params->qsf_default_hash, params->lister, child, qsf_ns);
+                }
                 qsf_map_calculate_output(param_node, child, params);
-			}
-			qsf_calculate_conditional( param_node, child, params);
-			qsf_calculate_else(param_node, child, params);
-		}
-		/* calculate_map currently not in use */
-		/* ensure uniqueness of the key before re-instating */
-/*		result = xmlHashAddEntry2(calculate_map,
-			xmlGetProp(child_node, MAP_TYPE_ATTR),
-			xmlGetProp(child_node, MAP_VALUE_ATTR), child_node);
-		if(result != 0) {
-			printf("add entry to calculate hash failed. %s\t%s\t%s.\n",
-				xmlGetProp(child_node, MAP_TYPE_ATTR),
-			xmlGetProp(child_node, MAP_VALUE_ATTR), child_node->name);
-			return;
-		}
+            }
+            qsf_calculate_conditional( param_node, child, params);
+            qsf_calculate_else(param_node, child, params);
+        }
+        /* calculate_map currently not in use */
+        /* ensure uniqueness of the key before re-instating */
+        /*		result = xmlHashAddEntry2(calculate_map,
+        			xmlGetProp(child_node, MAP_TYPE_ATTR),
+        			xmlGetProp(child_node, MAP_VALUE_ATTR), child_node);
+        		if(result != 0) {
+        			printf("add entry to calculate hash failed. %s\t%s\t%s.\n",
+        				xmlGetProp(child_node, MAP_TYPE_ATTR),
+        			xmlGetProp(child_node, MAP_VALUE_ATTR), child_node->name);
+        			return;
+        		}
 
-		is_qsf_object_with_map(path, map_path);
-*/
-	}
+        		is_qsf_object_with_map(path, map_path);
+        */
+    }
 }
 
 static void
 iterator_cb(xmlNodePtr child, xmlNsPtr ns, qsf_param *params)
 {
-	gchar *object_name;
+    gchar *object_name;
 
-	/* count the number of iterators in the QSF file */
-	if(qsf_is_element(child, ns, QSF_OBJECT_TAG))
-	{
-		object_name = (gchar *)xmlGetProp(child, BAD_CAST QSF_OBJECT_TYPE);
-		if(0 == safe_strcmp(object_name, params->qof_foreach))
-		{
-			params->foreach_limit++;
-		}
-	}
+    /* count the number of iterators in the QSF file */
+    if (qsf_is_element(child, ns, QSF_OBJECT_TAG))
+    {
+        object_name = (gchar *)xmlGetProp(child, BAD_CAST QSF_OBJECT_TYPE);
+        if (0 == safe_strcmp(object_name, params->qof_foreach))
+        {
+            params->foreach_limit++;
+        }
+    }
 }
 
 xmlDocPtr
 qsf_object_convert(xmlDocPtr mapDoc, xmlNodePtr qsf_root, qsf_param *params)
 {
-	/* mapDoc : map document. qsf_root: incoming QSF root node. */
-	struct qsf_node_iterate iter;
-	xmlDocPtr output_doc;
-	xmlNode *cur_node;
-	xmlNode *map_root, *output_root;
+    /* mapDoc : map document. qsf_root: incoming QSF root node. */
+    struct qsf_node_iterate iter;
+    xmlDocPtr output_doc;
+    xmlNode *cur_node;
+    xmlNode *map_root, *output_root;
 
-	g_return_val_if_fail((mapDoc && qsf_root && params), NULL);
-	ENTER (" root=%s", qsf_root->name);
-	/* prepare the intermediary document */
-	iter.ns = params->qsf_ns;
-	output_doc = xmlNewDoc(BAD_CAST QSF_XML_VERSION);
-	output_root = xmlNewNode(NULL, BAD_CAST QSF_ROOT_TAG);
-	xmlDocSetRootElement(output_doc, output_root);
-	xmlSetNs(output_root, params->qsf_ns);
-	params->output_node = xmlNewChild(output_root, params->qsf_ns, 
-        BAD_CAST QSF_BOOK_TAG, NULL);
-	xmlNewProp(params->output_node, BAD_CAST QSF_BOOK_COUNT, BAD_CAST "1");
-	/* parse the incoming QSF */
-	qsf_book_node_handler(qsf_root->children->next, params->qsf_ns, params);
-	/* parse the map and calculate the values */
-	map_root = xmlDocGetRootElement(mapDoc);
-	params->foreach_limit = 0;
-	iter.ns = params->map_ns;
-	qsf_node_foreach(map_root, qsf_map_top_node_handler, &iter, params);
-	/* identify the entities of iterator type. */
-	iter.ns = params->qsf_ns;
-	qsf_node_foreach(qsf_root->children->next, iterator_cb, &iter, params);
+    g_return_val_if_fail((mapDoc && qsf_root && params), NULL);
+    ENTER (" root=%s", qsf_root->name);
+    /* prepare the intermediary document */
+    iter.ns = params->qsf_ns;
+    output_doc = xmlNewDoc(BAD_CAST QSF_XML_VERSION);
+    output_root = xmlNewNode(NULL, BAD_CAST QSF_ROOT_TAG);
+    xmlDocSetRootElement(output_doc, output_root);
+    xmlSetNs(output_root, params->qsf_ns);
+    params->output_node = xmlNewChild(output_root, params->qsf_ns,
+                                      BAD_CAST QSF_BOOK_TAG, NULL);
+    xmlNewProp(params->output_node, BAD_CAST QSF_BOOK_COUNT, BAD_CAST "1");
+    /* parse the incoming QSF */
+    qsf_book_node_handler(qsf_root->children->next, params->qsf_ns, params);
+    /* parse the map and calculate the values */
+    map_root = xmlDocGetRootElement(mapDoc);
+    params->foreach_limit = 0;
+    iter.ns = params->map_ns;
+    qsf_node_foreach(map_root, qsf_map_top_node_handler, &iter, params);
+    /* identify the entities of iterator type. */
+    iter.ns = params->qsf_ns;
+    qsf_node_foreach(qsf_root->children->next, iterator_cb, &iter, params);
 
-	params->count = 0;
-	for(cur_node = map_root->children; cur_node != NULL; cur_node = cur_node->next)
-	{
-		params->convert_node = cur_node;
-		if(qsf_is_element(cur_node, params->map_ns, MAP_OBJECT_TAG))
-		{
-			gint i;
+    params->count = 0;
+    for (cur_node = map_root->children; cur_node != NULL; cur_node = cur_node->next)
+    {
+        params->convert_node = cur_node;
+        if (qsf_is_element(cur_node, params->map_ns, MAP_OBJECT_TAG))
+        {
+            gint i;
 
-			params->lister = NULL;
-			/* cur_node describes the target object */
-			if(!qof_class_is_registered(
-				(QofIdTypeConst)xmlGetProp(cur_node,
-                     BAD_CAST MAP_TYPE_ATTR))) { continue; }
-			qsf_add_object_tag(params, params->count);
-			params->count++;
-			iter.ns = params->map_ns;
-			for(i = 0; i < params->foreach_limit; i++) 
-			{
-				qsf_node_foreach(cur_node, qsf_map_object_handler, &iter, params);
-				params->qsf_object_list = g_list_next(params->qsf_object_list);
-				qsf_add_object_tag(params, params->count);
-				params->count++;
-			}
-		}
-	}
-	params->file_type = OUR_QSF_OBJ;
-	/* use for debugging */
-	/*    xmlSaveFormatFileEnc("-", output_doc, "UTF-8", 1);*/
-	LEAVE (" ");
-	return output_doc;
+            params->lister = NULL;
+            /* cur_node describes the target object */
+            if (!qof_class_is_registered(
+                        (QofIdTypeConst)xmlGetProp(cur_node,
+                                                   BAD_CAST MAP_TYPE_ATTR)))
+            {
+                continue;
+            }
+            qsf_add_object_tag(params, params->count);
+            params->count++;
+            iter.ns = params->map_ns;
+            for (i = 0; i < params->foreach_limit; i++)
+            {
+                qsf_node_foreach(cur_node, qsf_map_object_handler, &iter, params);
+                params->qsf_object_list = g_list_next(params->qsf_object_list);
+                qsf_add_object_tag(params, params->count);
+                params->count++;
+            }
+        }
+    }
+    params->file_type = OUR_QSF_OBJ;
+    /* use for debugging */
+    /*    xmlSaveFormatFileEnc("-", output_doc, "UTF-8", 1);*/
+    LEAVE (" ");
+    return output_doc;
 }

Modified: gnucash/trunk/src/libqof/backend/file/qsf-xml.c
===================================================================
--- gnucash/trunk/src/libqof/backend/file/qsf-xml.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/libqof/backend/file/qsf-xml.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -38,335 +38,376 @@
 gint
 qsf_compare_tag_strings(const xmlChar *node_name, gchar *tag_name)
 {
-	return xmlStrcmp(node_name, (const xmlChar *)tag_name);
+    return xmlStrcmp(node_name, (const xmlChar *)tag_name);
 }
 
 gint
 qsf_strings_equal(const xmlChar *node_name, gchar *tag_name)
 {
-	if(0 == qsf_compare_tag_strings(node_name, tag_name)) { return 1; }
-	return 0;
+    if (0 == qsf_compare_tag_strings(node_name, tag_name))
+    {
+        return 1;
+    }
+    return 0;
 }
 
 gint
 qsf_is_element(xmlNodePtr a, xmlNsPtr ns, gchar *c)
 {
-	g_return_val_if_fail(a != NULL, 0);
-	g_return_val_if_fail(ns != NULL, 0);
-	g_return_val_if_fail(c != NULL, 0);
-	if ((a->ns == ns) && (a->type == XML_ELEMENT_NODE) &&
-		qsf_strings_equal(a->name, c)) { return 1; }
-	return 0;
+    g_return_val_if_fail(a != NULL, 0);
+    g_return_val_if_fail(ns != NULL, 0);
+    g_return_val_if_fail(c != NULL, 0);
+    if ((a->ns == ns) && (a->type == XML_ELEMENT_NODE) &&
+            qsf_strings_equal(a->name, c))
+    {
+        return 1;
+    }
+    return 0;
 }
 
 gint
 qsf_check_tag(qsf_param *params, gchar *qof_type)
 {
-	return qsf_is_element(params->child_node, params->qsf_ns, qof_type);
+    return qsf_is_element(params->child_node, params->qsf_ns, qof_type);
 }
 
 gboolean
 qsf_is_valid(const gchar *schema_dir, const gchar* schema_filename, xmlDocPtr doc)
 {
-	xmlSchemaParserCtxtPtr qsf_schema_file;
-	xmlSchemaPtr qsf_schema;
-	xmlSchemaValidCtxtPtr qsf_context;
-	gchar *schema_path;
-	gint result;
+    xmlSchemaParserCtxtPtr qsf_schema_file;
+    xmlSchemaPtr qsf_schema;
+    xmlSchemaValidCtxtPtr qsf_context;
+    gchar *schema_path;
+    gint result;
 
-	g_return_val_if_fail(doc || schema_filename, FALSE);
-	schema_path = g_strdup_printf("%s/%s", schema_dir, schema_filename);
-	qsf_schema_file = xmlSchemaNewParserCtxt(schema_path);
-	qsf_schema = xmlSchemaParse(qsf_schema_file);
-	qsf_context = xmlSchemaNewValidCtxt(qsf_schema);
-	result = xmlSchemaValidateDoc(qsf_context, doc);
-	xmlSchemaFreeParserCtxt(qsf_schema_file);
-	xmlSchemaFreeValidCtxt(qsf_context);
-	xmlSchemaFree(qsf_schema);
-	g_free(schema_path);
-	if(result == 0) { return TRUE; }
-	return FALSE;
+    g_return_val_if_fail(doc || schema_filename, FALSE);
+    schema_path = g_strdup_printf("%s/%s", schema_dir, schema_filename);
+    qsf_schema_file = xmlSchemaNewParserCtxt(schema_path);
+    qsf_schema = xmlSchemaParse(qsf_schema_file);
+    qsf_context = xmlSchemaNewValidCtxt(qsf_schema);
+    result = xmlSchemaValidateDoc(qsf_context, doc);
+    xmlSchemaFreeParserCtxt(qsf_schema_file);
+    xmlSchemaFreeValidCtxt(qsf_context);
+    xmlSchemaFree(qsf_schema);
+    g_free(schema_path);
+    if (result == 0)
+    {
+        return TRUE;
+    }
+    return FALSE;
 }
 
 void
 qsf_valid_foreach(xmlNodePtr parent, qsf_validCB cb,
-	struct qsf_node_iterate *iter, qsf_validator *valid)
+                  struct qsf_node_iterate *iter, qsf_validator *valid)
 {
-	xmlNodePtr cur_node;
+    xmlNodePtr cur_node;
 
-	iter->v_fcn = &cb;
-	for(cur_node = parent->children; cur_node != NULL; cur_node = cur_node->next)
-	{
-		cb(cur_node, iter->ns, valid);
-	}
+    iter->v_fcn = &cb;
+    for (cur_node = parent->children; cur_node != NULL; cur_node = cur_node->next)
+    {
+        cb(cur_node, iter->ns, valid);
+    }
 }
 
 void
 qsf_node_foreach(xmlNodePtr parent, qsf_nodeCB cb,
-	struct qsf_node_iterate *iter, qsf_param *params)
+                 struct qsf_node_iterate *iter, qsf_param *params)
 {
-	xmlNodePtr cur_node;
+    xmlNodePtr cur_node;
 
-	g_return_if_fail(iter->ns);
-	iter->fcn = &cb;
-	for(cur_node = parent->children; cur_node != NULL; cur_node = cur_node->next)
-	{
-		cb(cur_node, iter->ns, params);
-	}
+    g_return_if_fail(iter->ns);
+    iter->fcn = &cb;
+    for (cur_node = parent->children; cur_node != NULL; cur_node = cur_node->next)
+    {
+        cb(cur_node, iter->ns, params);
+    }
 }
 
 void
 qsf_object_validation_handler(xmlNodePtr child, xmlNsPtr ns, qsf_validator *valid)
 {
-	xmlNodePtr cur_node;
-	xmlChar *object_declaration;
-	guint count;
+    xmlNodePtr cur_node;
+    xmlChar *object_declaration;
+    guint count;
 
-	count = 0;
-	for(cur_node = child->children; cur_node != NULL;
-		cur_node = cur_node->next)
-	{
-		if(qsf_is_element(cur_node, ns, QSF_OBJECT_TAG)) {
-			object_declaration = xmlGetProp(cur_node, BAD_CAST QSF_OBJECT_TYPE);
-			count = g_hash_table_size(valid->validation_table);
-			g_hash_table_insert(valid->validation_table, object_declaration, xmlNodeGetContent(cur_node));
-			if(g_hash_table_size(valid->validation_table) > count)
-			{
-				valid->valid_object_count++;
-				if(TRUE == qof_class_is_registered((QofIdTypeConst) object_declaration))
-				{
-					valid->qof_registered_count++;
-				}
-			}
-		}
-	}
+    count = 0;
+    for (cur_node = child->children; cur_node != NULL;
+            cur_node = cur_node->next)
+    {
+        if (qsf_is_element(cur_node, ns, QSF_OBJECT_TAG))
+        {
+            object_declaration = xmlGetProp(cur_node, BAD_CAST QSF_OBJECT_TYPE);
+            count = g_hash_table_size(valid->validation_table);
+            g_hash_table_insert(valid->validation_table, object_declaration, xmlNodeGetContent(cur_node));
+            if (g_hash_table_size(valid->validation_table) > count)
+            {
+                valid->valid_object_count++;
+                if (TRUE == qof_class_is_registered((QofIdTypeConst) object_declaration))
+                {
+                    valid->qof_registered_count++;
+                }
+            }
+        }
+    }
 }
 
 gboolean is_our_qsf_object(const gchar *path)
 {
-	xmlDocPtr doc;
-	struct qsf_node_iterate iter;
-	xmlNodePtr object_root;
-	qsf_validator valid;
-	gint table_count;
+    xmlDocPtr doc;
+    struct qsf_node_iterate iter;
+    xmlNodePtr object_root;
+    qsf_validator valid;
+    gint table_count;
 
-	g_return_val_if_fail((path != NULL),FALSE);
-	doc = xmlParseFile(path);
-	if(doc == NULL)  { return FALSE; }
-	if(TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc)) { 
-		PINFO (" validation failed %s %s %s", QSF_SCHEMA_DIR, 
-			QSF_OBJECT_SCHEMA, path);
-		xmlFreeDoc(doc);
-		return FALSE; 
-	}
-	object_root = xmlDocGetRootElement(doc);
-	/* check that all objects in the file are already registered in QOF */
-	valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
-	valid.qof_registered_count = 0;
-	valid.valid_object_count = 0;
-	iter.ns = object_root->ns;
-	qsf_valid_foreach(object_root, qsf_object_validation_handler, &iter, &valid);
-	table_count = g_hash_table_size(valid.validation_table);
-	g_hash_table_destroy(valid.validation_table);
-	if(table_count == valid.qof_registered_count) { return TRUE; }
-	return FALSE;
+    g_return_val_if_fail((path != NULL), FALSE);
+    doc = xmlParseFile(path);
+    if (doc == NULL)
+    {
+        return FALSE;
+    }
+    if (TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc))
+    {
+        PINFO (" validation failed %s %s %s", QSF_SCHEMA_DIR,
+               QSF_OBJECT_SCHEMA, path);
+        xmlFreeDoc(doc);
+        return FALSE;
+    }
+    object_root = xmlDocGetRootElement(doc);
+    /* check that all objects in the file are already registered in QOF */
+    valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
+    valid.qof_registered_count = 0;
+    valid.valid_object_count = 0;
+    iter.ns = object_root->ns;
+    qsf_valid_foreach(object_root, qsf_object_validation_handler, &iter, &valid);
+    table_count = g_hash_table_size(valid.validation_table);
+    g_hash_table_destroy(valid.validation_table);
+    if (table_count == valid.qof_registered_count)
+    {
+        return TRUE;
+    }
+    return FALSE;
 }
 
 gboolean is_qsf_object(const gchar *path)
 {
-	xmlDocPtr doc;
+    xmlDocPtr doc;
 
-	g_return_val_if_fail((path != NULL),FALSE);
-	if(path == NULL) { return FALSE; }
-	doc = xmlParseFile(path);
-	if(doc == NULL) { return FALSE; }
-	if(TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc)) {
-		xmlFreeDoc(doc);
-	    return FALSE;
-	}
-	xmlFreeDoc(doc);
-	/* Note cannot test against a map here, so if the file is valid QSF,
-	accept it and work out the details later. */
-	return TRUE;
+    g_return_val_if_fail((path != NULL), FALSE);
+    if (path == NULL)
+    {
+        return FALSE;
+    }
+    doc = xmlParseFile(path);
+    if (doc == NULL)
+    {
+        return FALSE;
+    }
+    if (TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc))
+    {
+        xmlFreeDoc(doc);
+        return FALSE;
+    }
+    xmlFreeDoc(doc);
+    /* Note cannot test against a map here, so if the file is valid QSF,
+    accept it and work out the details later. */
+    return TRUE;
 }
 
 gboolean is_our_qsf_object_be(qsf_param *params)
 {
-	xmlDocPtr doc;
-	struct qsf_node_iterate iter;
-	xmlNodePtr object_root;
-	qsf_validator valid;
-	gint table_count;
-	gchar *path;
+    xmlDocPtr doc;
+    struct qsf_node_iterate iter;
+    xmlNodePtr object_root;
+    qsf_validator valid;
+    gint table_count;
+    gchar *path;
 
-	g_return_val_if_fail((params != NULL),FALSE);
-	path = g_strdup(params->filepath);
-	if(path == NULL) {
-		qof_backend_set_error(params->be, ERR_FILEIO_FILE_NOT_FOUND);
-		return FALSE;
-	}
-	if(params->file_type != QSF_UNDEF) { return FALSE; }
-	doc = xmlParseFile(path);
-	if(doc == NULL)  {
-		qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
-		return FALSE;
-	}
-	if(TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc))
-	{
-		qof_backend_set_error(params->be, ERR_QSF_INVALID_OBJ);
-		return FALSE;
-	}
-	params->file_type = IS_QSF_OBJ;
-	object_root = xmlDocGetRootElement(doc);
-	valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
-	valid.qof_registered_count = 0;
-	iter.ns = object_root->ns;
-	qsf_valid_foreach(object_root, qsf_object_validation_handler, &iter, &valid);
-	table_count = g_hash_table_size(valid.validation_table);
-	if(table_count == valid.qof_registered_count)
-	{
-		g_hash_table_destroy(valid.validation_table);
-		qof_backend_set_error(params->be, ERR_BACKEND_NO_ERR);
-		return TRUE;
-	}
-	g_hash_table_destroy(valid.validation_table);
-	qof_backend_set_error(params->be, ERR_QSF_NO_MAP);
-	return FALSE;
+    g_return_val_if_fail((params != NULL), FALSE);
+    path = g_strdup(params->filepath);
+    if (path == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_FILE_NOT_FOUND);
+        return FALSE;
+    }
+    if (params->file_type != QSF_UNDEF)
+    {
+        return FALSE;
+    }
+    doc = xmlParseFile(path);
+    if (doc == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
+        return FALSE;
+    }
+    if (TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc))
+    {
+        qof_backend_set_error(params->be, ERR_QSF_INVALID_OBJ);
+        return FALSE;
+    }
+    params->file_type = IS_QSF_OBJ;
+    object_root = xmlDocGetRootElement(doc);
+    valid.validation_table = g_hash_table_new(g_str_hash, g_str_equal);
+    valid.qof_registered_count = 0;
+    iter.ns = object_root->ns;
+    qsf_valid_foreach(object_root, qsf_object_validation_handler, &iter, &valid);
+    table_count = g_hash_table_size(valid.validation_table);
+    if (table_count == valid.qof_registered_count)
+    {
+        g_hash_table_destroy(valid.validation_table);
+        qof_backend_set_error(params->be, ERR_BACKEND_NO_ERR);
+        return TRUE;
+    }
+    g_hash_table_destroy(valid.validation_table);
+    qof_backend_set_error(params->be, ERR_QSF_NO_MAP);
+    return FALSE;
 }
 
 gboolean is_qsf_object_be(qsf_param *params)
 {
-	gboolean result;
-	xmlDocPtr doc;
-	GList *maps;
-	gchar *path;
+    gboolean result;
+    xmlDocPtr doc;
+    GList *maps;
+    gchar *path;
 
-	g_return_val_if_fail((params != NULL),FALSE);
-	path = g_strdup(params->filepath);
-	if(path == NULL) {
-		qof_backend_set_error(params->be, ERR_FILEIO_FILE_NOT_FOUND);
-		return FALSE;
-	}
-	/* skip validation if is_our_qsf_object has already been called. */
-	if(ERR_QSF_INVALID_OBJ == qof_backend_get_error(params->be)) { return FALSE; }
-	if(params->file_type == QSF_UNDEF)
-	{
-		doc = xmlParseFile(path);
-		if(doc == NULL) {
-			qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
-			return FALSE;
-		}
-		if(TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc))
-		{
-			qof_backend_set_error(params->be, ERR_QSF_INVALID_OBJ);
-			return FALSE;
-		}
-	}
-	result = FALSE;
-	/* retrieve list of maps from config frame. */
-	for(maps = params->map_files; maps; maps=maps->next)
-	{
+    g_return_val_if_fail((params != NULL), FALSE);
+    path = g_strdup(params->filepath);
+    if (path == NULL)
+    {
+        qof_backend_set_error(params->be, ERR_FILEIO_FILE_NOT_FOUND);
+        return FALSE;
+    }
+    /* skip validation if is_our_qsf_object has already been called. */
+    if (ERR_QSF_INVALID_OBJ == qof_backend_get_error(params->be))
+    {
+        return FALSE;
+    }
+    if (params->file_type == QSF_UNDEF)
+    {
+        doc = xmlParseFile(path);
+        if (doc == NULL)
+        {
+            qof_backend_set_error(params->be, ERR_FILEIO_PARSE_ERROR);
+            return FALSE;
+        }
+        if (TRUE != qsf_is_valid(QSF_SCHEMA_DIR, QSF_OBJECT_SCHEMA, doc))
+        {
+            qof_backend_set_error(params->be, ERR_QSF_INVALID_OBJ);
+            return FALSE;
+        }
+    }
+    result = FALSE;
+    /* retrieve list of maps from config frame. */
+    for (maps = params->map_files; maps; maps = maps->next)
+    {
         QofBackendError err;
-		result = is_qsf_object_with_map_be(maps->data, params);
+        result = is_qsf_object_with_map_be(maps->data, params);
         err = qof_backend_get_error(params->be);
-        if((err == ERR_BACKEND_NO_ERR) && result) 
+        if ((err == ERR_BACKEND_NO_ERR) && result)
         {
             params->map_path = maps->data;
             PINFO ("map chosen = %s", params->map_path);
             break;
         }
         /* pop the error back on the stack. */
-        else { qof_backend_set_error(params->be, err); }
-	}
-	return result;
+        else
+        {
+            qof_backend_set_error(params->be, err);
+        }
+    }
+    return result;
 }
 
 static void
 qsf_supported_data_types(gpointer type, gpointer user_data)
 {
-	qsf_param *params;
+    qsf_param *params;
 
-	g_return_if_fail(user_data != NULL);
-	g_return_if_fail(type != NULL);
-	params = (qsf_param*) user_data;
-	if(qsf_is_element(params->param_node, params->qsf_ns, (gchar*)type))
-	{
-		g_hash_table_insert(params->qsf_parameter_hash,
-			xmlGetProp(params->param_node, BAD_CAST QSF_OBJECT_TYPE), params->param_node);
-	}
+    g_return_if_fail(user_data != NULL);
+    g_return_if_fail(type != NULL);
+    params = (qsf_param*) user_data;
+    if (qsf_is_element(params->param_node, params->qsf_ns, (gchar*)type))
+    {
+        g_hash_table_insert(params->qsf_parameter_hash,
+                            xmlGetProp(params->param_node, BAD_CAST QSF_OBJECT_TYPE), params->param_node);
+    }
 }
 
 static void
 qsf_parameter_handler(xmlNodePtr child, xmlNsPtr qsf_ns, qsf_param *params)
 {
-	params->param_node = child;
-	g_slist_foreach(params->supported_types, qsf_supported_data_types, params);
+    params->param_node = child;
+    g_slist_foreach(params->supported_types, qsf_supported_data_types, params);
 }
 
 void
 qsf_object_node_handler(xmlNodePtr child, xmlNsPtr qsf_ns, qsf_param *params)
 {
-	struct qsf_node_iterate iter;
-	qsf_objects *object_set;
-	gchar *tail, *object_count_s;
-	gint64 c;
+    struct qsf_node_iterate iter;
+    qsf_objects *object_set;
+    gchar *tail, *object_count_s;
+    gint64 c;
 
-	g_return_if_fail(child != NULL);
-	g_return_if_fail(qsf_ns != NULL);
-	params->qsf_ns = qsf_ns;
-	if(qsf_is_element(child, qsf_ns, QSF_OBJECT_TAG)) {
-		params->qsf_parameter_hash = NULL;
-		c = 0;
-		object_set = g_new(qsf_objects, 1);
-		params->object_set = object_set;
-		object_set->object_count = 0;
-		object_set->parameters = g_hash_table_new(g_str_hash, g_str_equal);
-		object_set->object_type = g_strdup((gchar*)xmlGetProp(child, 
-			BAD_CAST QSF_OBJECT_TYPE));
-		object_count_s = g_strdup((gchar*)xmlGetProp(child, 
-			BAD_CAST QSF_OBJECT_COUNT));
-		c = (gint64)strtol(object_count_s, &tail, 0);
-		object_set->object_count = (gint)c;
-		g_free(object_count_s);
-		params->qsf_object_list = g_list_prepend(params->qsf_object_list, object_set);
-		iter.ns = qsf_ns;
-		params->qsf_parameter_hash = object_set->parameters;
-		qsf_node_foreach(child, qsf_parameter_handler, &iter, params);
-	}
+    g_return_if_fail(child != NULL);
+    g_return_if_fail(qsf_ns != NULL);
+    params->qsf_ns = qsf_ns;
+    if (qsf_is_element(child, qsf_ns, QSF_OBJECT_TAG))
+    {
+        params->qsf_parameter_hash = NULL;
+        c = 0;
+        object_set = g_new(qsf_objects, 1);
+        params->object_set = object_set;
+        object_set->object_count = 0;
+        object_set->parameters = g_hash_table_new(g_str_hash, g_str_equal);
+        object_set->object_type = g_strdup((gchar*)xmlGetProp(child,
+                                           BAD_CAST QSF_OBJECT_TYPE));
+        object_count_s = g_strdup((gchar*)xmlGetProp(child,
+                                  BAD_CAST QSF_OBJECT_COUNT));
+        c = (gint64)strtol(object_count_s, &tail, 0);
+        object_set->object_count = (gint)c;
+        g_free(object_count_s);
+        params->qsf_object_list = g_list_prepend(params->qsf_object_list, object_set);
+        iter.ns = qsf_ns;
+        params->qsf_parameter_hash = object_set->parameters;
+        qsf_node_foreach(child, qsf_parameter_handler, &iter, params);
+    }
 }
 
 void
 qsf_book_node_handler(xmlNodePtr child, xmlNsPtr ns, qsf_param *params)
 {
-	gchar *book_count_s, *tail;
-	gint book_count;
-	xmlNodePtr child_node;
-	struct qsf_node_iterate iter;
-	gchar *buffer;
-	GUID book_guid;
+    gchar *book_count_s, *tail;
+    gint book_count;
+    xmlNodePtr child_node;
+    struct qsf_node_iterate iter;
+    gchar *buffer;
+    GUID book_guid;
 
-	g_return_if_fail(child);
-	g_return_if_fail(params);
-	ENTER (" child=%s", child->name);
-	if(qsf_is_element(child, ns, QSF_BOOK_TAG)) {
-		book_count_s = (gchar*)xmlGetProp(child, BAD_CAST QSF_BOOK_COUNT);
-		if(book_count_s) {
-			book_count = (gint)strtol(book_count_s, &tail, 0);
-			/* More than one book not currently supported. */
-			g_return_if_fail(book_count == 1);
-		}
-		iter.ns = ns;
-		child_node = child->children->next;
-		if(qsf_is_element(child_node, ns, QSF_BOOK_GUID)) {
-			DEBUG (" trying to set book GUID");
-			buffer = g_strdup((gchar*)xmlNodeGetContent(child_node));
-			g_return_if_fail(TRUE == string_to_guid(buffer, &book_guid));
-			qof_instance_set_guid(QOF_INSTANCE(params->book), &book_guid);
-			xmlNewChild(params->output_node, params->qsf_ns, 
-			BAD_CAST QSF_BOOK_GUID, BAD_CAST buffer);
-			g_free(buffer);
-		}
-		qsf_node_foreach(child, qsf_object_node_handler, &iter, params);
-	}
+    g_return_if_fail(child);
+    g_return_if_fail(params);
+    ENTER (" child=%s", child->name);
+    if (qsf_is_element(child, ns, QSF_BOOK_TAG))
+    {
+        book_count_s = (gchar*)xmlGetProp(child, BAD_CAST QSF_BOOK_COUNT);
+        if (book_count_s)
+        {
+            book_count = (gint)strtol(book_count_s, &tail, 0);
+            /* More than one book not currently supported. */
+            g_return_if_fail(book_count == 1);
+        }
+        iter.ns = ns;
+        child_node = child->children->next;
+        if (qsf_is_element(child_node, ns, QSF_BOOK_GUID))
+        {
+            DEBUG (" trying to set book GUID");
+            buffer = g_strdup((gchar*)xmlNodeGetContent(child_node));
+            g_return_if_fail(TRUE == string_to_guid(buffer, &book_guid));
+            qof_instance_set_guid(QOF_INSTANCE(params->book), &book_guid);
+            xmlNewChild(params->output_node, params->qsf_ns,
+                        BAD_CAST QSF_BOOK_GUID, BAD_CAST buffer);
+            g_free(buffer);
+        }
+        qsf_node_foreach(child, qsf_object_node_handler, &iter, params);
+    }
     LEAVE (" ");
 }

Modified: gnucash/trunk/src/libqof/backend/file/qsf-xml.h
===================================================================
--- gnucash/trunk/src/libqof/backend/file/qsf-xml.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/libqof/backend/file/qsf-xml.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -21,8 +21,8 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
- #ifndef QSF_XML_H
- #define QSF_XML_H
+#ifndef QSF_XML_H
+#define QSF_XML_H
 
 /** @file qsf-xml.h
     @brief  Private QSF header - not for use by applications
@@ -38,28 +38,29 @@
 #include <libintl.h>
 #define _(String) dgettext (GETTEXT_PACKAGE, String)
 
-typedef enum  {
-	QSF_UNDEF = 0, /**< Initial undefined value. */
-	IS_QSF_MAP,   /**< A QSF map */
-	IS_QSF_OBJ,   /**< A QSF object without a map - it may or may not need one. */
-	HAVE_QSF_MAP, /**< A QSF object with the map it needs. */
-	OUR_QSF_OBJ,  /**< A QSF object that can be loaded without a map. */
-}qsf_type;
+typedef enum
+{
+    QSF_UNDEF = 0, /**< Initial undefined value. */
+    IS_QSF_MAP,   /**< A QSF map */
+    IS_QSF_OBJ,   /**< A QSF object without a map - it may or may not need one. */
+    HAVE_QSF_MAP, /**< A QSF object with the map it needs. */
+    OUR_QSF_OBJ,  /**< A QSF object that can be loaded without a map. */
+} qsf_type;
 
 /** \brief Holds a description of the QofObject.
 
 Used when converting QOF objects from another application. The incoming,
-\b unknown, objects need to be stored prior to conversion. This allows 
+\b unknown, objects need to be stored prior to conversion. This allows
 many-to-many conversions where an invoice can receive data from an incoming
 expense AND datebook and use data from an incoming contacts object to lookup
 the customer for the invoice.
 */
 typedef struct qsf_object_set
 {
-	GHashTable *parameters;
-	QofIdType object_type;
-	gint object_count;
-}qsf_objects;
+    GHashTable *parameters;
+    QofIdType object_type;
+    gint object_count;
+} qsf_objects;
 
 #define QSF_QOF_VERSION QOF_OBJECT_VERSION /**< QOF Version check.
 
@@ -72,315 +73,315 @@
 #define QSF_DEFAULT_NS	"http://qof.sourceforge.net/" /**< Default namespace for QSF root tag
 
 The map namespace is not included as maps are not currently written out by QOF.
-*/
+            */
 #define QSF_DATE_LENGTH MAX_DATE_LENGTH /**< Max length of QSF_XSD_TIME.
 
-MAX_DATE_LENGTH itself is defined in gnc-date.h */
+            MAX_DATE_LENGTH itself is defined in gnc-date.h */
 #define QSF_BOOK_TAG	"book"      /**< First level child: book tag - the ::QofBook. */
 #define QSF_BOOK_GUID	"book-guid" /**< QOF GUID tag for the QofBook
-					described by this QSF object file */
+            described by this QSF object file */
 #define QSF_BOOK_COUNT	"count"     /**< Sequential counter of each book in this file */
 #define QSF_OBJECT_TAG	"object"    /**< Second level child: object tag */
 #define QSF_OBJECT_TYPE	"type"      /**< QSF parameter name for object type specifiers */
 #define QSF_OBJECT_COUNT "count"    /**< Sequential counter for each QSF object
-					in this file */
+            in this file */
 #define QSF_XML_VERSION  "1.0"      /**< The current XML version. */
 
-/** @} */
-/** @name Representing KVP as XML
+            /** @} */
+            /** @name Representing KVP as XML
 
-&lt;kvp type="kvp" path="/from-sched-xaction" value="guid"&gt;c858b9a3235723b55bc1179f0e8c1322&lt;/kvp&gt;
-A kvp type KVP parameter located at $path containing a GUID $value.
+            &lt;kvp type="kvp" path="/from-sched-xaction" value="guid"&gt;c858b9a3235723b55bc1179f0e8c1322&lt;/kvp&gt;
+            A kvp type KVP parameter located at $path containing a GUID $value.
 
-The relevance of type="kvp" won't be evident in GnuCash, they all use "kvp".
+            The relevance of type="kvp" won't be evident in GnuCash, they all use "kvp".
 
-A non-GnuCash example helps:
-&lt;kvp type="pilot_addr_kvp" path="/user/name" value="guid"&gt;c858b9a3235723b55bc1179f0e8c1322&lt;/kvp&gt;
-A pilot_addr_kvp type KVP parameter located at /user/name containing a guid value.
-@{ */
+            A non-GnuCash example helps:
+            &lt;kvp type="pilot_addr_kvp" path="/user/name" value="guid"&gt;c858b9a3235723b55bc1179f0e8c1322&lt;/kvp&gt;
+            A pilot_addr_kvp type KVP parameter located at /user/name containing a guid value.
+            @{ */
 
 #define QSF_OBJECT_KVP   "path" /**< The path to this KVP value in the entity frame. */
 #define QSF_OBJECT_VALUE "value" /**< The KVP Value. */
-/** @} */
-/** @name QSF Map XML
+            /** @} */
+            /** @name QSF Map XML
 
-@{ */
+            @{ */
 #define MAP_ROOT_TAG     "qsf-map" /**< Top level root tag for QSF Maps */
 #define MAP_DEFINITION_TAG "definition" /**< Second level container for defined objects 
 
-Attributes: qof_version - Taken from the QOF_OBJECT_VERSION macro in QOF,
-At the time of QSF development, QOF_OBJECT_VERSION is defined as 3. All
-QSF maps and QSF objects must use the same qof_version which in turn must
-match the QOF_OBJECT_VERSION for the QOF library in use by the calling process.
+            Attributes: qof_version - Taken from the QOF_OBJECT_VERSION macro in QOF,
+            At the time of QSF development, QOF_OBJECT_VERSION is defined as 3. All
+            QSF maps and QSF objects must use the same qof_version which in turn must
+            match the QOF_OBJECT_VERSION for the QOF library in use by the calling process.
 
-No text content allowed.
-*/
+            No text content allowed.
+            */
 #define MAP_DEFINE_TAG	"define" /**< defines each object supported by this QSF map 
 
-Attributes: e_type Copied directly from the QofObject definition.
-Content: The full QofObject description for the defined QOF object.
-*/
+            Attributes: e_type Copied directly from the QofObject definition.
+            Content: The full QofObject description for the defined QOF object.
+                */
 #define MAP_ITERATE_ATTR "foreach" /**< Dictate which object type is the basis
-for iteration in a hierarchical object set. */
+                for iteration in a hierarchical object set. */
 #define MAP_DEFAULT_TAG	"default"  /**< User editable defaults for data not
-available within the available QSF objects.
+                    available within the available QSF objects.
 
-Some defaults will relate to how to format descriptive dates, whether discount
-should be considered, which account to use for certain QSF data from applications
-that do not use accounts.
+                    Some defaults will relate to how to format descriptive dates, whether discount
+                    should be considered, which account to use for certain QSF data from applications
+                        that do not use accounts.
 
-Some defaults are pre-defined and cannot be over-written:
-- qsf_time_now
-- qsf_time_string
+                            Some defaults are pre-defined and cannot be over-written:
+                            - qsf_time_now
+                            - qsf_time_string
 
-Attributes (All are mandatory): 
+                            Attributes (All are mandatory):
 
-\a name The text name for this default. Certain pre-defined defaults exist but
-user- or map-defined defaults can have any unique text name. Spaces are \b NOT allowed, 
-use undersccores instead. The value of name must not duplicate any existing default,
-define, object or parameter unless the special type, enum, is used.
+                                \a name The text name for this default. Certain pre-defined defaults exist but
+                                user- or map-defined defaults can have any unique text name. Spaces are \b NOT allowed,
+                                use undersccores instead. The value of name must not duplicate any existing default,
+                                define, object or parameter unless the special type, enum, is used.
 
-\a type QOF_TYPE - must be one of the recognised QOF data types for the
-qof_version in use or the special type, enum.
+                                \a type QOF_TYPE - must be one of the recognised QOF data types for the
+                                    qof_version in use or the special type, enum.
 
-\a value Text representation of the required value. For numeric, use the format
-[0-9]?/[0-9]?
+                                    \a value Text representation of the required value. For numeric, use the format
+                                    [0-9]?/[0-9]?
 
-\attention Using boolean defaults 
+                                        \attention Using boolean defaults
 
-A boolean default is not output in the QSF directly, instead the value is
-used in the calculations to modify certain values. If the boolean default
-is set to true, the if statement containing the boolean name will be evaluated.
-If the boolean default is set to false, the corresponding else will be evaluted.
-Make sure your calculations contain an appropriate else statement so that the
-boolean value can be adjusted without invalidating the map!
+                                    A boolean default is not output in the QSF directly, instead the value is
+                                        used in the calculations to modify certain values. If the boolean default
+                                                is set to true, the if statement containing the boolean name will be evaluated.
+                                            If the boolean default is set to false, the corresponding else will be evaluted.
+                                                        Make sure your calculations contain an appropriate else statement so that the
+                                                            boolean value can be adjusted without invalidating the map!
 
-QSF deals with partial QofBooks - each object is fully described but the
-book does not have to contain any specific object types or have any
-particular structure. To merge partial books into usual QofBook data
-sources, the map must deal with entities that need to be referenced in
-the target QofBook but which simply do not exist in the QofBook used to generate
-the QSF. e.g. pilot-link knows nothing of Accounts yet when QSF creates
-a gncInvoice from qof-datebook, gncInvoice needs to know the GUID of 
-certain accounts in the target QofBook. This is handled in the map 
-by specifying the name of the account as a default for that map. When imported,
-the QSF QofBackend looks up the object required using the name of
-the parameter to obtain the parameter type. This is the only situation
-where QSF converts between QOF data types. A string description of the
-required object is converted to the GUID for that specific entity. The
-map cannot contain the GUID as it is generic and used by multiple users.
+                                                            QSF deals with partial QofBooks - each object is fully described but the
+                                                            book does not have to contain any specific object types or have any
+                                                            particular structure. To merge partial books into usual QofBook data
+                                                            sources, the map must deal with entities that need to be referenced in
+                                                            the target QofBook but which simply do not exist in the QofBook used to generate
+                                                                the QSF. e.g. pilot-link knows nothing of Accounts yet when QSF creates
+                                                                a gncInvoice from qof-datebook, gncInvoice needs to know the GUID of
+                                                                certain accounts in the target QofBook. This is handled in the map
+                                                            by specifying the name of the account as a default for that map. When imported,
+                                                                        the QSF QofBackend looks up the object required using the name of
+                                                                        the parameter to obtain the parameter type. This is the only situation
+                                                                        where QSF converts between QOF data types. A string description of the
+                                                                        required object is converted to the GUID for that specific entity. The
+                                                                            map cannot contain the GUID as it is generic and used by multiple users.
 
-\attention Using enumerators
-- enum types are the only defaults that are allowed to use the same name value
-more than once. 
-- enum types are used to increase the readability of a QSF map.
-- The enum name acts to group the enum values together - in a similar fashion to
-radio buttons in HTML forms. 
-- enum types are used only where the QOF object itself uses an enum type. 
+                                                                            \attention Using enumerators
+                                                                            - enum types are the only defaults that are allowed to use the same name value
+                                                                            more than once.
+                                                                            - enum types are used to increase the readability of a QSF map.
+                                                                            - The enum name acts to group the enum values together - in a similar fashion to
+                                                                            radio buttons in HTML forms.
+                                                                            - enum types are used only where the QOF object itself uses an enum type.
 
-e.g. the tax_included enum type allows maps to use the full name of the enum
-value GNC_TAXINCLUDED_YES, instead of the cryptic digit value, 1.
+                                                                            e.g. the tax_included enum type allows maps to use the full name of the enum
+                                                                            value GNC_TAXINCLUDED_YES, instead of the cryptic digit value, 1.
 
-*/
+                                                                            */
 #define MAP_OBJECT_TAG	"object" /**< Contains all the calculations to make one
-object from others.
+                                                                            object from others.
 
-Note that creating an object for the import application can involve using data
-from more than one QSF object, as well as defaults and lookups in the import
-application itself. Conditionals, simple arithmetic and date/time formatting 
-options are also available.
-*/
+                                                                            Note that creating an object for the import application can involve using data
+                                                                                from more than one QSF object, as well as defaults and lookups in the import
+                                                                                application itself. Conditionals, simple arithmetic and date/time formatting
+                                                                                options are also available.
+                                                                                */
 #define MAP_CALCULATE_TAG	"calculate" /**< One calculation for every parameter
-that needs to be set.
+                                                                                that needs to be set.
 
-QSF follows the same rule as qof_book_merge. Only if a getter and a setter
-function are defined for a parameter is it available to QSF. If a ::QofAccessFunc 
-and ::QofSetterFunc are both defined for any QofObject parameter, that parameter 
-\b MUST be calculated in any map that defines that object.
-*/
+                                                                                QSF follows the same rule as qof_book_merge. Only if a getter and a setter
+                                                                                    function are defined for a parameter is it available to QSF. If a ::QofAccessFunc
+                                                                                        and ::QofSetterFunc are both defined for any QofObject parameter, that parameter
+                                                                                            \b MUST be calculated in any map that defines that object.
+                                                                                            */
 #define MAP_QOF_VERSION	"qof_version" /**< This is the QOF_OBJECT_VERSION from QOF.
 
-QSF maps may need to be updated if QOF itself is upgraded. This setting is coded
-into QOF and maps for one version cannot necessarily be used by other versions.
-At the first release of QSF, QOF_OBJECT_VERSION = 3.
-*/
+                                                                                            QSF maps may need to be updated if QOF itself is upgraded. This setting is coded
+                                                                                                into QOF and maps for one version cannot necessarily be used by other versions.
+                                                                                                    At the first release of QSF, QOF_OBJECT_VERSION = 3.
+                                                                                                            */
 #define MAP_NAME_ATTR	"name" /**< The name of the default setting.
 
-Use this name to refer to the value of this default in the map calculations.
+                                                                                                        Use this name to refer to the value of this default in the map calculations.
 
-Make sure that the type of this default matches the type of the parameter being
-set by the parent calculation!
-*/
+                                                                                                            Make sure that the type of this default matches the type of the parameter being
+                                                                                                                    set by the parent calculation!
+                                                                                                                    */
 #define MAP_TYPE_ATTR	"type" /**< QSF will NOT convert between QOF types.
 
-QSF will allow a conditional to use a parameter of one type to determine the
-value from a parameter of another type, but the final value assigned \b MUST be
-of the same type as the parent calculation.
-*/
+                                                                                                                    QSF will allow a conditional to use a parameter of one type to determine the
+                                                                                                                    value from a parameter of another type, but the final value assigned \b MUST be
+                                                                                                                    of the same type as the parent calculation.
+                                                                                                                    */
 #define MAP_VALUE_ATTR	"value" /**< The value of the tag, used in defaults and
-calculations.
+                                                                                                                    calculations.
 
-The value of a default is a string representation of the value to be inserted into
-the calculation where the default is used.
+                                                                                                                The value of a default is a string representation of the value to be inserted into
+                                                                                                                    the calculation where the default is used.
 
-The value of a calculation is the name of the parameter that will be set by that
-calculation.
-*/
+                                                                                                                            The value of a calculation is the name of the parameter that will be set by that
+                                                                                                                            calculation.
+                                                                                                                            */
 #define MAP_OBJECT_ATTR "object" /**< The object to use to provide the data
-being set using the map.*/
+                                                                                                                            being set using the map.*/
 #define MAP_E_TYPE	"e_type" /**< Validates the objects defined in the map 
 
-The e_type will be used to match incoming QSF objects with the relevant QSF map.
-The value of the e_type must be the value of the e_type for that object in the
-originating QOF application. The define tag must contain the value of the description
-of the same object in the same originating QOF application.
-*/
-/** \todo enum is an attempt to make enumerator values descriptive in the maps
-and QSF (possibly). Not working yet. */
+                                                                                                                            The e_type will be used to match incoming QSF objects with the relevant QSF map.
+                                                                                                                            The value of the e_type must be the value of the e_type for that object in the
+                                                                                                                                originating QOF application. The define tag must contain the value of the description
+                                                                                                                                of the same object in the same originating QOF application.
+                                                                                                                                */
+                                                                                                                                /** \todo enum is an attempt to make enumerator values descriptive in the maps
+                                                                                                                                and QSF (possibly). Not working yet. */
 #define MAP_ENUM_TYPE "enum"
 
-/** \brief A specific boolean default for this map.
-*/
+                                                                                                                                /** \brief A specific boolean default for this map.
+                                                                                                                                */
 #define QSF_BOOLEAN_DEFAULT "boolean"
 
 #define QSF_CONDITIONAL "if"  /**< child of calculate.
 
-Conditionals can reference objects as if within the original application. In operation,
-the map is overlaid across both sets of defined objects, an import object in the source 
-application and an output object for the destination object. The current import and output 
-QSF objects are therefore always available to the map. 
-Conditionals can reference parameter as well as object values.
-*/
+                                                                                                                                Conditionals can reference objects as if within the original application. In operation,
+                                                                                                                                    the map is overlaid across both sets of defined objects, an import object in the source
+                                                                                                                                    application and an output object for the destination object. The current import and output
+                                                                                                                                        QSF objects are therefore always available to the map.
+                                                                                                                                        Conditionals can reference parameter as well as object values.
+                                                                                                                                        */
 #define QSF_CONDITIONAL_SET "set" /**< Assignment statement
 
-Map assignments can use the native values within the output object. The output object
-must support setting the relevant parameter using the value exactly as given in the map 
-because the relevant set() function will be called using this value. This may reduce the 
-readability of the map but the relevant application could also be modified to support
-a more readable set function.
-*/
+                                                                                                                                        Map assignments can use the native values within the output object. The output object
+                                                                                                                                        must support setting the relevant parameter using the value exactly as given in the map
+                                                                                                                                        because the relevant set() function will be called using this value. This may reduce the
+                                                                                                                                            readability of the map but the relevant application could also be modified to support
+                                                                                                                                            a more readable set function.
+                                                                                                                                            */
 #define QSF_CONDITIONAL_ELSE "else" /**< Alternative
 
-if(){} else{} is also supported. Nesting of conditionals causes problems for
-validating the final map against any sensible XML Schema and a map that does not 
-validate will be rejected. When editing conditionals in a QSF map, ALWAYS 
-validate the map using xmllint. If necessary, define a variable at the foot of 
-the definitions block, using a similar syntax to a default, then use that 
+                                                                                                                                    if(){} else{} is also supported. Nesting of conditionals causes problems for
+validating the final map against any sensible XML Schema and a map that does not
+validate will be rejected. When editing conditionals in a QSF map, ALWAYS
+validate the map using xmllint. If necessary, define a variable at the foot of
+the definitions block, using a similar syntax to a default, then use that
 variable in another conditional
 
 \a variable \a name="my_rate" \a type="numeric" \a value="0/1"
 
-The syntax for xmllint is:
+                                      The syntax for xmllint is:
 
 \a xmllint \a --schema \a &lt;schema file&gt; \a &lt;qsf-file&gt;
 
 Use the qsf-object.xsd.xml schema for objects and qsf-map.xsd.xml for map files.
 
-e.g. xmllint --schema qsf-object.xsd.xml --noout qof-qsf.xml
+    e.g. xmllint --schema qsf-object.xsd.xml --noout qof-qsf.xml
 
-*/
+    */
 #define QSF_OPTION "option" /**< enum operator
 
-Not implemented yet - may need to change once work starts.
-Theoretically, option will specify when an enumerator value is in use -
-it is quite possible that it will be unnecessary.
-*/
+    Not implemented yet - may need to change once work starts.
+    Theoretically, option will specify when an enumerator value is in use -
+    it is quite possible that it will be unnecessary.
+    */
 
 #define QSF_FORMATTING_OPTION "format" /**< How to format dates/times
 
-When the QSF map uses a date/time value as a \b string, the formatting
-can be adjusted to personal preference. \a format will only be evaluated
-if the calculated parameter is a QOF_TYPE_STRING - any format attributes
-on other data types will be ignored.
- */
+    When the QSF map uses a date/time value as a \b string, the formatting
+    can be adjusted to personal preference. \a format will only be evaluated
+    if the calculated parameter is a QOF_TYPE_STRING - any format attributes
+        on other data types will be ignored.
+        */
 
-/** @} */
+        /** @} */
 
 #define QSF_XSD_TIME  QOF_UTC_DATE_FORMAT /**< xsd:dateTime format in coordinated
-universal time, UTC.
+        universal time, UTC.
 
-You can reproduce the string from the GNU/Linux command line using the date utility: 
+You can reproduce the string from the GNU/Linux command line using the date utility:
 
 date -u +%Y-%m-%dT%H:%M:%SZ
 
-2004-12-12T23:39:11Z
+        2004-12-12T23:39:11Z
 
-The datestring must be timezone independent and include all specified fields.
+        The datestring must be timezone independent and include all specified fields.
 
-Remember to use gmtime() NOT localtime()!. From the command line, use the
+        Remember to use gmtime() NOT localtime()!. From the command line, use the
 -u switch with the date command: date -u
 
-To generate a timestamp based on a real time, use the qsf_time_now and
-qsf_time_string defaults.
+            To generate a timestamp based on a real time, use the qsf_time_now and
+            qsf_time_string defaults.
 
 qsf_time_now : Format: QOF_TYPE_DATE. The current time taken from the moment
-the default is read into a QSF object at runtime.
+        the default is read into a QSF object at runtime.
 
-qsf_time_string : Format: QOF_TYPE_STRING. The current timestamp taken from the 
-moment the default is read into a QSF object at runtime. This form is used when 
-the output parameter needs a formatted date string, not an actual date object. 
-The format is determined by the optional format attribute of the set tag which 
-takes the same operators as the GNU C Library for strftime() and output may therefore 
-be dependent on the locale of the calling process - \b take \b care. Default value 
-is %F, used when qsf_time_string is set without the format attribute.
+qsf_time_string : Format: QOF_TYPE_STRING. The current timestamp taken from the
+moment the default is read into a QSF object at runtime. This form is used when
+the output parameter needs a formatted date string, not an actual date object.
+The format is determined by the optional format attribute of the set tag which
+takes the same operators as the GNU C Library for strftime() and output may therefore
+        be dependent on the locale of the calling process - \b take \b care. Default value
+        is %F, used when qsf_time_string is set without the format attribute.
 
-Both defaults use UTC.
+        Both defaults use UTC.
 
-*/
+        */
 #define QSF_XML_BOOLEAN_TEST "true" /**< needs to be lowercase for XML validation */
 
 #define QSF_OBJECT_SCHEMA "qsf-object.xsd.xml" /**< Name of the QSF Object Schema. */
 #define QSF_MAP_SCHEMA "qsf-map.xsd.xml" /**< Name of the QSF Map Schema. */
-/** \brief QSF Parameters
+        /** \brief QSF Parameters
 
-This struct is a catch-all for all parameters required
-for various stages of the process. There are lots of elements
-here that will finally be removed.
-*/
-typedef struct qsf_metadata
-{
-	qsf_type file_type;          /**< what type of file is being handled */
-	qsf_objects *object_set;     /**< current object set for qsf_object_list. */
-	gint count;                  /**< sequential counter for each object in the book */
-	GList *qsf_object_list;      /**< list of qsf_objects */
-	GSList *qsf_sequence;        /**< Parameter list sorted into QSF order */
-	GList *referenceList;        /**< Table of references, ::QofInstanceReference. */
-	GHashTable *qsf_parameter_hash; /**< Hashtable of parameters for each object */
-	GHashTable *qsf_calculate_hash, *qsf_default_hash, *qsf_define_hash;
-	GSList *supported_types;     /**< The list of QOF types currently supported, in QSF order. */
-	xmlDocPtr input_doc;         /**< Pointer to the input xml document(s). */
-	xmlDocPtr output_doc;        /**< Pointer to the output xml document(s). */
-	xmlNodePtr child_node;       /**< The current child_node. */
-	xmlNodePtr convert_node;     /**< Node in the converted object */
-	xmlNodePtr param_node;       /**< Node for parameter data. */
-	xmlNodePtr output_node;      /**< Node in the output document. */
-	xmlNodePtr output_root;      /**< Root node of the output document. */
-	xmlNodePtr book_node;        /**< Node for the book. */
-	xmlNodePtr lister;           /**< Comparison node for map defaults. */
-	xmlNsPtr qsf_ns, map_ns;     /**< Separate namespaces for QSF objects and QSF maps. */
-	const gchar *qof_type;       /**< Holds details of the QOF_TYPE */
-	QofIdType qof_obj_type;	     /**< current QofObject type (e_type) for the parameters. */
-	QofIdType qof_foreach;       /**< How to iterate over hierarchical entities. */
-	gint foreach_limit;          /**< How many iterations are found in the QSF */
-	QofInstance *qsf_ent;          /**< Current entity in the book. */
-	QofBackend *be;              /**< the current QofBackend for this operation. */
-	gboolean knowntype;          /**< detect references by comparing with known QOF types. */
-	QofParam *qof_param;         /**< used by kvp to handle the frame hash table */
-	QofBook *book;	             /**< the current QofBook.
+        This struct is a catch-all for all parameters required
+        for various stages of the process. There are lots of elements
+        here that will finally be removed.
+        */
+        typedef struct qsf_metadata
+        {
+            qsf_type file_type;          /**< what type of file is being handled */
+            qsf_objects *object_set;     /**< current object set for qsf_object_list. */
+            gint count;                  /**< sequential counter for each object in the book */
+            GList *qsf_object_list;      /**< list of qsf_objects */
+            GSList *qsf_sequence;        /**< Parameter list sorted into QSF order */
+            GList *referenceList;        /**< Table of references, ::QofInstanceReference. */
+            GHashTable *qsf_parameter_hash; /**< Hashtable of parameters for each object */
+            GHashTable *qsf_calculate_hash, *qsf_default_hash, *qsf_define_hash;
+            GSList *supported_types;     /**< The list of QOF types currently supported, in QSF order. */
+            xmlDocPtr input_doc;         /**< Pointer to the input xml document(s). */
+            xmlDocPtr output_doc;        /**< Pointer to the output xml document(s). */
+            xmlNodePtr child_node;       /**< The current child_node. */
+            xmlNodePtr convert_node;     /**< Node in the converted object */
+            xmlNodePtr param_node;       /**< Node for parameter data. */
+            xmlNodePtr output_node;      /**< Node in the output document. */
+            xmlNodePtr output_root;      /**< Root node of the output document. */
+            xmlNodePtr book_node;        /**< Node for the book. */
+            xmlNodePtr lister;           /**< Comparison node for map defaults. */
+            xmlNsPtr qsf_ns, map_ns;     /**< Separate namespaces for QSF objects and QSF maps. */
+            const gchar *qof_type;       /**< Holds details of the QOF_TYPE */
+            QofIdType qof_obj_type;	     /**< current QofObject type (e_type) for the parameters. */
+            QofIdType qof_foreach;       /**< How to iterate over hierarchical entities. */
+            gint foreach_limit;          /**< How many iterations are found in the QSF */
+            QofInstance *qsf_ent;          /**< Current entity in the book. */
+            QofBackend *be;              /**< the current QofBackend for this operation. */
+            gboolean knowntype;          /**< detect references by comparing with known QOF types. */
+            QofParam *qof_param;         /**< used by kvp to handle the frame hash table */
+            QofBook *book;	             /**< the current QofBook.
 
 		Theoretically, QSF can handle multiple QofBooks - currently limited to 1.
 	*/
-	gint boolean_calculation_done; /**< simple trip once this boolean is complete. */
-	gchar *filepath;              /**< Path to the QSF file. */
-	gchar *map_path;              /**< Path to best match map, if any. */
-	gchar* full_kvp_path;         /**< Full path for each KvpValue written out. */
-	gint64 use_gz_level;          /**< Default compression level. */
-	GList *map_files;             /**< List of selected map files for this session.
+            gint boolean_calculation_done; /**< simple trip once this boolean is complete. */
+            gchar *filepath;              /**< Path to the QSF file. */
+            gchar *map_path;              /**< Path to best match map, if any. */
+            gchar* full_kvp_path;         /**< Full path for each KvpValue written out. */
+            gint64 use_gz_level;          /**< Default compression level. */
+            GList *map_files;             /**< List of selected map files for this session.
 
 	Defaults to the pre-installed QSF maps, currently: pilot-qsf-GnuCashInvoice.xml
 	*/
-	const gchar *encoding;        /**< Backend encoding option - defaults to UTF-8. */ 
-}qsf_param;
+            const gchar *encoding;        /**< Backend encoding option - defaults to UTF-8. */
+        } qsf_param;
 
 /** \brief Validation metadata
 
@@ -389,14 +390,14 @@
 */
 typedef struct qsf_validates
 {
-	QofBackendError error_state;
-	const gchar *object_path;
-	const gchar *map_path;
-	GHashTable *validation_table;
-	gint valid_object_count;
-	gint map_calculated_count;
-	gint qof_registered_count;
-}qsf_validator;
+    QofBackendError error_state;
+    const gchar *object_path;
+    const gchar *map_path;
+    GHashTable *validation_table;
+    gint valid_object_count;
+    gint map_calculated_count;
+    gint qof_registered_count;
+} qsf_validator;
 
 /** \brief shorthand function
 
@@ -493,10 +494,11 @@
 
 \todo resolve the two callbacks in ::qsf_node_iterate into one.
 */
-struct qsf_node_iterate {
-	qsf_nodeCB *fcn;
-	qsf_validCB *v_fcn;
-	xmlNsPtr ns;
+struct qsf_node_iterate
+{
+    qsf_nodeCB *fcn;
+    qsf_validCB *v_fcn;
+    xmlNsPtr ns;
 };
 
 /** \brief Validate a QSF file and identify a suitable QSF map
@@ -505,7 +507,7 @@
 
 These functions are in pairs. When called from within a QofSession, the qsf_param
 context will be available. When just determining the type of file, qsf_param is
-not necessary. Use the *_be functions from within the QofBackend and the 
+not necessary. Use the *_be functions from within the QofBackend and the
 corresponding function in other code.
 
 The file is validated against the QSF object schema, qsf-object.xsd.xml and
@@ -523,7 +525,7 @@
 
 These functions are in pairs. When called from within a QofSession, the qsf_param
 context will be available. When just determining the type of file, qsf_param is
-not necessary. Use the *_be functions from within the QofBackend and the 
+not necessary. Use the *_be functions from within the QofBackend and the
 corresponding function in other code.
 
 The file is validated against the QSF object schema, qsf-object.xsd.xml and
@@ -583,7 +585,7 @@
 
 These functions are in pairs. When called from within a QofSession, the qsf_param
 context will be available. When just determining the type of file, qsf_param is
-not necessary. Use the *_be functions from within the QofBackend and the 
+not necessary. Use the *_be functions from within the QofBackend and the
 corresponding function in other code.
 
 The file is validated aginst the QSF map schema, qsf-map.xsd.xsml. This
@@ -658,7 +660,7 @@
 */
 void
 qsf_valid_foreach(xmlNodePtr parent, qsf_validCB cb,
-	struct qsf_node_iterate *iter, qsf_validator *valid);
+                  struct qsf_node_iterate *iter, qsf_validator *valid);
 
 /** Iterate over the children of the parent node.
 
@@ -667,7 +669,7 @@
 */
 void
 qsf_node_foreach(xmlNodePtr parent, qsf_nodeCB cb,
-	struct qsf_node_iterate *iter, qsf_param *params);
+                 struct qsf_node_iterate *iter, qsf_param *params);
 
 /** \brief Convert between QSF objects
 
@@ -678,7 +680,7 @@
 @param qsf_root The top node of the QSF object to be converted using the map.
 @param params The QSF backend parameters.
 
-Each calculation in the map is performed over the child nodes of the 
+Each calculation in the map is performed over the child nodes of the
 object tree. A new xmlDoc is created and this is made available to QOF to
 be loaded into the book.
 

Modified: gnucash/trunk/src/libqof/qof/gnc-date.c
===================================================================
--- gnucash/trunk/src/libqof/qof/gnc-date.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/libqof/qof/gnc-date.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -448,7 +448,7 @@
         tm_str.tm_mday = day;
         tm_str.tm_mon = month - 1;    /* tm_mon = 0 through 11 */
         tm_str.tm_year = year - 1900; /* this is what the standard
-                                 * says, it's not a Y2K thing */
+				       * says, it's not a Y2K thing */
 
         gnc_tm_set_day_start (&tm_str);
         t = mktime (&tm_str);

Modified: gnucash/trunk/src/libqof/qof/qofbackend.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbackend.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/libqof/qof/qofbackend.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -525,7 +525,7 @@
         module_init_func();
 
     g_module_make_resident(backend);
-	backend_module_list = g_slist_prepend( backend_module_list, backend );
+    backend_module_list = g_slist_prepend( backend_module_list, backend );
     return TRUE;
 }
 
@@ -533,17 +533,18 @@
 qof_finalize_backend_libraries(void)
 {
     GSList* node;
-	GModule* backend;
+    GModule* backend;
     void (*module_finalize_func) (void);
 
-	for (node = backend_module_list; node != NULL; node = node->next) {
-	    backend = (GModule*)node->data;
+    for (node = backend_module_list; node != NULL; node = node->next)
+    {
+        backend = (GModule*)node->data;
 
         if (g_module_symbol(backend, "qof_backend_module_finalize",
-                        (gpointer)&module_finalize_func))
+                            (gpointer)&module_finalize_func))
             module_finalize_func();
 
-	}
+    }
 }
 
 /************************* END OF FILE ********************************/

Modified: gnucash/trunk/src/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/libqof/qof/qofbook.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -445,17 +445,17 @@
 {
     const char *opt;
     kvp_value *kvp_val;
-    
-    
-    kvp_val = kvp_frame_get_slot_path (qof_book_get_slots (book), 
-                                       BOOK_OPTIONS_NAME, 
+
+
+    kvp_val = kvp_frame_get_slot_path (qof_book_get_slots (book),
+                                       BOOK_OPTIONS_NAME,
                                        ACCOUNT_OPTIONS_SECTION,
                                        TRADING_ACCOUNTS_OPTION, NULL);
     if (kvp_val == NULL)
         return FALSE;
-    
+
     opt = kvp_value_get_string (kvp_val);
-    
+
     if (opt && opt[0] == 't' && opt[1] == 0)
         return TRUE;
     return FALSE;

Modified: gnucash/trunk/src/libqof/qof/qofbookslots.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbookslots.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/libqof/qof/qofbookslots.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -22,7 +22,7 @@
 /** @name Book parameter names
 
  * These define the names used for the slots used to store book level parameters.
- * They are defined here so swig will find them since they need to be available to 
+ * They are defined here so swig will find them since they need to be available to
  * Scheme code too.
  @{
 */

Modified: gnucash/trunk/src/libqof/qof/qofutil.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofutil.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/libqof/qof/qofutil.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -523,7 +523,7 @@
     qof_query_shutdown ();
     qof_object_shutdown ();
     guid_shutdown ();
-	qof_finalize_backend_libraries();
+    qof_finalize_backend_libraries();
     qof_util_string_cache_destroy ();
     qof_log_shutdown();
 }

Modified: gnucash/trunk/src/tax/us/gncmod-tax-us.c
===================================================================
--- gnucash/trunk/src/tax/us/gncmod-tax-us.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/tax/us/gncmod-tax-us.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -28,60 +28,64 @@
 
 
 char *
-libgncmod_tax_us_gnc_module_path(void) {
+libgncmod_tax_us_gnc_module_path(void)
+{
 #ifdef LOCALE_SPECIFIC_TAX
 # ifdef G_OS_WIN32
-  gchar *thislocale = g_win32_getlocale();
-  gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
-  g_free(thislocale);
+    gchar *thislocale = g_win32_getlocale();
+    gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
+    g_free(thislocale);
 # else /* !G_OS_WIN32 */
-  const char *thislocale = setlocale(LC_ALL, NULL);
-  gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
+    const char *thislocale = setlocale(LC_ALL, NULL);
+    gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
 # endif /* G_OS_WIN32 */
-  if (is_de_DE)
-     return g_strdup("gnucash/tax/de_DE");
-  else
-     return g_strdup("gnucash/tax/us");
+    if (is_de_DE)
+        return g_strdup("gnucash/tax/de_DE");
+    else
+        return g_strdup("gnucash/tax/us");
 #endif /* LOCALE_SPECIFIC_TAX */
-  return g_strdup("gnucash/tax/us");
+    return g_strdup("gnucash/tax/us");
 }
 
 char *
-libgncmod_tax_us_gnc_module_description(void) {
-  return g_strdup("US income tax information");
+libgncmod_tax_us_gnc_module_description(void)
+{
+    return g_strdup("US income tax information");
 }
 
 static void
 lmod(char * mn)
 {
-  char * form = g_strdup_printf("(use-modules %s)\n", mn);
-  scm_c_eval_string(form);
-  g_free(form);
+    char * form = g_strdup_printf("(use-modules %s)\n", mn);
+    scm_c_eval_string(form);
+    g_free(form);
 }
 
 int
-libgncmod_tax_us_gnc_module_init(int refcount) {
-  /* This is a very simple hack that loads the (new, special) German
-     tax definition file in a German locale, or (default) loads the
-     previous US tax file. */
+libgncmod_tax_us_gnc_module_init(int refcount)
+{
+    /* This is a very simple hack that loads the (new, special) German
+       tax definition file in a German locale, or (default) loads the
+       previous US tax file. */
 #ifdef LOCALE_SPECIFIC_TAX
 # ifdef G_OS_WIN32
-  gchar *thislocale = g_win32_getlocale();
-  gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
-  g_free(thislocale);
+    gchar *thislocale = g_win32_getlocale();
+    gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
+    g_free(thislocale);
 # else /* !G_OS_WIN32 */
-  const char *thislocale = setlocale(LC_ALL, NULL);
-  gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
+    const char *thislocale = setlocale(LC_ALL, NULL);
+    gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
 # endif /* G_OS_WIN32 */
-  if (is_de_DE)
-    lmod("(gnucash tax de_DE)");
-  else
+    if (is_de_DE)
+        lmod("(gnucash tax de_DE)");
+    else
 #endif /* LOCALE_SPECIFIC_TAX */
-    lmod("(gnucash tax us)");
-  return TRUE;
+        lmod("(gnucash tax us)");
+    return TRUE;
 }
 
 int
-libgncmod_tax_us_gnc_module_end(int refcount) {
-  return TRUE;
+libgncmod_tax_us_gnc_module_end(int refcount)
+{
+    return TRUE;
 }

Modified: gnucash/trunk/src/tax/us/test/test-link-module.c
===================================================================
--- gnucash/trunk/src/tax/us/test/test-link-module.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/tax/us/test/test-link-module.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -1,6 +1,6 @@
 int
-main(int argc, char ** argv) 
+main(int argc, char ** argv)
 {
-  return 0;
+    return 0;
 }
 

Modified: gnucash/trunk/src/test-core/gncmod-test.c
===================================================================
--- gnucash/trunk/src/test-core/gncmod-test.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/test-core/gncmod-test.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -23,21 +23,25 @@
 
 
 char *
-libgncmod_test_gnc_module_path(void) {
-  return g_strdup("gnucash/test");
+libgncmod_test_gnc_module_path(void)
+{
+    return g_strdup("gnucash/test");
 }
 
 char *
-libgncmod_test_gnc_module_description(void) {
-  return g_strdup("Basic GnuCash test infrastructure.");
+libgncmod_test_gnc_module_description(void)
+{
+    return g_strdup("Basic GnuCash test infrastructure.");
 }
 
 int
-libgncmod_test_gnc_module_init(int refcount) {
-  return TRUE;
+libgncmod_test_gnc_module_init(int refcount)
+{
+    return TRUE;
 }
 
 int
-libgncmod_test_gnc_module_end(int refcount) {
-  return TRUE;
+libgncmod_test_gnc_module_end(int refcount)
+{
+    return TRUE;
 }

Modified: gnucash/trunk/src/test-core/test-stuff.c
===================================================================
--- gnucash/trunk/src/test-core/test-stuff.c	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/test-core/test-stuff.c	2009-12-29 20:12:48 UTC (rev 18535)
@@ -21,18 +21,18 @@
 #include "test-stuff.h"
 
 void vsuccess_args(
-		const char *test_title,
-		const char *file,
-		int line,
-		const char *format,
-		va_list ap);
+    const char *test_title,
+    const char *file,
+    int line,
+    const char *format,
+    va_list ap);
 
 void vfailure_args(
-		const char *test_title,
-		const char *file,
-		int line,
-		const char *format,
-		va_list ap);
+    const char *test_title,
+    const char *file,
+    int line,
+    const char *format,
+    va_list ap);
 
 static guint successes;
 static guint failures;
@@ -40,81 +40,82 @@
 
 void
 success_call(
-		const char *test_title,
-		const char* file,
-		int line )
+    const char *test_title,
+    const char* file,
+    int line )
 {
-	success_args( test_title, file, line, "" );
+    success_args( test_title, file, line, "" );
 }
 
 void
 success_args(
-		const char *test_title,
-		const char *file,
-		int line,
-		const char *format,
-		... )
+    const char *test_title,
+    const char *file,
+    int line,
+    const char *format,
+    ... )
 {
-	va_list ap;
-	va_start(ap,format);
-	vsuccess_args( test_title, file, line, format, ap );
-	va_end(ap);
+    va_list ap;
+    va_start(ap, format);
+    vsuccess_args( test_title, file, line, format, ap );
+    va_end(ap);
 }
 
 void
 vsuccess_args(
-		const char *test_title,
-		const char *file,
-		int line,
-		const char *format,
-		va_list ap)
+    const char *test_title,
+    const char *file,
+    int line,
+    const char *format,
+    va_list ap)
 {
-	if( success_should_print ) {
-		printf("SUCCESS: %s, %s:%d ", test_title, file, line );
-		vprintf(format, ap);
-		printf("\n");
-		fflush(stdout);
-	}
-	++successes;
+    if ( success_should_print )
+    {
+        printf("SUCCESS: %s, %s:%d ", test_title, file, line );
+        vprintf(format, ap);
+        printf("\n");
+        fflush(stdout);
+    }
+    ++successes;
 }
 
 void
 failure_call(
-		const char *test_title,
-		const char *file,
-		int line)
+    const char *test_title,
+    const char *file,
+    int line)
 {
-	failure_args( test_title, file, line, "" );
+    failure_args( test_title, file, line, "" );
 }
 
 
 void
 failure_args(
-		const char *test_title,
-		const char *file,
-		int line,
-		const char *format,
-		... )
+    const char *test_title,
+    const char *file,
+    int line,
+    const char *format,
+    ... )
 {
-	va_list ap;
-	va_start(ap,format);
-	vfailure_args( test_title, file, line, format, ap );
-	va_end(ap);
+    va_list ap;
+    va_start(ap, format);
+    vfailure_args( test_title, file, line, format, ap );
+    va_end(ap);
 }
 void
 vfailure_args(
-		const char *test_title,
-		const char* file,
-		int line,
-		const char *format,
-		va_list ap)
+    const char *test_title,
+    const char* file,
+    int line,
+    const char *format,
+    va_list ap)
 {
-	printf("FAILURE %s %s:%d ", test_title, file, line );
-	vprintf(format, ap);
-	printf("\n");
-	fflush(stdout);
+    printf("FAILURE %s %s:%d ", test_title, file, line );
+    vprintf(format, ap);
+    printf("\n");
+    fflush(stdout);
 
-	++failures;
+    ++failures;
 }
 
 int
@@ -127,112 +128,124 @@
 do_test_call(gboolean result, const char* test_title, const char* filename,
              int line )
 {
-	if (result)
-		success_args( test_title, filename, line, "" );
-        else
-		failure_args( test_title, filename, line, "" );
+    if (result)
+        success_args( test_title, filename, line, "" );
+    else
+        failure_args( test_title, filename, line, "" );
 
-	return result;
+    return result;
 }
 
 gboolean
 do_test_args(
-	gboolean result,
-	const char* test_title,
-	const char* filename,
-	int line,
-	const char* format,
-	... )
+    gboolean result,
+    const char* test_title,
+    const char* filename,
+    int line,
+    const char* format,
+    ... )
 {
-	va_list ap;
-	va_start(ap, format);
+    va_list ap;
+    va_start(ap, format);
 
-	if( result ) {
-		vsuccess_args( test_title, filename, line, format, ap );
-	} else {
-		vfailure_args( test_title, filename, line, format, ap );
-	}
-	va_end(ap);
+    if ( result )
+    {
+        vsuccess_args( test_title, filename, line, format, ap );
+    }
+    else
+    {
+        vfailure_args( test_title, filename, line, format, ap );
+    }
+    va_end(ap);
 
-	return result;
+    return result;
 }
 
 void
 print_test_results(void)
 {
-	guint total = successes+failures;
-	if( total == 1 ) {
-		printf( "Executed 1 test." );
-	} else {
-		printf("Executed %d tests.", successes+failures );
-	}
-	if( failures ) {
-		if( failures == 1 ) {
-			printf(" There was 1 failure." );
-		} else {
-			printf(" There were %d failures.", failures );
-		}
-	} else {
-		printf(" All tests passed.");
-	}
-	printf("\n");
-	fflush(stdout);
+    guint total = successes + failures;
+    if ( total == 1 )
+    {
+        printf( "Executed 1 test." );
+    }
+    else
+    {
+        printf("Executed %d tests.", successes + failures );
+    }
+    if ( failures )
+    {
+        if ( failures == 1 )
+        {
+            printf(" There was 1 failure." );
+        }
+        else
+        {
+            printf(" There were %d failures.", failures );
+        }
+    }
+    else
+    {
+        printf(" All tests passed.");
+    }
+    printf("\n");
+    fflush(stdout);
 }
 
 void
 set_success_print( gboolean in_should_print )
 {
-	success_should_print = in_should_print;
+    success_should_print = in_should_print;
 }
 
 gboolean
 get_random_boolean(void)
 {
-  return get_random_int_in_range (0, 1);
+    return get_random_int_in_range (0, 1);
 }
 
 gint
 get_random_int_in_range(int start, int end)
 {
-  return CLAMP (start + (int)((double)(end - start + 1) * rand() /
-                              (RAND_MAX + 1.0)),
-                start,
-                end);
+    return CLAMP (start + (int)((double)(end - start + 1) * rand() /
+                                (RAND_MAX + 1.0)),
+                  start,
+                  end);
 }
 
 static char *random_chars = NULL;
 
 static char plain_chars[] =
-"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-"abcdefghijklmnopqrstuvwxyz"
-"1234567890"
-" ";
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+    "abcdefghijklmnopqrstuvwxyz"
+    "1234567890"
+    " ";
 
 static char funky_chars[] =
-",.'\"`~!@#$%^*(){}[]/=?+-_\\|"
-"<>&"
-"\n\t";
+    ",.'\"`~!@#$%^*(){}[]/=?+-_\\|"
+    "<>&"
+    "\n\t";
 
 static int rcend = 0;
 
 void
 random_character_include_funky_chars (gboolean use_funky_chars)
 {
-  g_free (random_chars);
+    g_free (random_chars);
 
-  if (use_funky_chars)
-    random_chars = g_strconcat (plain_chars, funky_chars, NULL);
-  else
-    random_chars = g_strdup (plain_chars);
+    if (use_funky_chars)
+        random_chars = g_strconcat (plain_chars, funky_chars, NULL);
+    else
+        random_chars = g_strdup (plain_chars);
 
-  rcend = strlen (random_chars) - 1;
+    rcend = strlen (random_chars) - 1;
 }
 
 gchar
 get_random_character(void)
 {
     if (!rcend)
-      random_character_include_funky_chars (TRUE);
+        random_character_include_funky_chars (TRUE);
 
     return random_chars[get_random_int_in_range(0, rcend)];
 }
@@ -242,12 +255,12 @@
 {
     gchar *ret;
     int i, len = get_random_int_in_range(minlen, maxlen);
-    
+
     ret = g_new0(gchar, len);
 
     for (i = 0; i < len - 1; i++)
         ret[i] = get_random_character ();
-    
+
     return g_strstrip(ret);
 }
 
@@ -258,15 +271,15 @@
     int len;
     int i;
 
-    switch(get_random_int_in_range(0, 9))
+    switch (get_random_int_in_range(0, 9))
     {
-/*     case 0: */
-/*         return ""; */
-/*     case 1: */
-/*         return NULL; */
-/*     case 2: */
-/*         len = get_random_int_in_range(1000, 5000); */
-/*         break; */
+        /*     case 0: */
+        /*         return ""; */
+        /*     case 1: */
+        /*         return NULL; */
+        /*     case 2: */
+        /*         len = get_random_int_in_range(1000, 5000); */
+        /*         break; */
     case 3:
         len = get_random_int_in_range(100, 500);
         break;
@@ -283,7 +296,8 @@
         do
         {
             c = get_random_character ();
-        } while (exclude_chars && strchr (exclude_chars, c));
+        }
+        while (exclude_chars && strchr (exclude_chars, c));
 
         ret[i] = c;
     }
@@ -294,7 +308,7 @@
 gchar *
 get_random_string(void)
 {
-  return get_random_string_without (NULL);
+    return get_random_string_without (NULL);
 }
 
 gint64
@@ -305,7 +319,7 @@
     ret = rand();
     ret <<= 32;
     ret += rand();
-    
+
     return ret;
 }
 
@@ -313,11 +327,11 @@
 get_random_double(void)
 {
     double d;
-	guint  i;
+    guint  i;
 
-	i = (guint)get_random_int_in_range(8,13);
-	/* using 0.9 and 7 increases chances of getting lots of decimals */
-    d = ((double)get_random_int_in_range(8,999999) * i * 0.9 / 7);
+    i = (guint)get_random_int_in_range(8, 13);
+    /* using 0.9 and 7 increases chances of getting lots of decimals */
+    d = ((double)get_random_int_in_range(8, 999999) * i * 0.9 / 7);
     return d;
 }
 
@@ -326,10 +340,10 @@
 {
     int num;
 
-	 /* count number of items in list */
-    for(num = 0; str_list[num] != NULL; num++)
+    /* count number of items in list */
+    for (num = 0; str_list[num] != NULL; num++)
         ;
-	 
-	 num = get_random_int_in_range(0, num-1);
-	 return str_list[num];
+
+    num = get_random_int_in_range(0, num - 1);
+    return str_list[num];
 }

Modified: gnucash/trunk/src/test-core/test-stuff.h
===================================================================
--- gnucash/trunk/src/test-core/test-stuff.h	2009-12-29 06:13:26 UTC (rev 18534)
+++ gnucash/trunk/src/test-core/test-stuff.h	2009-12-29 20:12:48 UTC (rev 18535)
@@ -57,16 +57,16 @@
  * wish, but it's easier to use the do_test macro above.
  */
 gboolean do_test_call(
-		gboolean result,
-		const char* test_title,
-		const char* filename,
-		int line );
+    gboolean result,
+    const char* test_title,
+    const char* filename,
+    int line );
 gboolean do_test_args(
-		gboolean result,
-		const char* test_title,
-		const char* filename,
-		int line,
-		const char* format, ... );
+    gboolean result,
+    const char* test_title,
+    const char* filename,
+    int line,
+    const char* format, ... );
 
 
 /**
@@ -93,28 +93,28 @@
  * a test into different forks of the code.
  */
 void success_call(
-		const char *test_title,
-		const char *file,
-		int line );
+    const char *test_title,
+    const char *file,
+    int line );
 
 void success_args(
-		const char *test_title,
-		const char *file,
-		int line,
-		const char *format,
-		... );
+    const char *test_title,
+    const char *file,
+    int line,
+    const char *format,
+    ... );
 
 void failure_call(
-		const char *test_title,
-		const char *file,
-		int line);
+    const char *test_title,
+    const char *file,
+    int line);
 
 void failure_args(
-		const char *test_title,
-		const char *file,
-		int line,
-		const char *format,
-		... );
+    const char *test_title,
+    const char *file,
+    int line,
+    const char *format,
+    ... );
 
 gboolean get_random_boolean(void);
 gint get_random_int_in_range(int start, int end);



More information about the gnucash-changes mailing list