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
-