daily diff

Dave Peticolas dave@krondo.com
Thu, 10 May 2001 13:44:42 -0700


This is a diff of gnucash development in the last 25 hours.
The diff is being posted for code review.


Index: gnucash/ChangeLog
diff -u gnucash/ChangeLog:1.436 gnucash/ChangeLog:1.443
--- gnucash/ChangeLog:1.436	Wed May  9 03:55:25 2001
+++ gnucash/ChangeLog	Thu May 10 11:06:09 2001
@@ -1,5 +1,69 @@
+2001-05-10  James LewisMoss  <jimdres@mindspring.com>
+
+	* src/scm/main.scm ((gnc:main)): remove the main window startup
+	with new user startup (moved to end of new user stuff).
+
+	* src/engine/sql/PostgresBackend.c (pgendGetAllAccountKVP): same
+	as below.
+
+	* src/engine/rpc/RpcUtils.c (rpcend_build_gncacctlist): 
+	xaccGroupForEachAccountDeeply -> xaccGroupForEachAccount(...TRUE)
+	(rpcend_build_gncacct_verslist): same.
+
+	* src/engine/gnc-book.c (gnc_book_set_group): free account group
+	when setting new one.
+
+	* src/engine/Group.c (xaccGroupForEachAccount): change from
+	xaccGroupForEachAccountDeeply and add argument on whether it
+	should do things deeply.
+
+	* src/engine/Account.c (xaccCloneAccountSimple): new func.
+	(xaccAccountEnumAsString): change arg to GNCAccountType.
+
+	* src/gnc-ui-util.c (gnc_ui_account_get_balance):
+	xaccGroupForEachAccountDeeply -> xaccGroupForEachAccount(...TRUE)
+
+	* src/engine/Account.c (xaccAccountGetChildren): Add children
+	group if ->children == NULL.
+
+2001-05-10  Dave Peticolas  <dave@krondo.com>
+
+	* src/guile/File.c (gncFindFile): handle NULL arg
+	(gncReadFile): use glib mem routines
+
+	* src/doc/design/engine.texinfo: update docs
+
+	* src/scm/command-line.scm: fix bugs
+
+	* src/engine/kvp_frame.c: handle NULL args
+
+2001-05-10  Christian Stimming  <stimming@tuhh.de>
+
+	* src/scm/report/account-summary.scm, balance-sheet.scm, pnl.scm:
+	moved foreign currency display option to display tab.
+
+	* src/scm/html-utilities.scm
+	(gnc:html-acct-table-comm-row-helper!): fixed display bug.
+
+	* src/engine/gnc-pricedb.c (gnc_pricedb_lookup_nearest_in_time):
+	Fixed this function so that it works properly now.
+
+	* src/scm/commodity-utilities.scm
+	(gnc:get-match-commodity-splits): fix bug.
+
 2001-05-09  Dave Peticolas  <dave@krondo.com>
 
+	* src/doc/design/engine.texinfo: update docs
+
+	* src/engine/*.[ch]: add GPL headers
+
+2001-05-09  Christian Stimming  <stimming@tuhh.de>
+
+	* src/scm/report/price-scatter.scm: use the configurable report
+	title.
+
+2001-05-09  Dave Peticolas  <dave@krondo.com>
+
 	* src/doc/design/user-preferences.texinfo: update docs
 
 	* src/doc/design/reports.texinfo: update docs
@@ -618,6 +682,11 @@
 	between html & txf
 
 	* src/gnome/window-report.c: implement export callback
+
+2001-04-19  James LewisMoss  <jimdres@mindspring.com>
+
+	* src/gnome/new-user-funs.c (gnc_new_user_get_clist): new func to
+	remove duplicate code.
 
 2001-04-18  Dave Peticolas  <dave@krondo.com>
 
Index: gnucash/accounts/C/acctchrt_brokerage.gnucash-xea
diff -u gnucash/accounts/C/acctchrt_brokerage.gnucash-xea:1.1 gnucash/accounts/C/acctchrt_brokerage.gnucash-xea:1.2
--- gnucash/accounts/C/acctchrt_brokerage.gnucash-xea:1.1	Wed Apr 18 16:25:55 2001
+++ gnucash/accounts/C/acctchrt_brokerage.gnucash-xea	Wed May  9 20:58:49 2001
@@ -7,6 +7,11 @@
       Brokerage account with related investment accounts
         (stock, bond, mutual fund, index fund, interest, dividend)
     </gnc-act:short-description>
+    <gnc-act:long-description>
+    You would want to select these set of accounts if you have
+    investments (stock, bond, mutual fund, index fund, interest,
+    dividend)
+  </gnc-act:long-description>    
 <gnc:account version="2.0.0">
   <act:name>Assets</act:name>
   <act:id type="new">52b5942b5beaec856eaca5a75ee71592</act:id>
Index: gnucash/accounts/C/acctchrt_carloan.gnucash-xea
diff -u gnucash/accounts/C/acctchrt_carloan.gnucash-xea:1.1 gnucash/accounts/C/acctchrt_carloan.gnucash-xea:1.2
--- gnucash/accounts/C/acctchrt_carloan.gnucash-xea:1.1	Wed Apr 18 16:25:55 2001
+++ gnucash/accounts/C/acctchrt_carloan.gnucash-xea	Wed May  9 20:59:22 2001
@@ -40,14 +40,14 @@
   <act:parent type="new">023e2343114b3d695feaeb96904e0da6</act:parent>
 </gnc:account>
 <gnc:account version="2.0.0">
-  <act:name>Expense</act:name>
+  <act:name>Expenses</act:name>
   <act:id type="new">acacdcb998e45fb741766622e8542f0b</act:id>
   <act:type>EXPENSE</act:type>
   <act:currency>
     <cmdty:space>ISO4217</cmdty:space>
     <cmdty:id>USD</cmdty:id>
   </act:currency>
-  <act:description>Expense</act:description>
+  <act:description>Expenses</act:description>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Interest</act:name>
Index: gnucash/src/FileDialog.c
diff -u gnucash/src/FileDialog.c:1.61 gnucash/src/FileDialog.c:1.62
--- gnucash/src/FileDialog.c:1.61	Thu May  3 02:56:36 2001
+++ gnucash/src/FileDialog.c	Wed May  9 19:12:42 2001
@@ -67,18 +67,52 @@
 
     case ERR_BACKEND_NO_BACKEND:
       fmt = _("The URL \n    %s\n"
-               "is not supported by this version of GnuCash.");
+              "is not supported by this version of GnuCash.");
       buf = g_strdup_printf (fmt, newfile);
       gnc_error_dialog (buf);
       break;
 
+    case ERR_BACKEND_BAD_URL:
+      fmt = _("Can't parse the URL\n   %s\n");
+      buf = g_strdup_printf (fmt, newfile);
+      gnc_error_dialog (buf);
+      break;
+
+    case ERR_BACKEND_CANT_CONNECT:
+      fmt = _("Can't connect to\n   %s\n"
+              "The host, username or password were incorrect.");
+      buf = g_strdup_printf (fmt, newfile);
+      gnc_error_dialog (buf);
+      break;
+
+    case ERR_BACKEND_CONN_LOST:
+      fmt = _("Can't connect to\n   %s\n"
+              "Connection was lost, unable to send data.");
+      buf = g_strdup_printf (fmt, newfile);
+      gnc_error_dialog (buf);
+      break;
+
     case ERR_BACKEND_LOCKED:
       fmt = _("The URL \n    %s\n"
-               "is in use by another user.");
+              "is in use by another user.");
       buf = g_strdup_printf (fmt, newfile);
       gnc_error_dialog (buf);
       break;
 
+    case ERR_BACKEND_DATA_CORRUPT:
+      fmt = _("The URL \n    %s\n"
+              "does not contain GnuCash data or the data is corrupt.");
+      buf = g_strdup_printf (fmt, newfile);
+      gnc_error_dialog (buf);
+      break;
+
+    case ERR_BACKEND_SERVER_ERR:
+      fmt = _("The server at URL \n    %s\n"
+              "experienced an error or encountered bad or corrupt data.");
+      buf = g_strdup_printf (fmt, newfile);
+      gnc_error_dialog (buf);
+      break;
+
     case ERR_BACKEND_MISC:
       fmt = _("An error occurred while processing\n    %s\n");
       buf = g_strdup_printf (fmt, newfile);
@@ -122,19 +156,6 @@
       gnc_error_dialog(buf);
       break;
       
-    case ERR_SQL_BAD_LOCATION:
-      fmt = _("Can't parse the database URL\n   %s\n");
-      buf = g_strdup_printf (fmt, newfile);
-      gnc_error_dialog (buf);
-      break;
-
-    case ERR_SQL_CANT_CONNECT:
-      fmt = _("Can't connect to the database\n   %s\n"
-              "The host, username or password were incorrect.");
-      buf = g_strdup_printf (fmt, newfile);
-      gnc_error_dialog (buf);
-      break;
-
     default:
       PERR("FIXME: Unhandled error %d", io_error);
       fmt = _("An unknown I/O error occurred.");
Index: gnucash/src/gnc-ui-util.c
diff -u gnucash/src/gnc-ui-util.c:1.28 gnucash/src/gnc-ui-util.c:1.29
--- gnucash/src/gnc-ui-util.c:1.28	Mon Apr 30 01:55:57 2001
+++ gnucash/src/gnc-ui-util.c	Thu May 10 11:11:16 2001
@@ -245,7 +245,7 @@
 
     children = xaccAccountGetChildren (account);
 
-    xaccGroupForEachAccountDeeply (children, balance_helper, &cb);
+    xaccGroupForEachAccount (children, balance_helper, &cb, TRUE);
 
     balance = cb.balance;
   }
Index: gnucash/src/doc/design/engine.texinfo
diff -u gnucash/src/doc/design/engine.texinfo:1.29 gnucash/src/doc/design/engine.texinfo:1.31
--- gnucash/src/doc/design/engine.texinfo:1.29	Wed May  9 03:55:34 2001
+++ gnucash/src/doc/design/engine.texinfo	Thu May 10 04:32:57 2001
@@ -268,12 +268,16 @@
 @}
 @end example
 
-You can compare two GUIDs for equality with the following function.
+You can compare two GUIDs with the following functions.
 
 @deftypefun gboolean guid_equal(const GUID * @var{guid_1}, const GUID * @var{guid_2})
 Compare two guids and return TRUE if they are both non-NULL and equal.
 @end deftypefun
 
+@deftypefun gint guid_compare(const GUID * @var{g1}, const GUID * @var{g2})
+Return the @code{memcmp} of the two GUID's.
+@end deftypefun
+
 
 You can encode and decode GUIDs and their string representations using the
 next two functions.
@@ -286,6 +290,15 @@
 string should be freed when no longer needed.
 @end deftypefun
 
+@deftypefun {char *} guid_to_string_buff (const GUID * @var{guid}, char * @var{buff})
+This routine does the same work as @code{guid_to_string}, except that the
+string is written into the memory pointed at by @var{buff}. The
+buffer must be at least GUID_ENCODING_LENGTH+1 characters long.
+This routine is handy for avoiding a malloc/free cycle.
+It returns a pointer to the @emph{end} of what was written.
+(i.e. it can be used like @code{stpcpy} during string concatenation)
+@end deftypefun
+
 @deftypefun gboolean string_to_guid(const char * @var{string}, GUID * @var{guid})
 Given a string, decode an id into @var{guid} if @var{guid} is
 non-NULL. The function returns TRUE if the string was a valid 32
@@ -295,6 +308,34 @@
 @end deftypefun
 
 
+You can allocate and deallocate space for GUIDs using standard
+memory routines. However, if your code is allocating and deallocating
+lots of GUID objects, then the next two functions should be used.
+
+@deftypefun {GUID *} xaccGUIDMalloc (void)
+Return newly allocated memory for a GUID object. The memory must
+be freed with @code{xaccGUIDFree}. In general, this function is
+faster than using the standard libc allocators.
+@end deftypefun
+
+@deftypefun void xaccGUIDFree (GUID * @var{guid})
+Free the space for a GUID that was allocated with @code{xaccGUIDMalloc}.
+@end deftypefun
+
+
+You can use the following two functions to aid in using GUIDS in hash
+tables.
+
+@deftypefun guint guid_hash_to_guint(gconstpointer @var{ptr})
+Return a hash value suitable for use with a @code{GHashTable}.
+@var{ptr} must point to a GUID.
+@end deftypefun
+
+@deftypefun {GHashTable *} guid_hash_table_new(void)
+Return a new @code{GHashTable} which uses GUIDs as keys.
+@end deftypefun
+
+
 @node GUIDs and GnuCash Entities, The GUID Generator, How to use GUIDs, Globally Unique Identifiers
 @subsection GUIDs and GnuCash Entities
 
@@ -422,6 +463,10 @@
 @item GNC_DENOM_RECIPROCAL (n)
 Use the value @code{1/n} as the denominator of the output value.
 
+@item GNC_DENOM_SIGFIGS (n)
+Use a value for the denominator that will keep at least @code{n}
+significant figures in the result.
+
 @item GNC_DENOM_AUTO
 Compute an appropriate denominator automatically. Flags in the @var{how}
 argument will specify how to compute the denominator.
@@ -501,6 +546,10 @@
 denominator is to be used in the output, and an error is to be signaled
 if any argument has a different denominator.
 
+@item GNC_DENOM_SIGFIG
+Round to the number of significant figures given in the rounding
+instructions by the GNC_DENOM_SIGFIGS () macro.
+
 @end table
 
 
@@ -875,6 +924,12 @@
 Associate @var{key} with @var{value} in @var{frame}.
 @end deftypefun
 
+@deftypefun void kvp_frame_set_slot_nc(kvp_frame * @var{frame}, const char * @var{key}, kvp_value * @var{value})
+Same as @code{kvp_frame_set_slot}, except that @var{value} is used
+directly, instead of being copied. This call transfers 'ownership'
+of @var{value} to @var{frame}.
+@end deftypefun
+
 @deftypefun kvp_value* kvp_frame_get_slot(kvp_frame * @var{frame}, const char * @var{key})
 Return the @code{kvp_value} object associated with @var{key}
 in @var{frame} or return @code{NULL} if there is no association
@@ -901,6 +956,27 @@
 @deftypefun {kvp_value *} kvp_frame_get_slot_path_gslist (kvp_frame * @var{frame}, GSList * @var{key_path})
 Return the value associated with the key path, or @code{NULL} if none.
 The path is specified as in @code{kvp_frame_set_slot_path_gslist}.
+@end deftypefun
+
+@deftypefun {kvp_frame *} kvp_frame_get_frame (kvp_frame * @var{frame}, ...)
+Works like @code{kvp_frame_get_slot_path}, but returns the last frame
+in the path. All the keys should refer to frames. If the frame path
+does not exist, it is created.
+@end deftypefun
+
+@deftypefun {kvp_frame *} kvp_frame_get_frame_gslist (kvp_frame * @var{frame}, GSList * @var{key_path})
+Works like @code{kvp_frame_get_slot_path_gslist}, but returns the last
+frame in the path. All the keys should refer to frames. If the frame
+path does not exist, it is created.
+@end deftypefun
+
+@deftypefun {kvp_frame *} kvp_frame_get_frame_slash (kvp_frame * @var{frame}, const char * @var{path})
+Works like @code{kvp_frame_get_frame}, but the frame path is specified
+as a single string where the keys are separated by slashes; thus, for
+example: @code{/this/is/a/valid/path} and @code{///so//is////this/}.
+Multiple slashes are compresed and a leading slash is optional. The
+pointers @code{.} and @code{..} are @emph{not} followed/obeyed. (This
+is arguably a bug that needs fixing).
 @end deftypefun
 
 
Index: gnucash/src/engine/Account-xml-parser-v1.c
diff -u gnucash/src/engine/Account-xml-parser-v1.c:1.7 gnucash/src/engine/Account-xml-parser-v1.c:1.8
--- gnucash/src/engine/Account-xml-parser-v1.c:1.7	Sat Feb 24 18:42:29 2001
+++ gnucash/src/engine/Account-xml-parser-v1.c	Wed May  9 18:03:35 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * Account-xml-parser-v1.c -- implementation of xml i/o             *
+ *                                                                  *
+ * Copyright (C) 2001 Rob Browning                                  *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #include "config.h"
 
 #include <string.h>
Index: gnucash/src/engine/Account.c
diff -u gnucash/src/engine/Account.c:1.142 gnucash/src/engine/Account.c:1.143
--- gnucash/src/engine/Account.c:1.142	Tue May  8 04:36:32 2001
+++ gnucash/src/engine/Account.c	Thu May 10 11:12:02 2001
@@ -135,6 +135,27 @@
   return acc;
 }
 
+Account *
+xaccCloneAccountSimple(const Account *from)
+{
+    Account *ret;
+
+    ret = xaccMallocAccount();
+    xaccInitAccount(ret);
+    
+    ret->type = from->type;
+
+    ret->accountName = g_strdup(from->accountName);
+    ret->accountCode = g_strdup(from->accountCode);
+    ret->description = g_strdup(from->description);
+
+    ret->kvp_data    = kvp_frame_copy(from->kvp_data);
+
+    ret->currency    = from->currency;
+
+    return ret;
+}
+
 /********************************************************************\
 \********************************************************************/
 
@@ -1273,6 +1294,8 @@
 xaccAccountGetChildren (Account *acc)
 {
    if (!acc) return NULL;
+   if (acc->children == NULL)
+       acc->children = xaccMallocAccountGroup ();
    return (acc->children);
 }
 
@@ -1755,7 +1778,7 @@
 #define GNC_RETURN_ENUM_AS_STRING(x) case (x): return #x;
 
 char *
-xaccAccountTypeEnumAsString(int type) {
+xaccAccountTypeEnumAsString(GNCAccountType type) {
   switch(type) {
     GNC_RETURN_ENUM_AS_STRING(NO_TYPE);
     GNC_RETURN_ENUM_AS_STRING(BANK);
Index: gnucash/src/engine/Account.h
diff -u gnucash/src/engine/Account.h:1.67 gnucash/src/engine/Account.h:1.68
--- gnucash/src/engine/Account.h:1.67	Mon Apr 23 01:07:57 2001
+++ gnucash/src/engine/Account.h	Thu May 10 11:12:02 2001
@@ -110,7 +110,7 @@
 /* Conversion routines for the account types to/from strings.
    Critical for the text communication mechanisms. i.e. INCOME ->
    "INCOME". */
-char *   xaccAccountTypeEnumAsString (int type); 
+char *   xaccAccountTypeEnumAsString (GNCAccountType type); 
 gboolean xaccAccountStringToType (const char* str, int *type);
 GNCAccountType xaccAccountStringToEnum (const char* str);
 
@@ -129,6 +129,7 @@
  *    (by calling xaccAccountBeginEdit()) before calling this routine.
  */
 Account     *xaccMallocAccount (void);
+Account * xaccCloneAccountSimple(const Account *from);
 void         xaccAccountBeginEdit (Account *account);
 void         xaccAccountCommitEdit (Account *account);
 void         xaccAccountDestroy (Account *account);
Index: gnucash/src/engine/Backend.h
diff -u gnucash/src/engine/Backend.h:1.6 gnucash/src/engine/Backend.h:1.8
--- gnucash/src/engine/Backend.h:1.6	Thu Mar 22 02:02:44 2001
+++ gnucash/src/engine/Backend.h	Wed May  9 19:12:43 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * Backend.h -- api for engine Backend                              *
+ *                                                                  *
+ * Copyright (c) 2000, 2001 Linas Vepstas <linas@linas.org>         *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 /* 
  * FILE:
  * Backend.h
@@ -8,9 +32,6 @@
  * a file).  There are no backend functions that are 'public' to
  * users of the engine.  The backend can, however, report errors to
  * the GUI & other front-end users.  This file defines these errors.
- * 
- * HISTORY:
- * Copyright (c) 2000, 2001 Linas Vepstas (linas@linas.org)
  */
 
 #ifndef __XACC_BACKEND_H__
@@ -23,13 +44,18 @@
   ERR_BACKEND_NO_ERR = 0,
   ERR_BACKEND_NO_BACKEND,   /* Backend * pointer was null the err routine */
                             /* or no backend handler (ENOSYS) */
-  ERR_BACKEND_LOCKED,       /* in use by another user (ETXTBSY) */
+  ERR_BACKEND_BAD_URL,      /* Can't parse url */
   ERR_BACKEND_NO_SUCH_DB,   /* the named database doesn't exist */
+  ERR_BACKEND_CANT_CONNECT, /* bad dbname/login/passwd or network failure */
+  ERR_BACKEND_CONN_LOST,    /* Lost connection to server */
+  ERR_BACKEND_LOCKED,       /* in use by another user (ETXTBSY) */
+  ERR_BACKEND_DATA_CORRUPT, /* data in db is corrupt */
+  ERR_BACKEND_SERVER_ERR,   /* error in response from server */
   ERR_BACKEND_ALLOC,        /* internal memory allocation failure */
   ERR_BACKEND_MISC,         /* undetermined error */
 
   /* fileio errors */
-  ERR_FILEIO_FILE_BAD_READ,  /* read failed or file prematurely truncated */
+  ERR_FILEIO_FILE_BAD_READ = 1000,  /* read failed or file prematurely truncated */
   ERR_FILEIO_FILE_EMPTY,     /* file exists, is readable, but is empty */
   ERR_FILEIO_FILE_LOCKERR,   /* mangled locks (unspecified error) */
   ERR_FILEIO_FILE_NOT_FOUND, /* not found / no such file */
@@ -38,30 +64,19 @@
   ERR_FILEIO_UNKNOWN_FILE_TYPE,
   
   /* network errors */
-  ERR_NETIO_NO_CONNECTION,      /* network failure, can't connect to server */
-  ERR_NETIO_SHORT_READ,         /* not enough bytes received */
+  ERR_NETIO_SHORT_READ = 2000,  /* not enough bytes received */
   ERR_NETIO_WRONG_CONTENT_TYPE, /* wrong kind of server, wrong data served */
   ERR_NETIO_NOT_GNCXML,         /* whatever it is, we can't parse it. */
 
   /* database errors */
-  ERR_SQL_BAD_LOCATION,        /* can't parse url */
-  ERR_SQL_CANT_CONNECT,        /* bad dbname/login/passwd or network failure */
-  ERR_SQL_SEND_QUERY_FAILED,   /* can't send to database */
-  ERR_SQL_FINISH_QUERY_FAILED, /* can't finish out sent request */
-  ERR_SQL_GET_RESULT_FAILED,   /* can't read response from the db. */
-  ERR_SQL_CORRUPT_DB,          /* data in db is corrupt */
-  ERR_SQL_MISSING_DATA,        /* database doesn't contain expected data */
+  ERR_SQL_MISSING_DATA = 3000,  /* database doesn't contain expected data */
 
   /* RPC errors */
-  ERR_RPC_BAD_URL,		/* Can't parse url */
-  ERR_RPC_HOST_UNK,		/* Host unknown */
-  ERR_RPC_CANT_CONNECT,		/* bad hostname/port/dbname/etc. */
+  ERR_RPC_HOST_UNK = 4000,	/* Host unknown */
   ERR_RPC_CANT_BIND,		/* can't bind to address */
   ERR_RPC_CANT_ACCEPT,		/* can't accept connection */
   ERR_RPC_NO_CONNECTION,	/* no connection to server */
-  ERR_RPC_CONNECTION_LOST,	/* Lost connection to server */
   ERR_RPC_BAD_VERSION,		/* RPC Version Mismatch */
-  ERR_RPC_SERVER_STATE,		/* Invalid/bad server state */
   ERR_RPC_FAILED,		/* Operation failed */
   ERR_RPC_NOT_ADDED,		/* object not added */
 
Index: gnucash/src/engine/BackendP.h
diff -u gnucash/src/engine/BackendP.h:1.14 gnucash/src/engine/BackendP.h:1.15
--- gnucash/src/engine/BackendP.h:1.14	Mon Apr 16 04:16:43 2001
+++ gnucash/src/engine/BackendP.h	Wed May  9 18:03:35 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * Backend.h -- private api for engine Backend                      *
+ *                                                                  *
+ * Copyright (c) 2000, 2001 Linas Vepstas <linas@linas.org>         *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 /* 
  * FILE:
  * BackendP.h
Index: gnucash/src/engine/Commodity-xml-parser-v1.c
diff -u gnucash/src/engine/Commodity-xml-parser-v1.c:1.6 gnucash/src/engine/Commodity-xml-parser-v1.c:1.7
--- gnucash/src/engine/Commodity-xml-parser-v1.c:1.6	Tue Mar  6 20:37:33 2001
+++ gnucash/src/engine/Commodity-xml-parser-v1.c	Wed May  9 18:03:35 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * Commodity-xml-parser-v1.c -- implementation of xml i/o           *
+ *                                                                  *
+ * Copyright (C) 2001 Rob Browning                                  *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #include "config.h"
 
 #include <glib.h>
Index: gnucash/src/engine/Group.c
diff -u gnucash/src/engine/Group.c:1.79 gnucash/src/engine/Group.c:1.80
--- gnucash/src/engine/Group.c:1.79	Wed Apr 25 18:37:56 2001
+++ gnucash/src/engine/Group.c	Thu May 10 11:12:28 2001
@@ -1295,9 +1295,10 @@
 }
 
 gpointer
-xaccGroupForEachAccountDeeply (AccountGroup *grp,
-                               gpointer (*thunk)(Account *a, gpointer data),
-                               gpointer data)
+xaccGroupForEachAccount (AccountGroup *grp,
+                         gpointer (*thunk)(Account *a, gpointer data),
+                         gpointer data,
+                         gboolean deeply)
 {
   GList *node;
 
@@ -1312,7 +1313,9 @@
     if (result)
       return(result);
 
-    result = xaccGroupForEachAccountDeeply (account->children, thunk, data);
+    if(deeply)
+        result = xaccGroupForEachAccount (account->children,
+                                          thunk, data, TRUE);
 
     if (result)
       return(result);
Index: gnucash/src/engine/Group.h
diff -u gnucash/src/engine/Group.h:1.44 gnucash/src/engine/Group.h:1.45
--- gnucash/src/engine/Group.h:1.44	Wed Apr 18 06:11:02 2001
+++ gnucash/src/engine/Group.h	Thu May 10 11:12:28 2001
@@ -211,10 +211,11 @@
                              gpointer (*thunk)(Account *a, gpointer data),
                              gpointer data);
 
-gpointer xaccGroupForEachAccountDeeply(AccountGroup *grp,
-                                       gpointer (*thunk)(Account *a,
-                                                         gpointer data),
-                                       gpointer data);
+gpointer xaccGroupForEachAccount (AccountGroup *grp,
+                                  gpointer (*thunk) (Account *a,
+                                                     gpointer data),
+                                  gpointer data,
+                                  gboolean deeply);
 
 gboolean xaccGroupEqual(AccountGroup *a, AccountGroup *b,
                         gboolean check_guids);
Index: gnucash/src/engine/Queue.h
diff -u gnucash/src/engine/Queue.h:1.4 gnucash/src/engine/Queue.h:1.5
--- gnucash/src/engine/Queue.h:1.4	Mon Apr 24 16:12:41 2000
+++ gnucash/src/engine/Queue.h	Wed May  9 18:03:36 2001
@@ -1,3 +1,22 @@
+/********************************************************************\
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+\********************************************************************/
+
 /*
  * FILE:
  * Queue.h
@@ -42,24 +61,6 @@
  * created by Linas Vepstas January 1999
  * Copyright (c) 1999, 2000 Linas Vepstas
  */
-/********************************************************************\
- * This program is free software; you can redistribute it and/or    *
- * 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, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
- * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
-\********************************************************************/
 
 #ifndef __XACC_QUEUE_H__
 #define __XACC_QUEUE_H__
Index: gnucash/src/engine/gnc-account-xml-v2.c
diff -u gnucash/src/engine/gnc-account-xml-v2.c:1.16 gnucash/src/engine/gnc-account-xml-v2.c:1.17
--- gnucash/src/engine/gnc-account-xml-v2.c:1.16	Wed Apr 18 06:11:02 2001
+++ gnucash/src/engine/gnc-account-xml-v2.c	Wed May  9 18:03:36 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * gnc-account-xml-v2.c -- account xml i/o implementation           *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #include "config.h"
 
 #include <glib.h>
Index: gnucash/src/engine/gnc-book.c
diff -u gnucash/src/engine/gnc-book.c:1.33 gnucash/src/engine/gnc-book.c:1.34
--- gnucash/src/engine/gnc-book.c:1.33	Tue Apr 17 04:32:03 2001
+++ gnucash/src/engine/gnc-book.c	Thu May 10 11:12:52 2001
@@ -197,8 +197,9 @@
 void
 gnc_book_set_group (GNCBook *book, AccountGroup *grp)
 {
-   if (!book) return;
-   book->topgroup = grp;
+  if(!book) return;
+  if(book->topgroup) xaccFreeAccountGroup(book->topgroup);
+  book->topgroup = grp;
 }
 
 /* ---------------------------------------------------------------------- */
Index: gnucash/src/engine/gnc-book.h
diff -u gnucash/src/engine/gnc-book.h:1.16 gnucash/src/engine/gnc-book.h:1.17
--- gnucash/src/engine/gnc-book.h:1.16	Thu Mar 22 02:02:47 2001
+++ gnucash/src/engine/gnc-book.h	Thu May 10 11:12:52 2001
@@ -120,6 +120,7 @@
 
 
 AccountGroup *gnc_book_get_group (GNCBook *book);
+void gnc_book_set_group(GNCBook *book, AccountGroup *group);
 GNCPriceDB   *gnc_book_get_pricedb (GNCBook *book);
 
 guint gnc_book_count_transactions(GNCBook *book);
Index: gnucash/src/engine/gnc-commodity-xml-v2.c
diff -u gnucash/src/engine/gnc-commodity-xml-v2.c:1.10 gnucash/src/engine/gnc-commodity-xml-v2.c:1.11
--- gnucash/src/engine/gnc-commodity-xml-v2.c:1.10	Thu Apr  5 16:37:52 2001
+++ gnucash/src/engine/gnc-commodity-xml-v2.c	Wed May  9 18:03:36 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * gnc-commodity-xml-v2.c -- commodity xml i/o implementation       *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #include "config.h"
 
 #include <glib.h>
Index: gnucash/src/engine/gnc-pricedb.c
diff -u gnucash/src/engine/gnc-pricedb.c:1.14 gnucash/src/engine/gnc-pricedb.c:1.15
--- gnucash/src/engine/gnc-pricedb.c:1.14	Fri Apr 27 04:08:17 2001
+++ gnucash/src/engine/gnc-pricedb.c	Thu May 10 02:07:45 2001
@@ -653,8 +653,8 @@
                                    Timespec t)
 {
   GList *price_list;
-  GNCPrice *before_price = NULL;
-  GNCPrice *after_price = NULL;
+  GNCPrice *current_price = NULL;
+  GNCPrice *next_price = NULL;
   GNCPrice *result = NULL;
   GList *item = NULL;
   GHashTable *currency_hash;
@@ -670,34 +670,37 @@
   item = price_list;
 
   /* default answer */
-  before_price = item->data;
+  current_price = item->data;
 
   /* find the first candidate past the one we want.  Remember that
      prices are in most-recent-first order. */
-  while(!after_price && item) {
+  while (!next_price && item) {
     GNCPrice *p = item->data;
     Timespec price_time = gnc_price_get_time(p);
-    if(timespec_cmp(&price_time, &t) > 0) {
-      before_price = after_price;
-      after_price = item->data;
+    if (timespec_cmp(&price_time, &t) <= 0) {
+      next_price = item->data;
+      break;
     }
+    current_price = item->data;
     item = item->next;
   }
 
-  if(before_price && !after_price) result = before_price;
-
-  {
-    Timespec before_t = gnc_price_get_time(before_price);
-    Timespec after_t = gnc_price_get_time(after_price);
-    Timespec diff_before = timespec_diff(&before_t, &t);
-    Timespec diff_after = timespec_diff(&after_t, &t);
-    Timespec abs_before = timespec_abs(&diff_before);
-    Timespec abs_after = timespec_abs(&diff_after);
-
-    if(timespec_cmp(&abs_before, &abs_after) < 0) {
-      result = before_price;
+  if (current_price) {
+    if (!next_price) {
+      result = current_price;
     } else {
-      result = after_price;
+      Timespec current_t = gnc_price_get_time(current_price);
+      Timespec next_t = gnc_price_get_time(next_price);
+      Timespec diff_current = timespec_diff(&current_t, &t);
+      Timespec diff_next = timespec_diff(&next_t, &t);
+      Timespec abs_current = timespec_abs(&diff_current);
+      Timespec abs_next = timespec_abs(&diff_next);
+      
+      if (timespec_cmp(&abs_current, &abs_next) <= 0) {
+	result = current_price;
+      } else {
+	result = next_price;
+      }
     }
   }
 
Index: gnucash/src/engine/gnc-xml-helper.h
diff -u gnucash/src/engine/gnc-xml-helper.h:1.2 gnucash/src/engine/gnc-xml-helper.h:1.3
--- gnucash/src/engine/gnc-xml-helper.h:1.2	Tue Feb 27 14:15:11 2001
+++ gnucash/src/engine/gnc-xml-helper.h	Wed May  9 18:03:36 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * gnc-xml-helper.h -- api for xml helpers                          *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #ifndef _GNC_XML_HELPER_H_
 #define _GNC_XML_HELPER_H_
 
Index: gnucash/src/engine/gnc-xml.h
diff -u gnucash/src/engine/gnc-xml.h:1.3 gnucash/src/engine/gnc-xml.h:1.4
--- gnucash/src/engine/gnc-xml.h:1.3	Tue Mar 13 00:20:00 2001
+++ gnucash/src/engine/gnc-xml.h	Wed May  9 18:03:36 2001
@@ -1,3 +1,26 @@
+/********************************************************************\
+ * gnc-xml.h -- api for gnucash xml i/o                             *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
 
 #ifndef __GNC_XML_H__
 #define __GNC_XML_H__
Index: gnucash/src/engine/io-example-account.c
diff -u gnucash/src/engine/io-example-account.c:1.1 gnucash/src/engine/io-example-account.c:1.2
--- gnucash/src/engine/io-example-account.c:1.1	Fri Apr 13 01:54:23 2001
+++ gnucash/src/engine/io-example-account.c	Wed May  9 18:03:36 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * io-example-account.c -- implementation for example accounts      *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #include <sys/types.h>
 #include <dirent.h>
 #include <sys/stat.h>
Index: gnucash/src/engine/io-example-account.h
diff -u gnucash/src/engine/io-example-account.h:1.2 gnucash/src/engine/io-example-account.h:1.3
--- gnucash/src/engine/io-example-account.h:1.2	Wed Apr 18 06:17:42 2001
+++ gnucash/src/engine/io-example-account.h	Wed May  9 18:03:36 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * io-example-account.h -- api for example accounts                 *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #ifndef __IO_EXAMPLE_ACCOUNT_H__
 #define __IO_EXAMPLE_ACCOUNT_H__
 
Index: gnucash/src/engine/io-gncxml-gen.c
diff -u gnucash/src/engine/io-gncxml-gen.c:1.1 gnucash/src/engine/io-gncxml-gen.c:1.2
--- gnucash/src/engine/io-gncxml-gen.c:1.1	Thu Apr  5 16:37:53 2001
+++ gnucash/src/engine/io-gncxml-gen.c	Wed May  9 18:03:36 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * gnc-xml-gen.c -- implementation for gnucash xml i/o              *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #include "io-gncxml-gen.h"
 
 gboolean
@@ -13,4 +37,3 @@
     return sixtp_parse_file(top_parser, filename, 
                             NULL, &gpdata, &parse_result);
 }
-
Index: gnucash/src/engine/io-gncxml-gen.h
diff -u gnucash/src/engine/io-gncxml-gen.h:1.1 gnucash/src/engine/io-gncxml-gen.h:1.2
--- gnucash/src/engine/io-gncxml-gen.h:1.1	Thu Apr  5 16:37:54 2001
+++ gnucash/src/engine/io-gncxml-gen.h	Wed May  9 18:03:36 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * gnc-xml-gen.h -- api for gnucash xml i/o                         *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #ifndef __IO_GNCXML_GEN_H__
 #define __IO_GNCXML_GEN_H__
 
Index: gnucash/src/engine/io-gncxml-v2.h
diff -u gnucash/src/engine/io-gncxml-v2.h:1.5 gnucash/src/engine/io-gncxml-v2.h:1.6
--- gnucash/src/engine/io-gncxml-v2.h:1.5	Thu Apr  5 16:37:54 2001
+++ gnucash/src/engine/io-gncxml-v2.h	Wed May  9 18:03:36 2001
@@ -1,11 +1,33 @@
+/********************************************************************\
+ * io-gncxml-v2.h -- api for gnucash xml i/o                        *
+ *                                                                  *
+ * Copyright (c) 2001 Gnumatic Incorporated                         *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 /*
  * io-gncxml.h -- api for new XML-based file format
  *
  * Initial code by James LewisMoss
- *
- * Copyright (c) 2001 Gnumatic Incorporated
- *
  */
+
 #ifndef __IO_GNCXML_V2_H__
 #define __IO_GNCXML_V2_H__
 
@@ -55,7 +77,6 @@
  * chars of the file look like gnc-xml data.
  */
 gboolean gnc_is_xml_data_file_v2(const gchar *name);
-
 
 
 #endif /* __IO_GNCXML_V2_H__ */
Index: gnucash/src/engine/io-gncxml.h
diff -u gnucash/src/engine/io-gncxml.h:1.8 gnucash/src/engine/io-gncxml.h:1.9
--- gnucash/src/engine/io-gncxml.h:1.8	Sat Feb 24 18:42:34 2001
+++ gnucash/src/engine/io-gncxml.h	Wed May  9 18:03:36 2001
@@ -1,12 +1,34 @@
+/********************************************************************\
+ * io-gncxml.h -- api for gnucash xml i/o                           *
+ *                                                                  *
+ * Copyright (c) 2000,2001 Gnumatic Incorporated                    *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 /*
  * io-gncxml.h -- api for new XML-based file format
  *
  * Initial code by Rob l. Browning 4Q 2000
  * Tuneups by James LewisMoss Dec 2000
- *
- * Copyright (c) 2000,2001 Gnumatic Incorporated
- *
  */
+
 #ifndef __IO_GNCXML_H__
 #define __IO_GNCXML_H__
 
Index: gnucash/src/engine/io-utils.c
diff -u gnucash/src/engine/io-utils.c:1.1 gnucash/src/engine/io-utils.c:1.2
--- gnucash/src/engine/io-utils.c:1.1	Fri Apr 13 01:54:24 2001
+++ gnucash/src/engine/io-utils.c	Wed May  9 18:03:36 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * io-utils.c -- implementation for gnucash file i/o utils          *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #include <stdio.h>
 
 #include <glib.h>
@@ -53,4 +77,3 @@
 {
     write_account_group(out, gnc_book_get_group(book));
 }
-
Index: gnucash/src/engine/io-utils.h
diff -u gnucash/src/engine/io-utils.h:1.1 gnucash/src/engine/io-utils.h:1.2
--- gnucash/src/engine/io-utils.h:1.1	Fri Apr 13 01:54:24 2001
+++ gnucash/src/engine/io-utils.h	Wed May  9 18:03:36 2001
@@ -1,3 +1,27 @@
+/********************************************************************\
+ * io-utils.h -- api for gnucash file i/o                           *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
 #ifndef __IO_UTILS_H__
 #define __IO_UTILS_H__
 
Index: gnucash/src/engine/kvp_frame.c
diff -u gnucash/src/engine/kvp_frame.c:1.20 gnucash/src/engine/kvp_frame.c:1.21
--- gnucash/src/engine/kvp_frame.c:1.20	Tue Apr 17 04:32:03 2001
+++ gnucash/src/engine/kvp_frame.c	Thu May 10 04:32:59 2001
@@ -1071,6 +1071,8 @@
 {
     gchar *tmp1;
 
+    g_return_val_if_fail (frame != NULL, NULL);
+
     tmp1 = g_strdup_printf("{\n");
 
     g_hash_table_foreach(frame->hash, kvp_frame_to_string_helper, &tmp1);
@@ -1088,5 +1090,6 @@
 GHashTable*
 kvp_frame_get_hash(const kvp_frame *frame)
 {
+    g_return_val_if_fail (frame != NULL, NULL);
     return frame->hash;
 }
Index: gnucash/src/engine/sixtp-parsers.h
diff -u gnucash/src/engine/sixtp-parsers.h:1.3 gnucash/src/engine/sixtp-parsers.h:1.4
--- gnucash/src/engine/sixtp-parsers.h:1.3	Sat Feb 24 18:42:35 2001
+++ gnucash/src/engine/sixtp-parsers.h	Wed May  9 18:03:36 2001
@@ -1,3 +1,26 @@
+/********************************************************************\
+ * sixtp-parsers.h -- api for gnucash sixtp parsers                 *
+ *                                                                  *
+ * Copyright (C) 2001 James LewisMoss <dres@debian.org>             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
+ * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
+ *                                                                  *
+\********************************************************************/
 
 #ifndef _SIXTP_PARSERS_H_
 #define _SIXTP_PARSERS_H_
Index: gnucash/src/engine/rpc/RpcBackend.c
diff -u gnucash/src/engine/rpc/RpcBackend.c:1.2 gnucash/src/engine/rpc/RpcBackend.c:1.3
--- gnucash/src/engine/rpc/RpcBackend.c:1.2	Tue Apr 17 04:32:04 2001
+++ gnucash/src/engine/rpc/RpcBackend.c	Wed May  9 19:12:44 2001
@@ -809,7 +809,7 @@
    * rpc://host[:port]/db_name
    */
   if (strncmp (book_id, "rpc://", 6)) {
-    xaccBackendSetError (&be->be, ERR_RPC_BAD_URL);
+    xaccBackendSetError (&be->be, ERR_BACKEND_BAD_URL);
     LEAVE ("Not an RPC URL?");
     return;
   }
@@ -817,7 +817,7 @@
   start = url + 6;
   rest = strchr (start, '/');
   if (!rest || *rest == '\0') {
-    xaccBackendSetError (&be->be, ERR_RPC_BAD_URL);
+    xaccBackendSetError (&be->be, ERR_BACKEND_BAD_URL);
     g_free (url);
     LEAVE ("cannot find a path after host[:port]");
     return;
@@ -832,7 +832,7 @@
   be->hostname = g_strdup (start);
   start = rest+1;
   if (*start == '\0') {
-    xaccBackendSetError (&be->be, ERR_RPC_BAD_URL);
+    xaccBackendSetError (&be->be, ERR_BACKEND_BAD_URL);
     g_free (url);
     LEAVE ("tailing slash but no path after host[:port]");
     return;
Index: gnucash/src/engine/rpc/RpcSock.c
diff -u gnucash/src/engine/rpc/RpcSock.c:1.1 gnucash/src/engine/rpc/RpcSock.c:1.2
--- gnucash/src/engine/rpc/RpcSock.c:1.1	Mon Mar 19 15:49:50 2001
+++ gnucash/src/engine/rpc/RpcSock.c	Wed May  9 19:12:44 2001
@@ -13,6 +13,8 @@
 #include <netdb.h>
 #include <unistd.h>
 #include <rpc/xprt_thrd.h>
+#include <sys/socket.h>
+
 #include "RpcBackend.h"
 #include "RpcSock.h"
 
@@ -103,7 +105,7 @@
   struct sockaddr_in sin;
 
   if (hostname == NULL || *hostname == '\0' || port == 0)
-    return ERR_RPC_BAD_URL;
+    return ERR_BACKEND_BAD_URL;
 
   if (sock == NULL)
     return ERR_BACKEND_MISC;
@@ -118,8 +120,8 @@
   if ((s = socket (sin.sin_family, SOCK_STREAM, 0)) < 0)
     return ERR_BACKEND_ALLOC;
 
-  if (connect (s, &sin, sizeof(sin)) != 0)
-    return ERR_RPC_CANT_CONNECT;
+  if (connect (s, (struct sockaddr *) &sin, sizeof(sin)) != 0)
+    return ERR_BACKEND_CANT_CONNECT;
 
   new = g_malloc (sizeof (*new));
   if (new == NULL) {
@@ -186,7 +188,7 @@
   sin.sin_family = AF_INET;
   sin.sin_port = port;
   sin.sin_addr.s_addr = INADDR_ANY;
-  if (bind (s, &sin, sizeof (sin)) < 0) {
+  if (bind (s, (struct sockaddr *) &sin, sizeof (sin)) < 0) {
     close (s);
     return ERR_RPC_CANT_BIND;
   }
Index: gnucash/src/engine/rpc/RpcUtils.c
diff -u gnucash/src/engine/rpc/RpcUtils.c:1.4 gnucash/src/engine/rpc/RpcUtils.c:1.5
--- gnucash/src/engine/rpc/RpcUtils.c:1.4	Tue Apr 17 04:32:05 2001
+++ gnucash/src/engine/rpc/RpcUtils.c	Thu May 10 11:13:13 2001
@@ -609,7 +609,7 @@
   ENTER ("ag=%p", ag);
   listinfo.end = &alist;
   listinfo.count = 0;
-  xaccGroupForEachAccountDeeply (ag, add_acctlist_cb, (void *) &listinfo);
+  xaccGroupForEachAccount (ag, add_acctlist_cb, (void *) &listinfo, TRUE);
   LEAVE ("%d accts", listinfo.count);
   return alist;
 }
@@ -739,7 +739,7 @@
   listinfo.copyguid = copyguid;
   listinfo.count = 0;
 
-  xaccGroupForEachAccountDeeply (ag, add_acctvers_cb, (void *) &listinfo);
+  xaccGroupForEachAccount (ag, add_acctvers_cb, (void *) &listinfo, TRUE);
 
   LEAVE ("%d accts", listinfo.count);
   return vlist;
Index: gnucash/src/engine/rpc/gncRpc_server.c
diff -u gnucash/src/engine/rpc/gncRpc_server.c:1.2 gnucash/src/engine/rpc/gncRpc_server.c:1.3
--- gnucash/src/engine/rpc/gncRpc_server.c:1.2	Tue Apr 17 04:32:05 2001
+++ gnucash/src/engine/rpc/gncRpc_server.c	Wed May  9 19:12:44 2001
@@ -57,7 +57,7 @@
 {
 	bool_t retval = TRUE;
 	GncRpcSvc *cl;
-	int res = ERR_RPC_SERVER_STATE;
+	int res = ERR_BACKEND_SERVER_ERR;
 
 	ENTER ("id=\"%s\"", argp->book_id ? argp->book_id : "");
 
@@ -91,7 +91,7 @@
 
 	retval = gncrpc_get_state (rqstp, NULL, &cl);
 	if (!retval) {
-	  result->error = ERR_RPC_SERVER_STATE;
+	  result->error = ERR_BACKEND_SERVER_ERR;
 	  LEAVE ("bad state");
 	  return retval;
 	}
@@ -121,7 +121,7 @@
 	ENTER ("ok");
 	retval = gncrpc_get_state (rqstp, NULL, &cl);
 	if (!retval) {
-	  *result = ERR_RPC_SERVER_STATE;
+	  *result = ERR_BACKEND_SERVER_ERR;
 	  LEAVE ("bad state");
 	  return retval;
 	}
@@ -168,7 +168,7 @@
 	ENTER ("vers=%d", argp->acct.vers);
 	retval = gncrpc_get_state (rqstp, NULL, &cl);
 	if (!retval) {
-	  *result = ERR_RPC_SERVER_STATE;
+	  *result = ERR_BACKEND_SERVER_ERR;
 	  LEAVE ("bad state");
 	  return retval;
 	}
@@ -217,7 +217,7 @@
 	ENTER ("ok");
 	retval = gncrpc_get_state (rqstp, NULL, &cl);
 	if (!retval) {
-	  *result = ERR_RPC_SERVER_STATE;
+	  *result = ERR_BACKEND_SERVER_ERR;
 	  LEAVE ("bad state");
 	  return retval;
 	}
@@ -273,7 +273,7 @@
 	ENTER ("vers=%d", argp->new.vers);
 	retval = gncrpc_get_state (rqstp, NULL, &cl);
 	if (!retval) {
-	  *result = ERR_RPC_SERVER_STATE;
+	  *result = ERR_BACKEND_SERVER_ERR;
 	  LEAVE ("bad state");
 	  return retval;
 	}
@@ -334,7 +334,7 @@
 	/* Find state */
 	retval = gncrpc_get_state (rqstp, NULL, &cl);
 	if (!retval) {
-	  result->error = ERR_RPC_SERVER_STATE;
+	  result->error = ERR_BACKEND_SERVER_ERR;
 	  LEAVE ("Bad state");
 	  return retval;
 	}
@@ -386,7 +386,7 @@
 	memset (result, 0, sizeof (*result));
 	retval = gncrpc_get_state (rqstp, NULL, &cl);
 	if (!retval) {
-	  result->error = ERR_RPC_SERVER_STATE;
+	  result->error = ERR_BACKEND_SERVER_ERR;
 	  LEAVE ("bad state");
 	  return retval;
 	}
@@ -507,7 +507,7 @@
 	*result = 0;
 	retval = gncrpc_get_state (rqstp, NULL, &cl);
 	if (!retval) {
-	  *result = ERR_RPC_SERVER_STATE;
+	  *result = ERR_BACKEND_SERVER_ERR;
 	  LEAVE ("bad state");
 	  return retval;
 	}
@@ -543,7 +543,7 @@
 	memset (result, 0, sizeof (*result));
 	retval = gncrpc_get_state (rqstp, NULL, &cl);
 	if (!retval) {
-	  result->error = ERR_RPC_SERVER_STATE;
+	  result->error = ERR_BACKEND_SERVER_ERR;
 	  LEAVE ("Bad state");
 	  return retval;
 	}
Index: gnucash/src/engine/sql/PostgresBackend.c
diff -u gnucash/src/engine/sql/PostgresBackend.c:1.36 gnucash/src/engine/sql/PostgresBackend.c:1.39
--- gnucash/src/engine/sql/PostgresBackend.c:1.36	Tue May  8 21:42:47 2001
+++ gnucash/src/engine/sql/PostgresBackend.c	Thu May 10 11:49:44 2001
@@ -62,8 +62,8 @@
 
 /* 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 theres not much point in getting fancy ... 
+ * rejects queries longer than 8192 bytes, (according to the
+ * documentation) so there's not much point in getting fancy ... 
  */
 #define QBUFSIZE 16350
 
@@ -366,7 +366,7 @@
 {
    if (!grp) return;
 
-   xaccGroupForEachAccountDeeply (grp, restore_cb, be);
+   xaccGroupForEachAccount (grp, restore_cb, be, TRUE);
 }
 
 /* ============================================================= */
@@ -404,7 +404,7 @@
    char * p;
    if (!be) return;
 
-   ENTER ("be=%p", be);
+   ENTER ("be=%p, conn=%p", be, be->connection);
 
    comtab = gnc_engine_commodities();
    if (!comtab) {
@@ -857,7 +857,7 @@
                    "too many transactions with GUID=%s\n",
                     guid_to_string (trans_guid));
              if (jrows != nrows) xaccTransCommitEdit (trans);
-             xaccBackendSetError (&be->be, ERR_SQL_CORRUPT_DB);
+             xaccBackendSetError (&be->be, ERR_BACKEND_DATA_CORRUPT);
              pgendEnable(be);
              gnc_engine_resume_events();
              return 0;
@@ -1247,12 +1247,12 @@
 
 /* ============================================================= */
 /* 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.
+ *    transactions out of the database.  This is a potential 
+ *    CPU and memory-burner; its use is not suggested for anything
+ *    but single-user mode.
  *
- * To add injury to insult, this routine fetches in a rather 
- * inefficient manner, in particular, the account query.
+ *    To add injury to insult, this routine fetches in a rather 
+ *    inefficient manner, in particular, the account query.
  */
 
 static void
@@ -1524,14 +1524,19 @@
 }
 
 /* ============================================================= */
-/* In single file mode, we treat 'sync' as 'file save'.
- * 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.  
- * So start with a clean slate.
+/* 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 
+ *    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.  
+ *    So start with a clean slate.
+ *
+ *    The use of this routine/this mode is 'depricated'.
+ *    Its handy for testing, sanity-checking, and as a failsafe,
+ *    but its use shouldn't be encouraged.
  */
 
 static void
@@ -1604,17 +1609,18 @@
 }
 
 /* ============================================================= */
-/* Determine whether we can start a session of the desired type.
- * The logic used is as follows:
- * -- if there is any session at all, and we want single
- *    (exclusive) access, then fail.
- * -- if we want any kind of session, and there is a single
- *    (exclusive) session going, then fail.
- * -- otherwise, suceed.
- * Return TRUE if we can get a session.
+/* 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
+ *       (exclusive) access, then fail.
+ *    -- if we want any kind of session, and there is a single
+ *       (exclusive) session going, then fail.
+ *    -- otherwise, suceed.
+ *    Return TRUE if we can get a session.
  *
- * This routine does not lock, but may be used inside a 
- * test-n-set atomic operation.
+ *    This routine does not lock, but may be used inside a 
+ *    test-n-set atomic operation.
  */
 
 static gpointer
@@ -1693,11 +1699,24 @@
 
 
 /* ============================================================= */
-/* Determine whether a valid session could be obtained.
- * Return TRUE if we have a session
- * This routine is implemented attomically as a test-n-set.
+/* 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
+ *       a session.  The update is handled as an atomic test-n-set.
+ *    Return TRUE if we have a session.
  */
 
+static gpointer 
+is_gnucash_cb (PGBackend *be, PGresult *result, int j, gpointer data)
+{
+   if (TRUE == (gboolean) data) return (gpointer) TRUE;
+
+   if (0 == strcmp ("gncsession", (DB_GET_VAL ("tablename", j)))) 
+      return (gpointer) TRUE;
+   return FALSE;
+}
+
 static gboolean
 pgendSessionValidate (PGBackend *be, int break_lock)
 {
@@ -1707,6 +1726,16 @@
 
    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 = (gboolean) pgendGetResults (be, is_gnucash_cb, (gpointer) FALSE);
+   if (FALSE == retval) {
+      xaccBackendSetError (&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.
@@ -1716,11 +1745,13 @@
    SEND_QUERY (be,p, FALSE);
    FINISH_QUERY(be->connection);
 
-   /* check to see if we can start a session of the desired type.  */
+   /* 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 */
+      /* 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.book_load = pgend_book_load_single_lockerr;
       xaccBackendSetError (&be->be, ERR_BACKEND_LOCKED);
       retval = FALSE;
@@ -1742,7 +1773,9 @@
 }
 
 /* ============================================================= */
-/* log end of session in the database. */
+/* The pgendSessionEnd() routine will log the end of session in 
+ *    the session table of the database. 
+ */
 
 static void
 pgendSessionEnd (PGBackend *be)
@@ -1764,6 +1797,11 @@
 }
 
 /* ============================================================= */
+/* The pgend_session_end() routine is the main entrypoint into
+ *    this backend for terminating a session.  It logs the
+ *    end of the session into the gncsession table,  disconnects
+ *    from the database, and finally frees all malloced memory.
+ */
 
 static void
 pgend_session_end (Backend *bend)
@@ -1806,8 +1844,11 @@
 }
 
 /* ============================================================= */
-/* the poll & event style load only loads accounts, never the
- * transactions. */
+/* 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. 
+ */
 
 static AccountGroup *
 pgend_book_load_poll (Backend *bend)
@@ -1832,8 +1873,12 @@
 }
 
 /* ============================================================= */
-/* The single-user mode loads all transactions.  Doesn't bother
- * with checkpoints */
+/* The pgend_book_load_single() routine loads the engine with
+ *    data from the database.  Used only in single-user mode,
+ *    it loads account *and* transaction data.  Single-user
+ *    mode doesn't require balance checkpoingts, to these are
+ *    not handled.
+ */
 
 static AccountGroup *
 pgend_book_load_single (Backend *bend)
@@ -1858,6 +1903,17 @@
 }
 
 /* ============================================================= */
+/* The pgend_session_begin() routine implements the main entrypoint
+ *    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 
+ *       initiate a user session.
+ *    3) It creates the GnuCash tables for the first time, if these
+ *       need to be created.
+ *    4) It logs the user session in the database (gncsession table).
+ *    5) loads data from the database into the engine.
+ */
 
 static void
 pgend_session_begin (GNCBook *sess, const char * sessionid, 
@@ -1897,7 +1953,7 @@
 
    if (strncmp (sessionid, "postgres://", 11)) 
    {
-      xaccBackendSetError (&be->be, ERR_SQL_BAD_LOCATION);
+      xaccBackendSetError (&be->be, ERR_BACKEND_BAD_URL);
       return;
    }
    url = g_strdup(sessionid);
@@ -1924,7 +1980,7 @@
    start = end+1;
    if (0x0 == *start) 
    { 
-      xaccBackendSetError (&be->be, ERR_SQL_BAD_LOCATION);
+      xaccBackendSetError (&be->be, ERR_BACKEND_BAD_URL);
       g_free(url); 
       return; 
    }
@@ -2062,7 +2118,7 @@
       }
       else
       {
-         xaccBackendSetError (&be->be, ERR_SQL_CANT_CONNECT);
+         xaccBackendSetError (&be->be, ERR_BACKEND_CANT_CONNECT);
          return;
       }
    }
@@ -2086,7 +2142,7 @@
               PQerrorMessage(be->connection));
          PQfinish (be->connection);
          be->connection = NULL;
-         xaccBackendSetError (&be->be, ERR_SQL_CANT_CONNECT);
+         xaccBackendSetError (&be->be, ERR_BACKEND_CANT_CONNECT);
          return;
       }
 
@@ -2117,7 +2173,7 @@
               PQerrorMessage(be->connection));
          PQfinish (be->connection);
          be->connection = NULL;
-         xaccBackendSetError (&be->be, ERR_SQL_CANT_CONNECT);
+         xaccBackendSetError (&be->be, ERR_BACKEND_CANT_CONNECT);
          return;
       }
 
@@ -2256,6 +2312,9 @@
 }
 
 /* ============================================================= */
+/* The pgendInit() routine initializes the backend private 
+ *    structures, mallocs any needed memory, etc.
+ */
 
 static void 
 pgendInit (PGBackend *be)
Index: gnucash/src/engine/sql/README
diff -u gnucash/src/engine/sql/README:1.23 gnucash/src/engine/sql/README:1.24
--- gnucash/src/engine/sql/README:1.23	Tue May  8 21:42:48 2001
+++ gnucash/src/engine/sql/README	Wed May  9 19:12:46 2001
@@ -12,11 +12,16 @@
 1) Install postgresql server, client and devel packages.
 2) if installed from redhat, then running /etc/rc.d/init.d/postgresql 
    will setup and initialize basic Postgres first-time setup & config.
-3) as root, su - postgres then run 'createuser' to add your user id
-4) (don't set a password on your postgres db name, yet, gnucash doesn't 
-    have a GUI to ask for your password yet)
+3) as root, 'su - postgres' then run 'createuser' to add your user id
+   (don't set a password on your postgres db name, yet, gnucash doesn't 
+   have a GUI to ask for your password yet)
+   If you've forgotten what users are on the system, you can check
+   by starting the 'psql' command shell and typing the command.
+   'SELECT * FROM pg_shadow;'
+   Note this wnly works for the posgres user, and other users that 
+   have creatuser permissions.
 
-5) (optional) enable TCPIP connections to remote hosts. To do this:
+4) (optional) enable TCPIP connections to remote hosts. To do this:
    edit the file pg_hba.conf on the remote host to configure and allow 
    access from other hosts.  See 'man pg_hba.conf' for details.  
         RedHat:   /var/lib/pgsql/pg_hba.conf  
@@ -26,9 +31,17 @@
    Note also the user must have 'createuser' permissions in order to 
    lock tables (this is a bug in postgres 6.5 and maybe later ???)
 
+5) Hints and Tips:  
+   If you've forgotten what databases you've created in the past,
+   you can look the filesystem: 'ls -la /var/lib/postgres/data/base'
+   to view the existing databases.  Alternately, if you connect as 
+   user postgres, you can 'SELECT * FROM pg_database;'
+
+
 Alternatively, you can install into a brand new database without
 using root privileges. After step 1 above, perform the following:
 
+1) Install postgresql server, client and devel packages.
 2) initdb -D ~/gnucash
    This creates a directory structure and supporting files
    under ~/gnucash. The gnucash directory is automatically 
@@ -54,6 +67,7 @@
    connections from processes on the local host.
 
 
+
 GnuCash Build Instructions
 --------------------------
 Same as usual, but you must specify the flag '--enable-sql' in order
@@ -76,6 +90,9 @@
 
 /usr/local/bin/gnucash postgres://localhost/dbname_whatever
 
+Note: GnuCash will automatically create the database if it does
+not already exist. Do *not* try to create the database by hand,
+or to specify a database that wasn't created by GnuCash.  
 
 Remote Access
 -------------
@@ -125,8 +142,6 @@
 
 -- distinguish between 'save' and 'save-as' in gnc-book & backend.
 
--- document the need for the 'gnucash' database & what its role is.
-
 -- single-update mode is asking to 'save' data  at end of session
    fix this (again,  ...)
 
@@ -141,6 +156,7 @@
    GUI dialogs. This is because the backend needs to return things
    like usernames, etc. in the dialogs, and the backend doesn't 
    have the interfaces for passing this kind of info.
+   (actually, the PERR/PINFO strings might do ??)
 
 -- fix the annoying postgres:,,localhost,asdf file syntax: needs
    mods to gnc-book to keep it happy about lock files & such.
@@ -152,9 +168,9 @@
    there will be other debilitating conditions if the backend disappears,
    leaving the engine in a possibly confused state.
 
-   for example, if postgres user is misconfigured, the LOCK TABLE
+   For example, if postgres user is misconfigured, the LOCK TABLE
    will fail on session validate, and FINISH_QUERY will close the
-   connection.  subsequent sql will core dump gnucash, even though this 
+   connection.  Subsequent sql will core dump gnucash, even though this 
    is a sysadmin error.
 
 -- during sync, detect and report conflicting edits to accounts 
@@ -214,7 +230,7 @@
    I don't currently have an opinion on the 'best' way of dealing with 
    this situation.
 
--- implement account rollback (i.e. of other user has modified the
+-- implement account rollback (i.e. if other user has modified the
    account, we need to do something to merge their work into ours...)
 
 -- transaction rollback is 'incorrect'; sort of ?? since we should
@@ -234,9 +250,10 @@
    note, however, that the file format needs to save the version number
    ...
 
--- Implement logging history in the SQL server.  i.e. save the old
-   copies of stuff in log tables.  Make the username part of the 
-   logging scheme.
+-- Implement logging history/audit-trail in the SQL server.  
+   i.e. save the old copies of stuff in log tables.  Make the username 
+   part of the logging scheme.   Having 'audit trails' is considered 
+   to be an important accounting feature.
 
 -- let all attached client receive update events via SQL LISTEN/NOTIFY 
    events.
Index: gnucash/src/engine/sql/design.txt
diff -u gnucash/src/engine/sql/design.txt:1.6 gnucash/src/engine/sql/design.txt:1.7
--- gnucash/src/engine/sql/design.txt:1.6	Sun Mar  4 00:54:56 2001
+++ gnucash/src/engine/sql/design.txt	Wed May  9 19:12:46 2001
@@ -75,9 +75,11 @@
 
 
 Connecting to Postgres
----------
-The postgres API requires a database to connect to. The initial
-connect is made using the "template1" database.
+----------------------
+The postgres API requires a database to connect to.  The initial
+connect is made using the "template1" database, which is the default
+database that is always created when Postgres is installed.  Thus,
+we assume its always present.
 
 
 m4 macros
@@ -132,3 +134,10 @@
 are not using NTP for time synchronization; or, e.g. if one machine failed 
 to have daylight-savings time set correctly: its transactions would be 
 an hour newer/older than the others, leading to bad updates).
+
+Balances
+--------
+UPDATE tx
+         SET (balance )= (SELECT expr from .... WHERE )
+WHERE txdate between today - 7 and today
+
Index: gnucash/src/engine/sql/putil.h
diff -u gnucash/src/engine/sql/putil.h:1.4 gnucash/src/engine/sql/putil.h:1.5
--- gnucash/src/engine/sql/putil.h:1.4	Tue May  8 21:42:48 2001
+++ gnucash/src/engine/sql/putil.h	Wed May  9 19:12:46 2001
@@ -58,6 +58,7 @@
 #define SEND_QUERY(be,buff,retval) 				\
 {								\
    int rc;							\
+   if (NULL == be->connection) return retval;			\
    rc = PQsendQuery (be->connection, buff);			\
    if (!rc)							\
    {								\
@@ -65,7 +66,8 @@
       PERR("send query failed:\n"				\
            "\t%s", PQerrorMessage(be->connection));		\
       PQfinish (be->connection);				\
-      xaccBackendSetError (&be->be, ERR_SQL_SEND_QUERY_FAILED);	\
+      be->connection = NULL;					\
+      xaccBackendSetError (&be->be, ERR_BACKEND_CONN_LOST);	\
       return retval;						\
    }								\
 }
@@ -93,7 +95,9 @@
               "\t%s", PQerrorMessage((conn)));			\
          PQclear(result);					\
          PQfinish ((conn));					\
-         xaccBackendSetError (&be->be, ERR_SQL_FINISH_QUERY_FAILED);	\
+         be->connection = NULL;					\
+         xaccBackendSetError (&be->be, ERR_BACKEND_CONN_LOST);	\
+	 break;							\
       }								\
       PQclear(result);						\
       i++;							\
@@ -118,7 +122,8 @@
            "\t%s", PQerrorMessage((conn)));			\
       PQclear (result);						\
       PQfinish (conn);						\
-      xaccBackendSetError (&be->be, ERR_SQL_GET_RESULT_FAILED);	\
+      be->connection = NULL;					\
+      xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR);	\
       break;							\
    }								\
 }
@@ -138,7 +143,7 @@
    }								\
    if (1 < nrows) {						\
       PERR ("unexpected duplicate records");			\
-      xaccBackendSetError (&be->be, ERR_SQL_CORRUPT_DB);	\
+      xaccBackendSetError (&be->be, ERR_BACKEND_DATA_CORRUPT);	\
       break;							\
    } else if (1 == nrows) 
 
Index: gnucash/src/gnome/new-user-callbacks.c
diff -u gnucash/src/gnome/new-user-callbacks.c:1.5 gnucash/src/gnome/new-user-callbacks.c:1.6
--- gnucash/src/gnome/new-user-callbacks.c:1.5	Fri Apr 13 01:54:25 2001
+++ gnucash/src/gnome/new-user-callbacks.c	Thu May 10 11:15:07 2001
@@ -28,6 +28,7 @@
 
 #include <gnome.h>
 
+#include "gnc-book.h"
 #include "new-user-callbacks.h"
 #include "new-user-interface.h"
 #include "gnc-commodity-edit.h"
@@ -36,11 +37,24 @@
 #include "gnc-ui-util.h"
 #include "gnc-dir.h"
 #include "io-example-account.h"
+#include "FileDialog.h"
 #include <guile/gh.h>
 
 static int commodEditAdded = 0;
 
+static AccountGroup *our_final_group = NULL;
+
 static void
+delete_our_final_group(void)
+{
+    if(our_final_group != NULL)
+    {
+        xaccFreeAccountGroup(our_final_group);
+        our_final_group = NULL;
+    }
+}
+
+static void
 set_first_startup(int first_startup)
 {
     gchar *todo;
@@ -88,8 +102,15 @@
     /* now we need to load all the accounts into the program */
 
     gh_eval_str("(gnc:show-main-window)");
+    gh_eval_str("(gnc:hook-run-danglers gnc:*book-opened-hook* #f)");
 
     set_first_startup(0);
+
+    if(our_final_group)
+    {
+        xaccGroupConcatGroup(gnc_book_get_group(gncGetCurrentBook()),
+                             our_final_group);
+    }
 }
 
 
@@ -114,6 +135,8 @@
                               "newAccountCancelDialog_RunAgainToggle")));
 
     set_first_startup(keepshowing);
+
+    delete_our_final_group();
     
     gnc_ui_delete_new_user_window();
     gnc_ui_delete_nu_cancel_dialog();
@@ -121,9 +144,9 @@
     
     gh_eval_str("(gnc:default-ui-start)");
     gh_eval_str("(gnc:show-main-window)");
+    gh_eval_str("(gnc:hook-run-danglers gnc:*book-opened-hook* #f)");
 }
 
-
 void
 on_newAccountCurrencyChoosePage_prepare (GnomeDruidPage  *gnomedruidpage,
                                          gpointer         arg1,
@@ -131,21 +154,14 @@
 {
     /* need to load currency info here.  In fact drop a
        gnc-commodity-edit widget here */
-    GtkWidget *commodityWid;
-    GtkWidget *vbox;
-
     if(!commodEditAdded)
     {
         commodEditAdded = 1;
-        commodityWid = gnc_commodity_edit_new();
-        gtk_widget_show(commodityWid);
-        gnc_commodity_edit_set_commodity(GNC_COMMODITY_EDIT(commodityWid),
-                                         gnc_locale_default_currency());
-        
-        vbox = lookup_widget(GTK_WIDGET(gnomedruidpage),
-                             "newAccountCurrencyChooser_vbox");
         
-        gtk_box_pack_start(GTK_BOX(vbox), commodityWid, FALSE, FALSE, 0);
+        gtk_box_pack_start(
+            GTK_BOX(lookup_widget(GTK_WIDGET(gnomedruidpage),
+                                  "newAccountCurrencyChooser_vbox")),
+            GTK_WIDGET(gnc_get_new_user_commodity_editor()), FALSE, FALSE, 0);
     }
     
 }
@@ -172,6 +188,7 @@
                                         gpointer         arg1,
                                         gpointer         user_data)
 {
+    static gboolean addedAccountLists = 0;
     GSList *list;
     GtkCList *clist;
     
@@ -179,13 +196,17 @@
 
     list = gnc_load_example_account_list(GNC_ACCOUNTS_DIR "/C");
 
-    clist = GTK_CLIST(lookup_widget(GTK_WIDGET(gnomedruidpage),
-                                    "newAccountTypesList"));
+    clist = gnc_new_user_get_clist();
+    
     gtk_clist_freeze(clist);
 
     gtk_clist_set_sort_column(clist, 0);
 
-    g_slist_foreach(list, add_each_gea_to_clist, (gpointer)clist);
+    if(!addedAccountLists)
+    {
+        g_slist_foreach(list, add_each_gea_to_clist, (gpointer)clist);
+        addedAccountLists = 1;
+    }
 
     gtk_clist_sort(clist);
     gtk_clist_thaw(clist);
@@ -204,7 +225,39 @@
     /* need to fill up the account list info here */
 }
 
+static gpointer
+add_to_tree_account(Account* toadd, gpointer data)
+{
+    GtkWidget *item;
+    GtkTree *tree = GTK_TREE(data);
+    
+    if(!toadd)
+    {
+        return NULL;
+    }
+    
+    item = gtk_tree_item_new_with_label(xaccAccountGetName(toadd));
+    gtk_tree_insert(tree, item, 0);
+    gtk_widget_show(item);
 
+    if(xaccGroupGetNumSubAccounts(xaccAccountGetChildren(toadd)) > 0)
+    {
+        GtkWidget *subtree = gtk_tree_new();
+        gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
+        gtk_tree_item_expand(GTK_TREE_ITEM(item));
+        xaccGroupForEachAccount(xaccAccountGetChildren(toadd),
+                                add_to_tree_account, subtree, FALSE);
+    }
+
+    return NULL;
+}
+
+static void
+add_to_tree(GtkTree *tree, AccountGroup *grp)
+{
+    xaccGroupForEachAccount(grp, add_to_tree_account, tree, FALSE);
+}
+
 void
 on_newAccountTypesList_select_row      (GtkCList        *clist,
                                         gint             row,
@@ -212,7 +265,29 @@
                                         GdkEvent        *event,
                                         gpointer         user_data)
 {
-    /* need to fill in useful data on a select row */
+    GtkText *datext =
+    GTK_TEXT(gnc_new_user_get_widget("newAccountTypesDescription"));
+    GtkTree *datree =
+    GTK_TREE(gnc_new_user_get_widget("newAccountListTree"));
+    GncExampleAccount *gea =
+    (GncExampleAccount*)gtk_clist_get_row_data(clist, row);
+
+    gtk_text_freeze(datext);
+    gtk_text_set_point(datext, 0);
+    gtk_text_forward_delete(datext, gtk_text_get_length(datext));
+    if(gea->long_description != NULL)
+    {
+        gtk_text_set_editable(datext, TRUE);
+        gtk_text_insert(datext, NULL, NULL, NULL, gea->long_description, -1);
+        gtk_text_set_editable(datext, FALSE);
+    }
+    gtk_text_thaw(datext);
+
+    gtk_tree_clear_items(datree, 0, 1000);
+    add_to_tree(datree, gea->group);
+
+    printf("%s", "");
+    
 }
 
 
@@ -231,7 +306,6 @@
 on_newAccountSelectAllButton_clicked   (GtkButton       *button,
                                         gpointer         user_data)
 {
-
 }
 
 
@@ -258,24 +332,121 @@
                                         (GtkButton       *button,
                                         gpointer         user_data)
 {
-
+    gtk_clist_select_all(gnc_new_user_get_clist());
 }
 
-
 void
-on_ctree1_select_row                   (GtkCList        *clist,
-                                        gint             row,
-                                        gint             column,
-                                        GdkEvent        *event,
+on_newAccountsTypeList_ClearAllButton_clicked
+                                        (GtkButton       *button,
                                         gpointer         user_data)
 {
+    gtk_clist_unselect_all(gnc_new_user_get_clist());
+}
+
+struct FinalInsertData_struct
+{
+    GtkCTree *tree;
+    GtkCTreeNode *node;
+    GtkCTreeNode *sibling;
+};
+typedef struct FinalInsertData_struct FinalInsertData;
+
+static gchar**
+generate_account_titles(Account *act)
+{
+    gchar **ret;
+
+    ret = g_new(gchar *, 3);
+
+    ret[0] = (gchar*)xaccAccountGetName(act);
+    ret[1] = xaccAccountTypeEnumAsString(xaccAccountGetType(act));
+    ret[2] = "";
+
+    return ret;
+}
+
+static void
+free_account_titles(gchar **tofree)
+{
+    g_free(tofree);
+}
+
+static gpointer
+add_to_ctree_final_account(Account* toadd, gpointer data)
+{
+    FinalInsertData *topdata = (FinalInsertData*)data;
+    GtkCTreeNode *node;
+    gchar **titles;
+
+    titles = generate_account_titles (toadd);
+    
+    node = gtk_ctree_insert_node(topdata->tree, topdata->node,
+                                 topdata->sibling, 
+                                 titles, 0,
+                                 NULL, NULL, NULL, NULL,
+                                 FALSE, TRUE);
+    /* don't know if this is safe, so commented out at the moment. FIXME! */
+    /* free_account_titles(titles); */
+
+    if(xaccGroupGetNumAccounts(xaccAccountGetChildren(toadd)) > 0)
+    {
+        FinalInsertData nextdata;
+        nextdata.tree = topdata->tree;
+        nextdata.node = node;
+        nextdata.sibling = NULL;
+
+        xaccGroupForEachAccount(xaccAccountGetChildren(toadd),
+                                add_to_ctree_final_account, &nextdata, FALSE);
+    }
 
+    topdata->sibling = node;
+
+    return NULL;
 }
 
+void
+gnc_new_user_insert_final_accounts(GtkCTree *tree, AccountGroup *group)
+{
+    FinalInsertData data;
+    data.tree = tree;
+    data.node = NULL;
+    data.sibling = NULL;
+
+    xaccGroupForEachAccount(group, add_to_ctree_final_account, &data, FALSE);
+}
 
 void
 on_finalAccountDruidPage_prepare       (GnomeDruidPage  *gnomedruidpage,
                                         gpointer         arg1,
+                                        gpointer         user_data)
+{
+    GList *dalist;
+    GSList *actlist = NULL;
+    GtkCList *clist = gnc_new_user_get_clist();
+
+    gtk_clist_clear(GTK_CLIST(gnc_new_user_get_widget("finalAccountCTree")));
+    
+    for(dalist = clist->selection; dalist; dalist = dalist->next)
+    {
+        int row = GPOINTER_TO_INT(dalist->data);
+        actlist = g_slist_append(actlist, gtk_clist_get_row_data(clist, row));
+    }
+
+    delete_our_final_group();
+    our_final_group = gnc_new_user_merge_groups(actlist);
+
+    gnc_new_user_insert_final_accounts(
+        GTK_CTREE(gnc_new_user_get_widget("finalAccountCTree")),
+        our_final_group);
+}
+
+
+
+void
+on_finalAccountCTree_select_row        (GtkCList        *clist,
+                                        gint             row,
+                                        gint             column,
+                                        GdkEvent        *event,
                                         gpointer         user_data)
 {
 
Index: gnucash/src/gnome/new-user-callbacks.h
diff -u gnucash/src/gnome/new-user-callbacks.h:1.5 gnucash/src/gnome/new-user-callbacks.h:1.6
--- gnucash/src/gnome/new-user-callbacks.h:1.5	Fri Apr 13 01:54:25 2001
+++ gnucash/src/gnome/new-user-callbacks.h	Thu May 10 11:15:07 2001
@@ -80,9 +80,6 @@
                                         GdkEvent        *event,
                                         gpointer         user_data);
 
-
-#endif /* _NEW_USER_CALLBACKS_H_ */    
-
 void
 on_newAccountSelectAllButton_clicked   (GtkButton       *button,
                                         gpointer         user_data);
@@ -108,14 +105,22 @@
                                         (GtkButton       *button,
                                         gpointer         user_data);
 
+void
+on_finalAccountDruidPage_prepare       (GnomeDruidPage  *gnomedruidpage,
+                                        gpointer         arg1,
+                                        gpointer         user_data);
+void
+on_newAccountsTypeList_ClearAllButton_clicked
+                                        (GtkButton       *button,
+                                        gpointer         user_data);
+
 void
-on_ctree1_select_row                   (GtkCList        *clist,
+on_finalAccountCTree_select_row        (GtkCList        *clist,
                                         gint             row,
                                         gint             column,
                                         GdkEvent        *event,
                                         gpointer         user_data);
 
-void
-on_finalAccountDruidPage_prepare       (GnomeDruidPage  *gnomedruidpage,
-                                        gpointer         arg1,
-                                        gpointer         user_data);
+#endif /* _NEW_USER_CALLBACKS_H_ */    
+
+
Index: gnucash/src/gnome/new-user-funs.c
diff -u gnucash/src/gnome/new-user-funs.c:1.4 gnucash/src/gnome/new-user-funs.c:1.5
--- gnucash/src/gnome/new-user-funs.c:1.4	Fri Mar  2 20:14:18 2001
+++ gnucash/src/gnome/new-user-funs.c	Thu May 10 11:15:07 2001
@@ -30,13 +30,130 @@
 #include "new-user-callbacks.h"
 #include "new-user-interface.h"
 #include "new-user-funs.h"
+#include "glade-support.h"
+#include "gnc-currency-edit.h"
+#include "gnc-ui-util.h"
 
+#include "Group.h"
+#include "io-example-account.h"
+#include "Account.h"
+#include "AccountP.h"
+
 #include <guile/gh.h>
 
 static GtkWidget *newUserDialog = NULL;
 static GtkWidget *cancelDialog = NULL;
 static GtkWidget *accountList = NULL;
 
+static Account*
+clone_account(const Account* from, gnc_commodity *com)
+{
+    Account *ret;
+
+    ret = xaccCloneAccountSimple(from);
+    ret->currency    = com;
+
+    return ret;
+}
+
+GNCCommodityEdit *
+gnc_get_new_user_commodity_editor(void)
+{
+    static GNCCommodityEdit *cur_editor = NULL;
+    if(!cur_editor)
+    {
+        cur_editor = GNC_COMMODITY_EDIT(gnc_commodity_edit_new());
+        gtk_widget_set_name (GTK_WIDGET(cur_editor),
+                             "newAccountCurrencyChooser");
+        gtk_widget_show(GTK_WIDGET(cur_editor));
+        gnc_commodity_edit_set_commodity(cur_editor,
+                                         gnc_locale_default_currency());
+    }
+    return cur_editor;
+}
+
+struct add_group_data_struct
+{
+    AccountGroup *to;
+    gnc_commodity *com;
+};
+
+static gpointer
+add_groups_for_each(Account *toadd, gpointer data)
+{
+    struct add_group_data_struct *dadata =
+    (struct add_group_data_struct*)data;
+    Account *foundact;
+    
+    foundact = xaccGetAccountFromName(dadata->to, xaccAccountGetName(toadd));
+
+    if(!foundact)
+    {
+        foundact = clone_account(toadd, dadata->com);
+
+        xaccGroupInsertAccount(dadata->to, foundact);
+    }
+    
+    {
+        AccountGroup *addgrp = xaccAccountGetChildren(toadd);
+
+        if(xaccGroupGetNumAccounts(addgrp) > 0)
+        {
+            struct add_group_data_struct downdata;
+            downdata.to = xaccAccountGetChildren(foundact);
+            downdata.com = dadata->com;
+            xaccGroupForEachAccount(addgrp, add_groups_for_each,
+                                    &downdata, FALSE);
+        }
+    }
+    return NULL;
+}
+
+static void
+add_groups_to_with_random_guids(AccountGroup *into, AccountGroup *from,
+                                gnc_commodity *com)
+{
+    struct add_group_data_struct data;
+    data.to = into;
+    data.com = com;
+    
+    xaccGroupForEachAccount(from, add_groups_for_each, &data, FALSE);
+}
+
+
+AccountGroup*
+gnc_new_user_merge_groups(GSList *dalist)
+{
+    GSList *mark;
+    gnc_commodity *com;
+    AccountGroup *ret = xaccMallocAccountGroup();
+
+    com = gnc_commodity_edit_get_commodity(
+        gnc_get_new_user_commodity_editor());
+    
+    for(mark = dalist; mark; mark = mark->next)
+    {
+        add_groups_to_with_random_guids(
+            ret, ((GncExampleAccount*)mark->data)->group, com);
+    }
+
+    return ret;
+}
+
+GtkWidget*
+gnc_new_user_get_widget(const char *name)
+{
+    return lookup_widget(newUserDialog, name);
+}
+
+GtkCList*
+gnc_new_user_get_clist(void)
+{
+    return GTK_CLIST(gnc_new_user_get_widget("newAccountTypesList"));
+}
+
+
+/***********************************************************************/
 static int
 createit(GtkWidget*(*creator)(), GtkWidget** placetoput)
 {
Index: gnucash/src/gnome/new-user-funs.h
diff -u gnucash/src/gnome/new-user-funs.h:1.2 gnucash/src/gnome/new-user-funs.h:1.3
--- gnucash/src/gnome/new-user-funs.h:1.2	Fri Mar  2 20:14:18 2001
+++ gnucash/src/gnome/new-user-funs.h	Thu May 10 11:15:07 2001
@@ -23,6 +23,11 @@
 #ifndef _NEW_USER_FUNS_H_
 #define _NEW_USER_FUNS_H_
 
+#include <glib.h>
+
+#include "gnc-commodity-edit.h"
+#include "Group.h"
+
 int gnc_ui_show_new_user_window(void);
 int gnc_ui_delete_new_user_window(void);
 
@@ -31,5 +36,10 @@
 
 int gnc_ui_show_nu_account_list(void);
 int gnc_ui_delete_nu_account_list(void);
+
+GtkCList* gnc_new_user_get_clist(void);
+GtkWidget* gnc_new_user_get_widget(const char *name);
+AccountGroup* gnc_new_user_merge_groups(GSList *dalist);
+GNCCommodityEdit * gnc_get_new_user_commodity_editor(void);
 
 #endif /* NEW_USER_FUNS_H */
Index: gnucash/src/gnome/new-user-interface.c
diff -u gnucash/src/gnome/new-user-interface.c:1.8 gnucash/src/gnome/new-user-interface.c:1.9
--- gnucash/src/gnome/new-user-interface.c:1.8	Thu May  3 02:56:47 2001
+++ gnucash/src/gnome/new-user-interface.c	Thu May 10 11:15:07 2001
@@ -46,7 +46,7 @@
   GtkWidget *newAccountTypesList_DescriptionLabel;
   GtkWidget *hbox1;
   GtkWidget *scrolledwindow2;
-  GtkWidget *accountTypesDescription;
+  GtkWidget *newAccountTypesDescription;
   GtkWidget *scrolledwindow3;
   GtkWidget *viewport1;
   GtkWidget *newAccountListTree;
@@ -58,10 +58,10 @@
   GdkColor finalAccountDruidPage_logo_bg_color = { 0, 65535, 65535, 65535 };
   GdkColor finalAccountDruidPage_title_color = { 0, 65535, 65535, 65535 };
   GtkWidget *druid_vbox3;
-  GtkWidget *label6;
+  GtkWidget *finalAccountLabel;
   GtkWidget *hbox4;
   GtkWidget *scrolledwindow4;
-  GtkWidget *ctree1;
+  GtkWidget *finalAccountCTree;
   GtkWidget *checkAccountList_AccountNameLabel;
   GtkWidget *checkAccountList_TypeLabel;
   GtkWidget *checkAccountList_StartBalanceLabel;
@@ -80,6 +80,7 @@
   gtk_object_set_data (GTK_OBJECT (newUserDialog), "newUserDialog", newUserDialog);
   gtk_widget_set_usize (newUserDialog, 540, 370);
   gtk_window_set_title (GTK_WINDOW (newUserDialog), _("New User Account setup"));
+  gtk_window_set_position (GTK_WINDOW (newUserDialog), GTK_WIN_POS_MOUSE);
   gtk_window_set_default_size (GTK_WINDOW (newUserDialog), 640, 480);
 
   accountChooseDruidPage = gnome_druid_new ();
@@ -222,15 +223,14 @@
   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow2, TRUE, TRUE, 0);
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
 
-  accountTypesDescription = gtk_text_new (NULL, NULL);
-  gtk_widget_set_name (accountTypesDescription, "accountTypesDescription");
-  gtk_widget_ref (accountTypesDescription);
-  gtk_object_set_data_full (GTK_OBJECT (newUserDialog), "accountTypesDescription", accountTypesDescription,
-                            (GtkDestroyNotify) gtk_widget_unref);
-  gtk_widget_show (accountTypesDescription);
-  gtk_container_add (GTK_CONTAINER (scrolledwindow2), accountTypesDescription);
-  gtk_widget_set_sensitive (accountTypesDescription, FALSE);
-  GTK_WIDGET_UNSET_FLAGS (accountTypesDescription, GTK_CAN_FOCUS);
+  newAccountTypesDescription = gtk_text_new (NULL, NULL);
+  gtk_widget_set_name (newAccountTypesDescription, "newAccountTypesDescription");
+  gtk_widget_ref (newAccountTypesDescription);
+  gtk_object_set_data_full (GTK_OBJECT (newUserDialog), "newAccountTypesDescription", newAccountTypesDescription,
+                            (GtkDestroyNotify) gtk_widget_unref);
+  gtk_widget_show (newAccountTypesDescription);
+  gtk_container_add (GTK_CONTAINER (scrolledwindow2), newAccountTypesDescription);
+  GTK_WIDGET_UNSET_FLAGS (newAccountTypesDescription, GTK_CAN_FOCUS);
 
   scrolledwindow3 = gtk_scrolled_window_new (NULL, NULL);
   gtk_widget_set_name (scrolledwindow3, "scrolledwindow3");
@@ -256,7 +256,6 @@
                             (GtkDestroyNotify) gtk_widget_unref);
   gtk_widget_show (newAccountListTree);
   gtk_container_add (GTK_CONTAINER (viewport1), newAccountListTree);
-  gtk_widget_set_sensitive (newAccountListTree, FALSE);
 
   hbox3 = gtk_hbox_new (FALSE, 0);
   gtk_widget_set_name (hbox3, "hbox3");
@@ -301,17 +300,17 @@
                             (GtkDestroyNotify) gtk_widget_unref);
   gtk_widget_show (druid_vbox3);
 
-  label6 = gtk_label_new (_("If you would like the accounts to have a starting balance click on the account line and enter the starting balance in the text entry box on the right."));
-  gtk_widget_set_name (label6, "label6");
-  gtk_widget_ref (label6);
-  gtk_object_set_data_full (GTK_OBJECT (newUserDialog), "label6", label6,
-                            (GtkDestroyNotify) gtk_widget_unref);
-  gtk_widget_show (label6);
-  gtk_box_pack_start (GTK_BOX (druid_vbox3), label6, FALSE, FALSE, 0);
-  gtk_label_set_justify (GTK_LABEL (label6), GTK_JUSTIFY_FILL);
-  gtk_label_set_line_wrap (GTK_LABEL (label6), TRUE);
-  gtk_misc_set_alignment (GTK_MISC (label6), 0.0800003, 0.08);
-  gtk_misc_set_padding (GTK_MISC (label6), 1, 1);
+  finalAccountLabel = gtk_label_new (_("If you would like the accounts to have a starting balance click on the account line and enter the starting balance in the text entry box on the right."));
+  gtk_widget_set_name (finalAccountLabel, "finalAccountLabel");
+  gtk_widget_ref (finalAccountLabel);
+  gtk_object_set_data_full (GTK_OBJECT (newUserDialog), "finalAccountLabel", finalAccountLabel,
+                            (GtkDestroyNotify) gtk_widget_unref);
+  gtk_widget_show (finalAccountLabel);
+  gtk_box_pack_start (GTK_BOX (druid_vbox3), finalAccountLabel, FALSE, FALSE, 0);
+  gtk_label_set_justify (GTK_LABEL (finalAccountLabel), GTK_JUSTIFY_FILL);
+  gtk_label_set_line_wrap (GTK_LABEL (finalAccountLabel), TRUE);
+  gtk_misc_set_alignment (GTK_MISC (finalAccountLabel), 0.0800003, 0.08);
+  gtk_misc_set_padding (GTK_MISC (finalAccountLabel), 1, 1);
 
   hbox4 = gtk_hbox_new (FALSE, 0);
   gtk_widget_set_name (hbox4, "hbox4");
@@ -329,17 +328,17 @@
   gtk_widget_show (scrolledwindow4);
   gtk_box_pack_start (GTK_BOX (hbox4), scrolledwindow4, TRUE, TRUE, 0);
 
-  ctree1 = gtk_ctree_new (3, 0);
-  gtk_widget_set_name (ctree1, "ctree1");
-  gtk_widget_ref (ctree1);
-  gtk_object_set_data_full (GTK_OBJECT (newUserDialog), "ctree1", ctree1,
-                            (GtkDestroyNotify) gtk_widget_unref);
-  gtk_widget_show (ctree1);
-  gtk_container_add (GTK_CONTAINER (scrolledwindow4), ctree1);
-  gtk_clist_set_column_width (GTK_CLIST (ctree1), 0, 285);
-  gtk_clist_set_column_width (GTK_CLIST (ctree1), 1, 118);
-  gtk_clist_set_column_width (GTK_CLIST (ctree1), 2, 80);
-  gtk_clist_column_titles_show (GTK_CLIST (ctree1));
+  finalAccountCTree = gtk_ctree_new (3, 0);
+  gtk_widget_set_name (finalAccountCTree, "finalAccountCTree");
+  gtk_widget_ref (finalAccountCTree);
+  gtk_object_set_data_full (GTK_OBJECT (newUserDialog), "finalAccountCTree", finalAccountCTree,
+                            (GtkDestroyNotify) gtk_widget_unref);
+  gtk_widget_show (finalAccountCTree);
+  gtk_container_add (GTK_CONTAINER (scrolledwindow4), finalAccountCTree);
+  gtk_clist_set_column_width (GTK_CLIST (finalAccountCTree), 0, 285);
+  gtk_clist_set_column_width (GTK_CLIST (finalAccountCTree), 1, 118);
+  gtk_clist_set_column_width (GTK_CLIST (finalAccountCTree), 2, 80);
+  gtk_clist_column_titles_show (GTK_CLIST (finalAccountCTree));
 
   checkAccountList_AccountNameLabel = gtk_label_new (_("Account Name"));
   gtk_widget_set_name (checkAccountList_AccountNameLabel, "checkAccountList_AccountNameLabel");
@@ -347,7 +346,7 @@
   gtk_object_set_data_full (GTK_OBJECT (newUserDialog), "checkAccountList_AccountNameLabel", checkAccountList_AccountNameLabel,
                             (GtkDestroyNotify) gtk_widget_unref);
   gtk_widget_show (checkAccountList_AccountNameLabel);
-  gtk_clist_set_column_widget (GTK_CLIST (ctree1), 0, checkAccountList_AccountNameLabel);
+  gtk_clist_set_column_widget (GTK_CLIST (finalAccountCTree), 0, checkAccountList_AccountNameLabel);
 
   checkAccountList_TypeLabel = gtk_label_new (_("Type"));
   gtk_widget_set_name (checkAccountList_TypeLabel, "checkAccountList_TypeLabel");
@@ -355,7 +354,7 @@
   gtk_object_set_data_full (GTK_OBJECT (newUserDialog), "checkAccountList_TypeLabel", checkAccountList_TypeLabel,
                             (GtkDestroyNotify) gtk_widget_unref);
   gtk_widget_show (checkAccountList_TypeLabel);
-  gtk_clist_set_column_widget (GTK_CLIST (ctree1), 1, checkAccountList_TypeLabel);
+  gtk_clist_set_column_widget (GTK_CLIST (finalAccountCTree), 1, checkAccountList_TypeLabel);
 
   checkAccountList_StartBalanceLabel = gtk_label_new (_("Starting Balance"));
   gtk_widget_set_name (checkAccountList_StartBalanceLabel, "checkAccountList_StartBalanceLabel");
@@ -363,7 +362,7 @@
   gtk_object_set_data_full (GTK_OBJECT (newUserDialog), "checkAccountList_StartBalanceLabel", checkAccountList_StartBalanceLabel,
                             (GtkDestroyNotify) gtk_widget_unref);
   gtk_widget_show (checkAccountList_StartBalanceLabel);
-  gtk_clist_set_column_widget (GTK_CLIST (ctree1), 2, checkAccountList_StartBalanceLabel);
+  gtk_clist_set_column_widget (GTK_CLIST (finalAccountCTree), 2, checkAccountList_StartBalanceLabel);
 
   vbox5 = gtk_vbox_new (FALSE, 0);
   gtk_widget_set_name (vbox5, "vbox5");
@@ -435,11 +434,14 @@
   gtk_signal_connect (GTK_OBJECT (newAccountsTypeList_SelectAllButton), "clicked",
                       GTK_SIGNAL_FUNC (on_newAccountsTypeList_SelectAllButton_clicked),
                       NULL);
+  gtk_signal_connect (GTK_OBJECT (newAccountsTypeList_ClearAllButton), "clicked",
+                      GTK_SIGNAL_FUNC (on_newAccountsTypeList_ClearAllButton_clicked),
+                      NULL);
   gtk_signal_connect (GTK_OBJECT (finalAccountDruidPage), "prepare",
                       GTK_SIGNAL_FUNC (on_finalAccountDruidPage_prepare),
                       NULL);
-  gtk_signal_connect (GTK_OBJECT (ctree1), "select_row",
-                      GTK_SIGNAL_FUNC (on_ctree1_select_row),
+  gtk_signal_connect (GTK_OBJECT (finalAccountCTree), "select_row",
+                      GTK_SIGNAL_FUNC (on_finalAccountCTree_select_row),
                       NULL);
   gtk_signal_connect (GTK_OBJECT (newUserDruidFinishPage), "finish",
                       GTK_SIGNAL_FUNC (on_newUserDruidFinishPage_finish),
Index: gnucash/src/gnome/new-user.glade
diff -u gnucash/src/gnome/new-user.glade:1.8 gnucash/src/gnome/new-user.glade:1.9
--- gnucash/src/gnome/new-user.glade:1.8	Thu May  3 02:56:47 2001
+++ gnucash/src/gnome/new-user.glade	Thu May 10 11:15:08 2001
@@ -29,7 +29,7 @@
   <height>370</height>
   <title>New User Account setup</title>
   <type>GTK_WINDOW_TOPLEVEL</type>
-  <position>GTK_WIN_POS_NONE</position>
+  <position>GTK_WIN_POS_MOUSE</position>
   <modal>False</modal>
   <default_width>640</default_width>
   <default_height>480</default_height>
@@ -259,8 +259,7 @@
 
 	    <widget>
 	      <class>GtkText</class>
-	      <name>accountTypesDescription</name>
-	      <sensitive>False</sensitive>
+	      <name>newAccountTypesDescription</name>
 	      <editable>False</editable>
 	      <text></text>
 	    </widget>
@@ -287,7 +286,6 @@
 	      <widget>
 		<class>GtkTree</class>
 		<name>newAccountListTree</name>
-		<sensitive>False</sensitive>
 		<selection_mode>GTK_SELECTION_SINGLE</selection_mode>
 		<view_mode>GTK_TREE_VIEW_LINE</view_mode>
 		<view_line>True</view_line>
@@ -329,6 +327,11 @@
 	    <class>GtkButton</class>
 	    <name>newAccountsTypeList_ClearAllButton</name>
 	    <can_focus>True</can_focus>
+	    <signal>
+	      <name>clicked</name>
+	      <handler>on_newAccountsTypeList_ClearAllButton_clicked</handler>
+	      <last_modification_time>Thu, 19 Apr 2001 14:27:32 GMT</last_modification_time>
+	    </signal>
 	    <label>Clear All</label>
 	    <relief>GTK_RELIEF_NORMAL</relief>
 	    <child>
@@ -368,7 +371,7 @@
 
 	<widget>
 	  <class>GtkLabel</class>
-	  <name>label6</name>
+	  <name>finalAccountLabel</name>
 	  <label>If you would like the accounts to have a starting balance click on the account line and enter the starting balance in the text entry box on the right.</label>
 	  <justify>GTK_JUSTIFY_FILL</justify>
 	  <wrap>True</wrap>
@@ -409,12 +412,12 @@
 
 	    <widget>
 	      <class>GtkCTree</class>
-	      <name>ctree1</name>
+	      <name>finalAccountCTree</name>
 	      <can_focus>True</can_focus>
 	      <signal>
 		<name>select_row</name>
-		<handler>on_ctree1_select_row</handler>
-		<last_modification_time>Thu, 12 Apr 2001 22:48:53 GMT</last_modification_time>
+		<handler>on_finalAccountCTree_select_row</handler>
+		<last_modification_time>Thu, 19 Apr 2001 17:26:51 GMT</last_modification_time>
 	      </signal>
 	      <columns>3</columns>
 	      <column_widths>285,118,80</column_widths>
Index: gnucash/src/guile/File.c
diff -u gnucash/src/guile/File.c:1.6 gnucash/src/guile/File.c:1.7
--- gnucash/src/guile/File.c:1.6	Mon Jan 15 22:40:38 2001
+++ gnucash/src/guile/File.c	Thu May 10 04:49:16 2001
@@ -51,15 +51,19 @@
 {
   char *full_filename = NULL;
   char *g_filename;
-
-  /* This should be gh_lookup, but that appears to be broken */
-  SCM find_doc_file = gh_eval_str("gnc:find-doc-file");
-  SCM scm_filename = gh_str02scm ((char *) filename);
+  SCM find_doc_file;
+  SCM scm_filename;
   SCM scm_result;
 
+  if (!filename || *filename == '\0')
+    return NULL;
+
+  /* This should be gh_lookup, but that appears to be broken */
+  find_doc_file = gh_eval_str("gnc:find-doc-file");
+  scm_filename = gh_str02scm ((char *) filename);
   scm_result = gh_call1(find_doc_file, scm_filename);
 
-  if (scm_result != SCM_BOOL_F)
+  if (gh_string_p(scm_result))
     full_filename = gh_scm2newstr(scm_result, NULL);
 
   g_filename = g_strdup (full_filename);
@@ -78,7 +82,7 @@
  * Global: helpPath - the path to the help files                    *
 \********************************************************************/
 int 
-gncReadFile (const char * file, char ** data )
+gncReadFile (const char * file, char ** data)
 {
   char *buf=NULL;
   char  *filename;
@@ -107,25 +111,25 @@
     PERR ("file was %s\n", file);
     return 0;
   }
-  
+
   /* Find size: */
   size = lseek( fd, 0, SEEK_END );
   lseek( fd, 0, SEEK_SET );
 
-  /* Allocate memory... don't use _malloc(), `cause it is
-   * freed elsewhere */
-  buf = (char *)malloc((size+1)*sizeof(char));
+  /* Allocate memory */
+  buf = g_new(char, size + 1);
 
   /* read in file */
   if( read(fd,buf,size) == -1 )
   {
-    free(buf);
+    g_free(buf);
     buf=NULL;
   }
-  buf[size] = 0x0;
-  
+  buf[size] = '\0';
+
   close(fd);
   *data = buf;
+
   return size;
 }
 
Index: gnucash/src/guile/gnc.gwp
diff -u gnucash/src/guile/gnc.gwp:1.92 gnucash/src/guile/gnc.gwp:1.93
--- gnucash/src/guile/gnc.gwp:1.92	Sat May  5 14:28:31 2001
+++ gnucash/src/guile/gnc.gwp	Wed May  9 19:12:47 2001
@@ -1860,8 +1860,13 @@
 
     (gw:enum-add-value! we "ERR_BACKEND_NO_ERR" 'no-err)
     (gw:enum-add-value! we "ERR_BACKEND_NO_BACKEND" 'no-backend)
-    (gw:enum-add-value! we "ERR_BACKEND_LOCKED" 'locked)
+    (gw:enum-add-value! we "ERR_BACKEND_BAD_URL" 'bad-url)
+    (gw:enum-add-value! we "ERR_BACKEND_CANT_CONNECT" 'cant-connect)
+    (gw:enum-add-value! we "ERR_BACKEND_CONN_LOST" 'connection-lost)
     (gw:enum-add-value! we "ERR_BACKEND_NO_SUCH_DB" 'no-such-db)
+    (gw:enum-add-value! we "ERR_BACKEND_LOCKED" 'locked)
+    (gw:enum-add-value! we "ERR_BACKEND_DATA_CORRUPT" 'data-corrupt)
+    (gw:enum-add-value! we "ERR_BACKEND_SERVER_ERR" 'server-error)
     (gw:enum-add-value! we "ERR_BACKEND_ALLOC" 'alloc)
     (gw:enum-add-value! we "ERR_BACKEND_MISC" 'misc)
   
@@ -1872,30 +1877,18 @@
     (gw:enum-add-value! we "ERR_FILEIO_FILE_TOO_NEW" 'file-too-new)
     (gw:enum-add-value! we "ERR_FILEIO_FILE_TOO_OLD" 'file-too-old)
   
-    (gw:enum-add-value! we "ERR_NETIO_NO_CONNECTION" 'netio-no-connection)
     (gw:enum-add-value! we "ERR_NETIO_SHORT_READ" 'netio-short-read)
     (gw:enum-add-value! we "ERR_NETIO_WRONG_CONTENT_TYPE"
                         'netio-wrong-content-type)
     (gw:enum-add-value! we "ERR_NETIO_NOT_GNCXML" 'netio-not-gncxml)
   
-    (gw:enum-add-value! we "ERR_SQL_BAD_LOCATION" 'sql-bad-location)
-    (gw:enum-add-value! we "ERR_SQL_CANT_CONNECT" 'sql-cant-connect)
-    (gw:enum-add-value! we "ERR_SQL_SEND_QUERY_FAILED" 'sql-send-query-failed)
-    (gw:enum-add-value! we "ERR_SQL_FINISH_QUERY_FAILED"
-                        'sql-finish-query-failed)
-    (gw:enum-add-value! we "ERR_SQL_GET_RESULT_FAILED" 'sql-get-result-failed)
-    (gw:enum-add-value! we "ERR_SQL_CORRUPT_DB" 'sql-corrupt-db)
     (gw:enum-add-value! we "ERR_SQL_MISSING_DATA" 'sql-missing-data)
 
-    (gw:enum-add-value! we "ERR_RPC_BAD_URL" 'rpc_bad_url)
     (gw:enum-add-value! we "ERR_RPC_HOST_UNK" 'rpc_host_unk)
-    (gw:enum-add-value! we "ERR_RPC_CANT_CONNECT" 'rpc_cant_connect)
     (gw:enum-add-value! we "ERR_RPC_CANT_BIND" 'rpc_cant_bind)
     (gw:enum-add-value! we "ERR_RPC_CANT_ACCEPT" 'rpc_cant_accept)
     (gw:enum-add-value! we "ERR_RPC_NO_CONNECTION" 'rpc_no_connection)
-    (gw:enum-add-value! we "ERR_RPC_CONNECTION_LOST" 'rpc_connection_lost)
     (gw:enum-add-value! we "ERR_RPC_BAD_VERSION" 'rpc_bad_version)
-    (gw:enum-add-value! we "ERR_RPC_SERVER_STATE" 'rpc_server_state)
     (gw:enum-add-value! we "ERR_RPC_FAILED" 'rpc_failed)
     (gw:enum-add-value! we "ERR_RPC_NOT_ADDED" 'rpc_not_added)
     #t)
Index: gnucash/src/scm/command-line.scm
diff -u gnucash/src/scm/command-line.scm:1.22 gnucash/src/scm/command-line.scm:1.23
--- gnucash/src/scm/command-line.scm:1.22	Thu May  3 02:56:51 2001
+++ gnucash/src/scm/command-line.scm	Thu May 10 04:33:00 2001
@@ -246,8 +246,9 @@
               (list value (cdr args)))))))
 
 (define (gnc:cmd-line-get-string-arg args)
-  (gnc:debug "got string arg returning " (car args) " and " (cdr args))
-  (list (car args) (cdr args)))
+  (if (pair? args)
+      (list (car args) (cdr args))
+      (begin (gnc:warn "no argument given where one expected") #f)))
 
 (define (gnc:prefs-show-version)
   (display "GnuCash ")
@@ -370,7 +371,7 @@
 
                       (if (not arg-parse-result)
                           (begin                
-                            (set result #f)
+                            (set! result #f)
                             (set! quit? #t))
                           (let ((parsed-value (car arg-parse-result))
                                 (remaining-args (cadr arg-parse-result)))
Index: gnucash/src/scm/commodity-utilities.scm
diff -u gnucash/src/scm/commodity-utilities.scm:1.13 gnucash/src/scm/commodity-utilities.scm:1.14
--- gnucash/src/scm/commodity-utilities.scm:1.13	Wed May  9 03:52:08 2001
+++ gnucash/src/scm/commodity-utilities.scm	Thu May 10 02:07:46 2001
@@ -65,7 +65,7 @@
 				 (not (gnc:commodity-equiv? 
 				       trans-comm acc-comm))
 				 (or
-				  commodity
+				  (not commodity)
 				  (gnc:commodity-equiv?
 				   commodity trans-comm)
 				  (gnc:commodity-equiv?
Index: gnucash/src/scm/html-utilities.scm
diff -u gnucash/src/scm/html-utilities.scm:1.35 gnucash/src/scm/html-utilities.scm:1.36
--- gnucash/src/scm/html-utilities.scm:1.35	Wed May  9 03:27:05 2001
+++ gnucash/src/scm/html-utilities.scm	Thu May 10 03:24:35 2001
@@ -192,83 +192,87 @@
 	 current-depth my-name my-commodity balance 
 	 reverse-balance? is-stock-account? main-row-style other-rows-style 
 	 boldface? group-header-line?) 
-  ;; Adds one row to the table. my-name is the html-object
-  ;; displayed in the name column; foreign-balance is the
-  ;; <gnc-monetary> for the foreign column or #f if to be left
-  ;; empty; domestic-balance is the <gnc-monetary> for the
-  ;; domestic column.
-  (define (commodity-row-helper! 
-	   my-name foreign-balance domestic-balance row-style)
-    (gnc:html-table-append-row/markup!
-     table
-     row-style
-     (append
-      ;; left third of the table
-      (gnc:html-make-empty-cells (- current-depth 1))
-      (list (gnc:html-acct-table-cell (+ 1 (- tree-depth current-depth))
-				      my-name boldface?))
-      ;; right two-thirds of the table
-      (gnc:html-make-empty-cells 
-       (* 2 (- tree-depth (+ current-depth (if group-header-line? 1 0)))))
-      (if boldface?
-	  (list 
-	   (and foreign-balance 
-		(gnc:make-html-text (gnc:html-markup-b foreign-balance)))
-	   (and domestic-balance
-		(gnc:make-html-text (gnc:html-markup-b domestic-balance))))
-	  (list foreign-balance domestic-balance))
-      (gnc:html-make-empty-cells (* 2 (- current-depth 
-					 (if group-header-line? 0 1)))))))
-  
-      ;;;;;;;;;;
-  ;; the first row for each account: shows the name and the
-  ;; balance in the report-commodity
-  (if (and (not is-stock-account?)
-	   ;; FIXME: need to check whether we really have only one
-	   ;; foreign currency if is-stock-account==#t.
-	   (gnc:commodity-equiv? my-commodity report-commodity))
-      ;; usual case: the account balance in terms of report
-      ;; commodity
-      (commodity-row-helper! 
-       my-name #f
-       (if balance 
-	   (balance 'getmonetary report-commodity reverse-balance?)
-	   #f)
-       main-row-style)
-      ;; Special case for stock-accounts: then the foreign commodity
-      ;; gets displayed in this line rather then the following lines
-      ;; (loop below). Is also used if is-stock-account? is true.
-      (let ((my-balance 
-	     (if balance (balance 'getmonetary 
-				  my-commodity reverse-balance?) #f)))
+  (let ((already-printed #f))
+    ;; Adds one row to the table. my-name is the html-object
+    ;; displayed in the name column; foreign-balance is the
+    ;; <gnc-monetary> for the foreign column or #f if to be left
+    ;; empty; domestic-balance is the <gnc-monetary> for the
+    ;; domestic column.
+    (define (commodity-row-helper! 
+	     my-name foreign-balance domestic-balance row-style)
+      (gnc:html-table-append-row/markup!
+       table
+       row-style
+       (append
+	;; left third of the table
+	(gnc:html-make-empty-cells (- current-depth 1))
+	(list (gnc:html-acct-table-cell (+ 1 (- tree-depth current-depth))
+					my-name boldface?))
+	;; right two-thirds of the table
+	(gnc:html-make-empty-cells 
+	 (* 2 (- tree-depth (+ current-depth (if group-header-line? 1 0)))))
+	(if boldface?
+	    (list 
+	     (and foreign-balance 
+		  (gnc:make-html-text (gnc:html-markup-b foreign-balance)))
+	     (and domestic-balance
+		  (gnc:make-html-text (gnc:html-markup-b domestic-balance))))
+	    (list foreign-balance domestic-balance))
+	(gnc:html-make-empty-cells (* 2 (- current-depth 
+					   (if group-header-line? 0 1)))))))
+    
+    ;;;;;;;;;;
+    ;; the first row for each account: shows the name and the
+    ;; balance in the report-commodity
+    (if (and (not is-stock-account?)
+	     ;; FIXME: need to check whether we really have only one
+	     ;; foreign currency if is-stock-account==#t.
+	     (gnc:commodity-equiv? my-commodity report-commodity))
+	;; usual case: the account balance in terms of report
+	;; commodity
 	(commodity-row-helper! 
-	 my-name
-	 my-balance
-	 (exchange-fn my-balance report-commodity)
-	 main-row-style)))
-  
-  ;; The additional rows: show no name, but the foreign currency
-  ;; balance and its corresponding value in the
-  ;; report-currency. One row for each non-report-currency. 
-  (if (and balance (not is-stock-account?))
-      (balance 
-       'format 
-       (lambda (curr val)
-	 (if (gnc:commodity-equiv? curr report-commodity)
-	     '()
-	     (let ((bal 
-		    (if reverse-balance?
-			(gnc:monetary-neg (gnc:make-gnc-monetary curr val))
-			(gnc:make-gnc-monetary curr val))))
-	       (commodity-row-helper!
-		;; print no account name 
-		(car (gnc:html-make-empty-cells 1))
-		;; print the account balance in the respective
-		;; commodity
-		bal
-		(exchange-fn bal report-commodity)
-		other-rows-style))))
-       #f)))
+	 my-name #f
+	 (if balance 
+	     (balance 'getmonetary report-commodity reverse-balance?)
+	     #f)
+	 main-row-style)
+	;; Special case for stock-accounts: then the foreign commodity
+	;; gets displayed in this line rather then the following lines
+	;; (loop below). Is also used if is-stock-account? is true.
+	(let ((my-balance 
+	       (if balance (balance 'getmonetary 
+				    my-commodity reverse-balance?) #f)))
+	  (set! already-printed my-commodity)
+	  (commodity-row-helper! 
+	   my-name
+	   my-balance
+	   (exchange-fn my-balance report-commodity)
+	   main-row-style)))
+    
+    ;; The additional rows: show no name, but the foreign currency
+    ;; balance and its corresponding value in the
+    ;; report-currency. One row for each non-report-currency. 
+    (if (and balance (not is-stock-account?))
+	(balance 
+	 'format 
+	 (lambda (curr val)
+	   (if (or (gnc:commodity-equiv? curr report-commodity)
+		   (and already-printed
+			(gnc:commodity-equiv? curr already-printed)))
+	       '()
+	       (let ((bal 
+		      (if reverse-balance?
+			  (gnc:monetary-neg (gnc:make-gnc-monetary curr val))
+			  (gnc:make-gnc-monetary curr val))))
+		 (commodity-row-helper!
+		  ;; print no account name 
+		  (car (gnc:html-make-empty-cells 1))
+		  ;; print the account balance in the respective
+		  ;; commodity
+		  bal
+		  (exchange-fn bal report-commodity)
+		  other-rows-style))))
+	 #f))))
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -419,7 +423,8 @@
       (gnc:html-acct-table-comm-row-helper!
        table tree-depth report-commodity exchange-fn
        current-depth my-name my-commodity balance 
-       reverse-balance? is-stock-account? main-row-style other-rows-style boldface? group-header-line?))
+       reverse-balance? is-stock-account? 
+       main-row-style other-rows-style boldface? group-header-line?))
         
     ;; Adds all appropriate rows to the table which belong to one
     ;; account. Uses the above helper function, i.e. here the
@@ -447,7 +452,8 @@
     ;; Generalization of add-account-rows! for a subtotal or for the
     ;; total balance.
     (define (add-subtotal-row! 
-	     current-depth subtotal-name balance row-style boldface? group-header-line?)
+	     current-depth subtotal-name balance 
+	     row-style boldface? group-header-line?)
       (if show-other-curr?
 	  (add-commodity-rows! current-depth subtotal-name 
 			       report-commodity 
Index: gnucash/src/scm/main.scm
diff -u gnucash/src/scm/main.scm:1.41 gnucash/src/scm/main.scm:1.42
--- gnucash/src/scm/main.scm:1.41	Fri May  4 03:16:46 2001
+++ gnucash/src/scm/main.scm	Thu May 10 11:15:34 2001
@@ -162,9 +162,6 @@
                       (gnc:lookup-global-option "__new_user" "first_startup")))
                     1))
             (begin
-              (gnc:default-ui-start)
-              (gnc:show-main-window)
-              (gnc:hook-run-danglers gnc:*book-opened-hook* #f)
               (gnc:show-new-user-window)
               (gnc:start-ui-event-loop))
             (begin
Index: gnucash/src/scm/report/account-summary.scm
diff -u gnucash/src/scm/report/account-summary.scm:1.37 gnucash/src/scm/report/account-summary.scm:1.38
--- gnucash/src/scm/report/account-summary.scm:1.37	Thu May  3 03:47:26 2001
+++ gnucash/src/scm/report/account-summary.scm	Thu May 10 03:24:37 2001
@@ -65,10 +65,9 @@
        options pagename-general optname-date "a")
 
       ;; all about currencies
-      (gnc:options-add-currency-selection!
+      (gnc:options-add-currency!
        options pagename-general 
-       optname-show-foreign optname-report-currency
-       "b")
+       optname-report-currency "b")
 
       ;; accounts to work on
       (gnc:options-add-account-selection! 
@@ -99,6 +98,12 @@
 	pagename-display optname-show-parent-total
 	"d" (N_ "Show subtotals for parent accounts") #t))
 
+      (gnc:register-option 
+       options
+       (gnc:make-simple-boolean-option
+	gnc:pagename-display optname-show-foreign 
+	"e" (N_ "Display the account's foreign currency amount?") #f))
+
       ;; Set the general page as default option tab
       (gnc:options-set-default-section options pagename-general)      
 
@@ -126,7 +131,7 @@
 					    optname-show-parent-balance))
           (show-parent-total? (get-option pagename-display
 					  optname-show-parent-total))
-	  (show-fcur? (get-option pagename-general optname-show-foreign))
+	  (show-fcur? (get-option pagename-display optname-show-foreign))
 	  (report-currency (get-option pagename-general 
 				       optname-report-currency))
           (date-tp (gnc:timepair-end-day-time 
Index: gnucash/src/scm/report/balance-sheet.scm
diff -u gnucash/src/scm/report/balance-sheet.scm:1.21 gnucash/src/scm/report/balance-sheet.scm:1.22
--- gnucash/src/scm/report/balance-sheet.scm:1.21	Mon Apr 30 21:14:18 2001
+++ gnucash/src/scm/report/balance-sheet.scm	Thu May 10 03:24:37 2001
@@ -77,10 +77,10 @@
        optname-to-date "a")
 
       ;; all about currencies
-      (gnc:options-add-currency-selection!
+      (gnc:options-add-currency!
        options gnc:pagename-general
-       optname-show-foreign optname-report-currency
-       "b")
+       optname-report-currency "b")
+
       (gnc:options-add-price-source! 
        options gnc:pagename-general
        optname-price-source "c" 'weighted-average)
@@ -113,8 +113,14 @@
       (gnc:register-option 
        options
        (gnc:make-simple-boolean-option
+	gnc:pagename-display optname-show-foreign 
+	"e" (N_ "Display the account's foreign currency amount?") #f))
+
+      (gnc:register-option 
+       options
+       (gnc:make-simple-boolean-option
 	gnc:pagename-display optname-show-rates
-	"e" (N_ "Show the exchange rates used") #f))
+	"f" (N_ "Show the exchange rates used") #f))
 
       ;; Set the general page as default option tab
       (gnc:options-set-default-section options gnc:pagename-general)      
@@ -143,7 +149,7 @@
 					     optname-show-parent-balance))
 	   (show-parent-total? (get-option gnc:pagename-display
 					   optname-show-parent-total))
-	   (show-fcur? (get-option gnc:pagename-general
+	   (show-fcur? (get-option gnc:pagename-display
 				   optname-show-foreign))
 	   (report-currency (get-option gnc:pagename-general
 					optname-report-currency))
Index: gnucash/src/scm/report/pnl.scm
diff -u gnucash/src/scm/report/pnl.scm:1.21 gnucash/src/scm/report/pnl.scm:1.22
--- gnucash/src/scm/report/pnl.scm:1.21	Mon Apr 30 21:14:19 2001
+++ gnucash/src/scm/report/pnl.scm	Thu May 10 03:24:37 2001
@@ -57,10 +57,9 @@
        optname-from-date optname-to-date "a")
 
       ;; all about currencies
-      (gnc:options-add-currency-selection!
+      (gnc:options-add-currency!
        options gnc:pagename-general
-       optname-show-foreign optname-report-currency
-       "b")
+       optname-report-currency "b")
 
       ;; accounts to work on
       (gnc:options-add-account-selection! 
@@ -93,8 +92,14 @@
       (gnc:register-option 
        options
        (gnc:make-simple-boolean-option
+	gnc:pagename-display optname-show-foreign 
+	"e" (N_ "Display the account's foreign currency amount?") #f))
+
+      (gnc:register-option 
+       options
+       (gnc:make-simple-boolean-option
 	gnc:pagename-display optname-show-rates
-	"e" (N_ "Show the exchange rates used") #t))
+	"f" (N_ "Show the exchange rates used") #t))
 
       ;; Set the general page as default option tab
       (gnc:options-set-default-section options gnc:pagename-general)      
@@ -126,7 +131,7 @@
 					    optname-show-parent-balance))
           (show-parent-total? (get-option gnc:pagename-display
 					  optname-show-parent-total))
-	  (show-fcur? (get-option gnc:pagename-general
+	  (show-fcur? (get-option gnc:pagename-display
 				  optname-show-foreign))
 	  (report-currency (get-option gnc:pagename-general
 				       optname-report-currency))
Index: gnucash/src/scm/report/price-scatter.scm
diff -u gnucash/src/scm/report/price-scatter.scm:1.5 gnucash/src/scm/report/price-scatter.scm:1.6
--- gnucash/src/scm/report/price-scatter.scm:1.5	Wed May  9 03:52:12 2001
+++ gnucash/src/scm/report/price-scatter.scm	Wed May  9 15:46:06 2001
@@ -60,18 +60,6 @@
       (gnc:options-add-interval-choice! 
        options gnc:pagename-general optname-stepsize "b" 'MonthDelta)
 
-					;      (add-option
-					;       (gnc:make-account-list-option
-					;	gnc:pagename-accounts optname-accounts
-					;	"c"
-					;	(N_ "Report on these accounts, if chosen account level allows.")
-					;	(lambda ()
-					;	  (gnc:group-get-subaccounts (gnc:get-current-group)))
-					;	(lambda (accounts)
-					;	  (list #t
-					;		accounts))
-					;	#t))
-
       (gnc:options-add-currency! 
        options gnc:pagename-general optname-report-currency "d")
       
@@ -92,7 +80,7 @@
 		      (N_ "The weighted average all currency transactions of the past"))
 	      (vector 'actual-transactions
 		      (N_ "Actual Transactions")
-		      (N_ "The actual price of currency transactions in the past"))
+		      (N_ "The instantaneous price of actual currency transactions in the past"))
 	      ;;(vector 'pricedb-nearest
 	      ;;      (N_ "Pricedb: Nearest in time")
 	      ;;    (N_ "The price recorded nearest in time to the report date"))
@@ -143,7 +131,8 @@
                            (op-value gnc:pagename-general 
 				     optname-from-date))))
 	   (interval (op-value gnc:pagename-general optname-stepsize))
-	   ;; (accounts (op-value gnc:pagename-accounts optname-accounts))
+	   (report-title (op-value gnc:pagename-general 
+				   gnc:optname-reportname))
 
 	   (height (op-value gnc:pagename-display optname-plot-height))
 	   (width (op-value gnc:pagename-display optname-plot-width))
@@ -175,7 +164,7 @@
 		   (2.0 1.0) (2.1 1.2) (2.2 1.4) (2.3 1.6))))
       
       (gnc:html-scatter-set-title! 
-       chart (_ "Price Plot (Test)"))
+       chart report-title)
       (gnc:html-scatter-set-subtitle!
        chart (sprintf #f
                       (_ "%s to %s")