r18811 - gnucash/trunk/src - Move gnc-filepath-utils and dependencies from engine to core-utils

Geert Janssens gjanssens at code.gnucash.org
Thu Mar 4 11:32:54 EST 2010


Author: gjanssens
Date: 2010-03-04 11:32:54 -0500 (Thu, 04 Mar 2010)
New Revision: 18811
Trac: http://svn.gnucash.org/trac/changeset/18811

Added:
   gnucash/trunk/src/core-utils/binreloc.c
   gnucash/trunk/src/core-utils/binreloc.h
   gnucash/trunk/src/core-utils/gnc-filepath-utils.c
   gnucash/trunk/src/core-utils/gnc-filepath-utils.h
   gnucash/trunk/src/core-utils/gnc-path.c
   gnucash/trunk/src/core-utils/gnc-path.h
   gnucash/trunk/src/core-utils/gncla-dir.h.in
Removed:
   gnucash/trunk/src/engine/binreloc.c
   gnucash/trunk/src/engine/binreloc.h
   gnucash/trunk/src/engine/gnc-filepath-utils.c
   gnucash/trunk/src/engine/gnc-filepath-utils.h
   gnucash/trunk/src/engine/gnc-path.c
   gnucash/trunk/src/engine/gnc-path.h
   gnucash/trunk/src/engine/gncla-dir.h.in
Modified:
   gnucash/trunk/src/core-utils/Makefile.am
   gnucash/trunk/src/engine/Makefile.am
Log:
Move gnc-filepath-utils and dependencies from engine to core-utils

Modified: gnucash/trunk/src/core-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/core-utils/Makefile.am	2010-03-04 10:31:41 UTC (rev 18810)
+++ gnucash/trunk/src/core-utils/Makefile.am	2010-03-04 16:32:54 UTC (rev 18811)
@@ -1,11 +1,14 @@
 lib_LTLIBRARIES = libgnc-core-utils.la
 
 libgnc_core_utils_la_SOURCES = \
+  binreloc.c \
   gnc-main.c \
+  gnc-filepath-utils.c \
   gnc-gconf-utils.c \
   gnc-gdate-utils.c \
   gnc-gkeyfile-utils.c \
   gnc-glib-utils.c \
+  gnc-path.c \
   swig-core-utils.c
 
 libgnc_core_utils_la_LIBADD = \
@@ -14,11 +17,14 @@
   ${GCONF_LIBS}
 
 noinst_HEADERS = \
+  binreloc.h \
   gnc-main.h \
+  gnc-filepath-utils.h \
   gnc-gconf-utils.h \
   gnc-gdate-utils.h \
   gnc-gkeyfile-utils.h \
-  gnc-glib-utils.h
+  gnc-glib-utils.h \
+  gnc-path.h
 
 if BUILDING_FROM_SVN
 swig-core-utils.c: core-utils.i ${top_srcdir}/src/base-typemaps.i
@@ -30,6 +36,7 @@
   ${GUILE_INCS} \
   ${GLIB_CFLAGS} \
   ${GCONF_CFLAGS} \
+  -I${top_srcdir}/src/libqof/qof \
   -I${top_srcdir}/src
 
 
@@ -57,8 +64,20 @@
 endif
 
 noinst_DATA = .scm-links
-EXTRA_DIST = $(gncmod_DATA) core-utils.i
+EXTRA_DIST = $(gncmod_DATA) core-utils.i gncla-dir.h.in
 CLEANFILES = gnucash .scm-links
 MAINTAINERCLEANFILES = swig-core-utils.c
+BUILT_SOURCES = gncla-dir.h
 
 INCLUDES = -DG_LOG_DOMAIN=\"gnc.core-utils\"
+
+gncla-dir.h: gncla-dir.h.in ${top_builddir}/config.status Makefile
+	rm -f $@.tmp
+	sed < $< > $@.tmp \
+		-e 's#@-DATADIRNAME-@#${DATADIRNAME}#g' \
+		-e 's#@-libdir-@#${libdir}#g' \
+		-e 's#@-sysconfdir-@#${sysconfdir}#g' \
+		-e 's#@-datadir-@#${datadir}#g' \
+		-e 's#@-prefix-@#${prefix}#g'
+	mv $@.tmp $@
+

Copied: gnucash/trunk/src/core-utils/binreloc.c (from rev 18809, gnucash/trunk/src/engine/binreloc.c)
===================================================================
--- gnucash/trunk/src/core-utils/binreloc.c	                        (rev 0)
+++ gnucash/trunk/src/core-utils/binreloc.c	2010-03-04 16:32:54 UTC (rev 18811)
@@ -0,0 +1,782 @@
+/*
+ * BinReloc - a library for creating relocatable executables
+ * Written by: Hongli Lai <h.lai at chello.nl>
+ * http://autopackage.org/
+ *
+ * This source code is public domain. You can relicense this code
+ * under whatever license you want.
+ *
+ * See http://autopackage.org/docs/binreloc/ for
+ * more information and how to use this.
+ */
+
+#ifndef __BINRELOC_C__
+#define __BINRELOC_C__
+#include "config.h"
+
+#ifdef ENABLE_BINRELOC
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#ifdef MAC_INTEGRATION
+#include <igemacintegration/ige-mac-bundle.h>
+#endif
+#endif /* ENABLE_BINRELOC */
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+#include "binreloc.h"
+#include <glib.h>
+
+G_BEGIN_DECLS
+#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION
+static IgeMacBundle *bundle = NULL;
+#endif
+
+/** @internal
+ * Find the canonical filename of the executable. Returns the filename
+ * (which must be freed) or NULL on error. If the parameter 'error' is
+ * not NULL, the error code will be stored there, if an error occured.
+ */
+static char *
+_br_find_exe (GbrInitError *error)
+{
+#ifndef ENABLE_BINRELOC
+    if (error)
+        *error = GBR_INIT_ERROR_DISABLED;
+    return NULL;
+#else
+#ifdef G_OS_WIN32
+    /* I *thought* this program code already included the
+       relocation code for windows. Unfortunately this is not
+       the case and we have to add this manually. This is only
+       one possibility; other ways of looking up the full path
+       of gnucash-bin.exe probably exist.*/
+    gchar *prefix;
+    gchar *result;
+
+    /* From the glib docs: When passed NULL, this function looks
+       up installation the directory of the main executable of
+       the current process */
+    prefix = g_win32_get_package_installation_directory_of_module (NULL);
+    result = g_build_filename (prefix,
+                               "bin", "gnucash-bin.exe",
+                               (char*)NULL);
+    g_free (prefix);
+    return result;
+#elif MAC_INTEGRATION
+    gchar *prefix = NULL, *result = NULL;
+    g_type_init();
+    bundle = ige_mac_bundle_new();
+    if (!bundle)
+    {
+        *error = GBR_INIT_ERROR_MAC_NOT_BUNDLE;
+        return NULL;
+    }
+    if (!ige_mac_bundle_get_is_app_bundle (bundle))
+    {
+        g_object_unref(bundle);
+        bundle = NULL;
+        *error = GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE;
+        return NULL;
+    }
+    ige_mac_bundle_setup_environment(bundle);
+    prefix = g_strdup(ige_mac_bundle_get_path(bundle));
+    result = g_build_filename(prefix, "Contents/MacOS",
+                              "gnucash-bin", NULL);
+    g_free(prefix);
+    return result;
+#else
+    char *path, *path2, *line, *result;
+    size_t buf_size;
+    ssize_t size;
+    struct stat stat_buf;
+    FILE *f;
+
+    /* Read from /proc/self/exe (symlink) */
+    if (sizeof (path) > SSIZE_MAX)
+        buf_size = SSIZE_MAX - 1;
+    else
+        buf_size = PATH_MAX - 1;
+    path = (char *) g_try_malloc (buf_size);
+    if (path == NULL)
+    {
+        /* Cannot allocate memory. */
+        if (error)
+            *error = GBR_INIT_ERROR_NOMEM;
+        return NULL;
+    }
+    path2 = (char *) g_try_malloc (buf_size);
+    if (path2 == NULL)
+    {
+        /* Cannot allocate memory. */
+        if (error)
+            *error = GBR_INIT_ERROR_NOMEM;
+        g_free (path);
+        return NULL;
+    }
+
+    strncpy (path2, "/proc/self/exe", buf_size - 1);
+
+    while (1)
+    {
+        int i;
+
+        size = readlink (path2, path, buf_size - 1);
+        if (size == -1)
+        {
+            /* Error. */
+            g_free (path2);
+            break;
+        }
+
+        /* readlink() success. */
+        path[size] = '\0';
+
+        /* Check whether the symlink's target is also a symlink.
+         * We want to get the final target. */
+        i = stat (path, &stat_buf);
+        if (i == -1)
+        {
+            /* Error. */
+            g_free (path2);
+            break;
+        }
+
+        /* stat() success. */
+        if (!S_ISLNK (stat_buf.st_mode))
+        {
+            /* path is not a symlink. Done. */
+            g_free (path2);
+            return path;
+        }
+
+        /* path is a symlink. Continue loop and resolve this. */
+        strncpy (path, path2, buf_size - 1);
+    }
+
+
+    /* readlink() or stat() failed; this can happen when the program is
+     * running in Valgrind 2.2. Read from /proc/self/maps as fallback. */
+
+    buf_size = PATH_MAX + 128;
+    line = (char *) g_try_realloc (path, buf_size);
+    if (line == NULL)
+    {
+        /* Cannot allocate memory. */
+        g_free (path);
+        if (error)
+            *error = GBR_INIT_ERROR_NOMEM;
+        return NULL;
+    }
+
+    f = fopen ("/proc/self/maps", "r");
+    if (f == NULL)
+    {
+        g_free (line);
+        if (error)
+            *error = GBR_INIT_ERROR_OPEN_MAPS;
+        return NULL;
+    }
+
+    /* The first entry should be the executable name. */
+    result = fgets (line, (int) buf_size, f);
+    if (result == NULL)
+    {
+        fclose (f);
+        g_free (line);
+        if (error)
+            *error = GBR_INIT_ERROR_READ_MAPS;
+        return NULL;
+    }
+
+    /* Get rid of newline character. */
+    buf_size = strlen (line);
+    if (buf_size <= 0)
+    {
+        /* Huh? An empty string? */
+        fclose (f);
+        g_free (line);
+        if (error)
+            *error = GBR_INIT_ERROR_INVALID_MAPS;
+        return NULL;
+    }
+    if (line[buf_size - 1] == 10)
+        line[buf_size - 1] = 0;
+
+    /* Extract the filename; it is always an absolute path. */
+    path = strchr (line, '/');
+
+    /* Sanity check. */
+    if (strstr (line, " r-xp ") == NULL || path == NULL)
+    {
+        fclose (f);
+        g_free (line);
+        if (error)
+            *error = GBR_INIT_ERROR_INVALID_MAPS;
+        return NULL;
+    }
+
+    path = g_strdup (path);
+    g_free (line);
+    fclose (f);
+    return path;
+#endif /* G_OS_WINDOWS */
+#endif /* ENABLE_BINRELOC */
+}
+
+
+/** @internal
+ * Find the canonical filename of the executable which owns symbol.
+ * Returns a filename which must be freed, or NULL on error.
+ */
+static char *
+_br_find_exe_for_symbol (const void *symbol, GbrInitError *error)
+{
+#ifndef ENABLE_BINRELOC
+    if (error)
+        *error = GBR_INIT_ERROR_DISABLED;
+    return (char *) NULL;
+#else
+#if defined G_OS_WIN32
+    g_warning ("_br_find_exe_for_symbol not implemented on win32.");
+    if (error)
+        *error = GBR_INIT_ERROR_DISABLED;
+    return (char *) NULL;
+#else
+#define SIZE PATH_MAX + 100
+    FILE *f;
+    size_t address_string_len;
+    char *address_string, line[SIZE], *found;
+
+    if (symbol == NULL)
+        return (char *) NULL;
+
+    f = fopen ("/proc/self/maps", "r");
+    if (f == NULL)
+        return (char *) NULL;
+
+    address_string_len = 4;
+    address_string = (char *) g_try_malloc (address_string_len);
+    found = (char *) NULL;
+
+    while (!feof (f))
+    {
+        char *start_addr, *end_addr, *end_addr_end, *file;
+        void *start_addr_p, *end_addr_p;
+        size_t len;
+
+        if (fgets (line, SIZE, f) == NULL)
+            break;
+
+        /* Sanity check. */
+        if (strstr (line, " r-xp ") == NULL || strchr (line, '/') == NULL)
+            continue;
+
+        /* Parse line. */
+        start_addr = line;
+        end_addr = strchr (line, '-');
+        file = strchr (line, '/');
+
+        /* More sanity check. */
+        if (!(file > end_addr && end_addr != NULL && end_addr[0] == '-'))
+            continue;
+
+        end_addr[0] = '\0';
+        end_addr++;
+        end_addr_end = strchr (end_addr, ' ');
+        if (end_addr_end == NULL)
+            continue;
+
+        end_addr_end[0] = '\0';
+        len = strlen (file);
+        if (len == 0)
+            continue;
+        if (file[len - 1] == '\n')
+            file[len - 1] = '\0';
+
+        /* Get rid of "(deleted)" from the filename. */
+        len = strlen (file);
+        if (len > 10 && strcmp (file + len - 10, " (deleted)") == 0)
+            file[len - 10] = '\0';
+
+        /* I don't know whether this can happen but better safe than sorry. */
+        len = strlen (start_addr);
+        if (len != strlen (end_addr))
+            continue;
+
+
+        /* Transform the addresses into a string in the form of 0xdeadbeef,
+         * then transform that into a pointer. */
+        if (address_string_len < len + 3)
+        {
+            address_string_len = len + 3;
+            address_string = (char *) g_try_realloc (address_string, address_string_len);
+        }
+
+        memcpy (address_string, "0x", 2);
+        memcpy (address_string + 2, start_addr, len);
+        address_string[2 + len] = '\0';
+        sscanf (address_string, "%p", &start_addr_p);
+
+        memcpy (address_string, "0x", 2);
+        memcpy (address_string + 2, end_addr, len);
+        address_string[2 + len] = '\0';
+        sscanf (address_string, "%p", &end_addr_p);
+
+
+        if (symbol >= start_addr_p && symbol < end_addr_p)
+        {
+            found = file;
+            break;
+        }
+    }
+
+    g_free (address_string);
+    fclose (f);
+
+    if (found == NULL)
+        return (char *) NULL;
+    else
+        return g_strdup (found);
+#endif /* G_OS_WIN32 */
+#endif /* ENABLE_BINRELOC */
+}
+
+
+static gchar *exe = NULL;
+
+static void set_gerror (GError **error, GbrInitError errcode);
+
+
+/** Initialize the BinReloc library (for applications).
+ *
+ * This function must be called before using any other BinReloc functions.
+ * It attempts to locate the application's canonical filename.
+ *
+ * @note If you want to use BinReloc for a library, then you should call
+ *       gbr_init_lib() instead.
+ *
+ * @param error  If BinReloc failed to initialize, then the error report will
+ *               be stored in this variable. Set to NULL if you don't want an
+ *               error report. See the #GbrInitError for a list of error
+ *               codes.
+ *
+ * @returns TRUE on success, FALSE if BinReloc failed to initialize.
+ */
+gboolean
+gbr_init (GError **error)
+{
+    GbrInitError errcode = 0;
+
+    /* Locate the application's filename. */
+    exe = _br_find_exe (&errcode);
+    if (exe != NULL)
+        /* Success! */
+        return TRUE;
+    else
+    {
+        /* Failed :-( */
+        set_gerror (error, errcode);
+        return FALSE;
+    }
+}
+
+
+/** Initialize the BinReloc library (for libraries).
+ *
+ * This function must be called before using any other BinReloc functions.
+ * It attempts to locate the calling library's canonical filename.
+ *
+ * @note The BinReloc source code MUST be included in your library, or this
+ *       function won't work correctly.
+ *
+ * @returns TRUE on success, FALSE if a filename cannot be found.
+ */
+gboolean
+gbr_init_lib (GError **error)
+{
+    GbrInitError errcode = 0;
+
+    exe = _br_find_exe_for_symbol ((const void *) "", &errcode);
+    if (exe != NULL)
+        /* Success! */
+        return TRUE;
+    else
+    {
+        /* Failed :-( */
+        set_gerror (error, errcode);
+        return exe != NULL;
+    }
+}
+
+
+static void
+set_gerror (GError **error, GbrInitError errcode)
+{
+    gchar *error_message;
+
+    if (error == NULL)
+        return;
+
+    switch (errcode)
+    {
+    case GBR_INIT_ERROR_NOMEM:
+        error_message = "Cannot allocate memory.";
+        break;
+    case GBR_INIT_ERROR_OPEN_MAPS:
+        error_message = "Unable to open /proc/self/maps for reading.";
+        break;
+    case GBR_INIT_ERROR_READ_MAPS:
+        error_message = "Unable to read from /proc/self/maps.";
+        break;
+    case GBR_INIT_ERROR_INVALID_MAPS:
+        error_message = "The file format of /proc/self/maps is invalid.";
+        break;
+    case GBR_INIT_ERROR_MAC_NOT_BUNDLE:
+        error_message = "Binreloc did not find a bundle";
+        break;
+    case GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE:
+        error_message = "Binreloc found that the bundle is not an app bundle";
+        break;
+    case GBR_INIT_ERROR_DISABLED:
+        error_message = "Binary relocation support is disabled.";
+        break;
+    default:
+        error_message = "Unknown error.";
+        break;
+    };
+    g_set_error (error, g_quark_from_static_string ("GBinReloc"),
+                 errcode, "%s", error_message);
+}
+
+
+/** Find the canonical filename of the current application.
+ *
+ * @param default_exe  A default filename which will be used as fallback.
+ * @returns A string containing the application's canonical filename,
+ *          which must be freed when no longer necessary. If BinReloc is
+ *          not initialized, or if the initialization function failed,
+ *          then a copy of default_exe will be returned. If default_exe
+ *          is NULL, then NULL will be returned.
+ */
+gchar *
+gbr_find_exe (const gchar *default_exe)
+{
+    if (exe == NULL)
+    {
+        /* BinReloc is not initialized. */
+        if (default_exe != NULL)
+            return g_strdup (default_exe);
+        else
+            return NULL;
+    }
+    return g_strdup (exe);
+}
+
+
+/** Locate the directory in which the current application is installed.
+ *
+ * The prefix is generated by the following pseudo-code evaluation:
+ * \code
+ * dirname(exename)
+ * \endcode
+ *
+ * @param default_dir  A default directory which will used as fallback.
+ * @return A string containing the directory, which must be freed when no
+ *         longer necessary. If BinReloc is not initialized, or if the
+ *         initialization function failed, then a copy of default_dir
+ *         will be returned. If default_dir is NULL, then NULL will be
+ *         returned.
+ */
+gchar *
+gbr_find_exe_dir (const gchar *default_dir)
+{
+    if (exe == NULL)
+    {
+        /* BinReloc not initialized. */
+        if (default_dir != NULL)
+            return g_strdup (default_dir);
+        else
+            return NULL;
+    }
+
+    return g_path_get_dirname (exe);
+}
+
+
+/** Locate the prefix in which the current application is installed.
+ *
+ * The prefix is generated by the following pseudo-code evaluation:
+ * \code
+ * dirname(dirname(exename))
+ * \endcode
+ *
+ * @param default_prefix  A default prefix which will used as fallback.
+ * @return A string containing the prefix, which must be freed when no
+ *         longer necessary. If BinReloc is not initialized, or if the
+ *         initialization function failed, then a copy of default_prefix
+ *         will be returned. If default_prefix is NULL, then NULL will be
+ *         returned.
+ */
+gchar *
+gbr_find_prefix (const gchar *default_prefix)
+{
+    gchar *dir1, *dir2;
+
+#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION
+    gchar *prefix = NULL, *result = NULL;
+    if (bundle == NULL)
+    {
+        /* BinReloc not initialized. */
+        if (default_prefix != NULL)
+            return g_strdup (default_prefix);
+        else
+            return NULL;
+    }
+    prefix = g_strdup(ige_mac_bundle_get_path(bundle));
+    result = g_build_filename(prefix, "Contents/Resources", NULL);
+    g_free(prefix);
+    return result;
+#else
+
+    if (exe == NULL)
+    {
+        /* BinReloc not initialized. */
+        if (default_prefix != NULL)
+            return g_strdup (default_prefix);
+        else
+            return NULL;
+    }
+    dir1 = g_path_get_dirname (exe);
+    dir2 = g_path_get_dirname (dir1);
+    g_free (dir1);
+    return dir2;
+#endif //ENABLE_BINRELOC && MAC_INTEGRATION
+}
+
+
+/** Locate the application's binary folder.
+ *
+ * The path is generated by the following pseudo-code evaluation:
+ * \code
+ * prefix + "/bin"
+ * \endcode
+ *
+ * @param default_bin_dir  A default path which will used as fallback.
+ * @return A string containing the bin folder's path, which must be freed when
+ *         no longer necessary. If BinReloc is not initialized, or if the
+ *         initialization function failed, then a copy of default_bin_dir will
+ *         be returned. If default_bin_dir is NULL, then NULL will be returned.
+ */
+gchar *
+gbr_find_bin_dir (const gchar *default_bin_dir)
+{
+    gchar *prefix, *dir;
+#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION
+    if (bundle == NULL)
+    {
+        /* BinReloc not initialized. */
+        if (default_bin_dir != NULL)
+            return g_strdup (default_bin_dir);
+        else
+            return NULL;
+    }
+    prefix = g_strdup(ige_mac_bundle_get_path(bundle));
+    dir = g_build_filename(prefix, "Contents/MacOS", NULL);
+    g_free(prefix);
+    return dir;
+#else
+
+    prefix = gbr_find_prefix (NULL);
+    if (prefix == NULL)
+    {
+        /* BinReloc not initialized. */
+        if (default_bin_dir != NULL)
+            return g_strdup (default_bin_dir);
+        else
+            return NULL;
+    }
+
+    dir = g_build_filename (prefix, "bin", NULL);
+    g_free (prefix);
+    return dir;
+#endif //ENABLE_BINRELOC && MAC_INTEGRATION
+}
+
+
+/** Locate the application's superuser binary folder.
+ *
+ * The path is generated by the following pseudo-code evaluation:
+ * \code
+ * prefix + "/sbin"
+ * \endcode
+ *
+ * @param default_sbin_dir  A default path which will used as fallback.
+ * @return A string containing the sbin folder's path, which must be freed when
+ *         no longer necessary. If BinReloc is not initialized, or if the
+ *         initialization function failed, then a copy of default_sbin_dir will
+ *         be returned. If default_bin_dir is NULL, then NULL will be returned.
+ */
+gchar *
+gbr_find_sbin_dir (const gchar *default_sbin_dir)
+{
+    gchar *prefix, *dir;
+
+    prefix = gbr_find_prefix (NULL);
+    if (prefix == NULL)
+    {
+        /* BinReloc not initialized. */
+        if (default_sbin_dir != NULL)
+            return g_strdup (default_sbin_dir);
+        else
+            return NULL;
+    }
+
+    dir = g_build_filename (prefix, "sbin", NULL);
+    g_free (prefix);
+    return dir;
+}
+
+
+/** Locate the application's data folder.
+ *
+ * The path is generated by the following pseudo-code evaluation:
+ * \code
+ * prefix + "/share"
+ * \endcode
+ *
+ * @param default_data_dir  A default path which will used as fallback.
+ * @return A string containing the data folder's path, which must be freed when
+ *         no longer necessary. If BinReloc is not initialized, or if the
+ *         initialization function failed, then a copy of default_data_dir
+ *         will be returned. If default_data_dir is NULL, then NULL will be
+ *         returned.
+ */
+gchar *
+gbr_find_data_dir (const gchar *default_data_dir)
+{
+    gchar *prefix, *dir;
+
+    prefix = gbr_find_prefix (NULL);
+    if (prefix == NULL)
+    {
+        /* BinReloc not initialized. */
+        if (default_data_dir != NULL)
+            return g_strdup (default_data_dir);
+        else
+            return NULL;
+    }
+
+    dir = g_build_filename (prefix, "share", NULL);
+    g_free (prefix);
+    return dir;
+}
+
+
+/** Locate the application's library folder.
+ *
+ * The path is generated by the following pseudo-code evaluation:
+ * \code
+ * prefix + "/lib"
+ * \endcode
+ *
+ * @param default_lib_dir  A default path which will used as fallback.
+ * @return A string containing the library folder's path, which must be freed when
+ *         no longer necessary. If BinReloc is not initialized, or if the
+ *         initialization function failed, then a copy of default_lib_dir will be returned.
+ *         If default_lib_dir is NULL, then NULL will be returned.
+ */
+gchar *
+gbr_find_lib_dir (const gchar *default_lib_dir)
+{
+    gchar *prefix, *dir;
+
+    prefix = gbr_find_prefix (NULL);
+    if (prefix == NULL)
+    {
+        /* BinReloc not initialized. */
+        if (default_lib_dir != NULL)
+            return g_strdup (default_lib_dir);
+        else
+            return NULL;
+    }
+
+    dir = g_build_filename (prefix, "lib", NULL);
+    g_free (prefix);
+    return dir;
+}
+
+
+/** Locate the application's libexec folder.
+ *
+ * The path is generated by the following pseudo-code evaluation:
+ * \code
+ * prefix + "/libexec"
+ * \endcode
+ *
+ * @param default_libexec_dir  A default path which will used as fallback.
+ * @return A string containing the libexec folder's path, which must be freed when
+ *         no longer necessary. If BinReloc is not initialized, or if the initialization
+ *         function failed, then a copy of default_libexec_dir will be returned.
+ *         If default_libexec_dir is NULL, then NULL will be returned.
+ */
+gchar *
+gbr_find_libexec_dir (const gchar *default_libexec_dir)
+{
+    gchar *prefix, *dir;
+
+    prefix = gbr_find_prefix (NULL);
+    if (prefix == NULL)
+    {
+        /* BinReloc not initialized. */
+        if (default_libexec_dir != NULL)
+            return g_strdup (default_libexec_dir);
+        else
+            return NULL;
+    }
+
+    dir = g_build_filename (prefix, "libexec", NULL);
+    g_free (prefix);
+    return dir;
+}
+
+
+/** Locate the application's configuration files folder.
+ *
+ * The path is generated by the following pseudo-code evaluation:
+ * \code
+ * prefix + "/etc"
+ * \endcode
+ *
+ * @param default_etc_dir  A default path which will used as fallback.
+ * @return A string containing the etc folder's path, which must be freed when
+ *         no longer necessary. If BinReloc is not initialized, or if the initialization
+ *         function failed, then a copy of default_etc_dir will be returned.
+ *         If default_etc_dir is NULL, then NULL will be returned.
+ */
+gchar *
+gbr_find_etc_dir (const gchar *default_etc_dir)
+{
+    gchar *prefix, *dir;
+
+    prefix = gbr_find_prefix (NULL);
+    if (prefix == NULL)
+    {
+        /* BinReloc not initialized. */
+        if (default_etc_dir != NULL)
+            return g_strdup (default_etc_dir);
+        else
+            return NULL;
+    }
+
+    dir = g_build_filename (prefix, "etc", NULL);
+    g_free (prefix);
+    return dir;
+}
+
+
+G_END_DECLS
+
+#endif /* __BINRELOC_C__ */

Copied: gnucash/trunk/src/core-utils/binreloc.h (from rev 18809, gnucash/trunk/src/engine/binreloc.h)
===================================================================
--- gnucash/trunk/src/core-utils/binreloc.h	                        (rev 0)
+++ gnucash/trunk/src/core-utils/binreloc.h	2010-03-04 16:32:54 UTC (rev 18811)
@@ -0,0 +1,71 @@
+/*
+ * BinReloc - a library for creating relocatable executables
+ * Written by: Hongli Lai <h.lai at chello.nl>
+ * http://autopackage.org/
+ *
+ * This source code is public domain. You can relicense this code
+ * under whatever license you want.
+ *
+ * See http://autopackage.org/docs/binreloc/ for
+ * more information and how to use this.
+ */
+
+#ifndef __BINRELOC_H__
+#define __BINRELOC_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+
+/** These error codes can be returned by br_init(), br_init_lib(), gbr_init() or gbr_init_lib(). */
+typedef enum
+{
+    /** Cannot allocate memory. */
+    GBR_INIT_ERROR_NOMEM,
+    /** Unable to open /proc/self/maps; see errno for details. */
+    GBR_INIT_ERROR_OPEN_MAPS,
+    /** Unable to read from /proc/self/maps; see errno for details. */
+    GBR_INIT_ERROR_READ_MAPS,
+    /** The file format of /proc/self/maps is invalid; kernel bug? */
+    GBR_INIT_ERROR_INVALID_MAPS,
+    /** BinReloc determined that gnucash is not running from a bundle */
+    GBR_INIT_ERROR_MAC_NOT_BUNDLE,
+    /** Binreloc determined that the bundle is not an app bundle */
+    GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE,
+    /** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */
+    GBR_INIT_ERROR_DISABLED
+} GbrInitError;
+
+
+#ifndef BINRELOC_RUNNING_DOXYGEN
+/* Mangle symbol names to avoid symbol collisions with other ELF objects. */
+#define gbr_find_exe         ffEt66859784967989_gbr_find_exe
+#define gbr_find_exe_dir     ffEt66859784967989_gbr_find_exe_dir
+#define gbr_find_prefix      ffEt66859784967989_gbr_find_prefix
+#define gbr_find_bin_dir     ffEt66859784967989_gbr_find_bin_dir
+#define gbr_find_sbin_dir    ffEt66859784967989_gbr_find_sbin_dir
+#define gbr_find_data_dir    ffEt66859784967989_gbr_find_data_dir
+#define gbr_find_lib_dir     ffEt66859784967989_gbr_find_lib_dir
+#define gbr_find_libexec_dir ffEt66859784967989_gbr_find_libexec_dir
+#define gbr_find_etc_dir     ffEt66859784967989_gbr_find_etc_dir
+
+
+#endif
+gboolean gbr_init             (GError **error);
+gboolean gbr_init_lib         (GError **error);
+
+gchar   *gbr_find_exe         (const gchar *default_exe);
+gchar   *gbr_find_exe_dir     (const gchar *default_dir);
+gchar   *gbr_find_prefix      (const gchar *default_prefix);
+gchar   *gbr_find_bin_dir     (const gchar *default_bin_dir);
+gchar   *gbr_find_sbin_dir    (const gchar *default_sbin_dir);
+gchar   *gbr_find_data_dir    (const gchar *default_data_dir);
+gchar   *gbr_find_lib_dir     (const gchar *default_lib_dir);
+gchar   *gbr_find_libexec_dir (const gchar *default_libexec_dir);
+gchar   *gbr_find_etc_dir     (const gchar *default_etc_dir);
+
+
+G_END_DECLS
+
+#endif /* __BINRELOC_H__ */

Copied: gnucash/trunk/src/core-utils/gnc-filepath-utils.c (from rev 18810, gnucash/trunk/src/engine/gnc-filepath-utils.c)
===================================================================
--- gnucash/trunk/src/core-utils/gnc-filepath-utils.c	                        (rev 0)
+++ gnucash/trunk/src/core-utils/gnc-filepath-utils.c	2010-03-04 16:32:54 UTC (rev 18811)
@@ -0,0 +1,469 @@
+/********************************************************************\
+ * gnc-filepath-utils.c -- file path resolutin utilitie             *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+/*
+ * @file gnc-filepath-utils.c
+ * @brief file path resolution utilities
+ * @author Copyright (c) 1998-2004 Linas Vepstas <linas at linas.org>
+ * @author Copyright (c) 2000 Dave Peticolas
+ *
+ * XXX this file does not belong in the gnucash engine; it is here
+ * for the moment only because both the file backend and the app-file
+ * GUI code make use of it.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib/gprintf.h>
+#include <glib/gstdio.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#include <errno.h>
+
+#include "qof.h"
+#include "gnc-path.h"
+#include "gnc-filepath-utils.h"
+
+#ifdef _MSC_VER
+#include <glib/gwin32.h>
+#define PATH_MAX MAXPATHLEN
+#endif
+
+/**
+ * Scrubs a filename by changing "strange" chars (e.g. those that are not
+ * valid in a win32 file name) to "_".
+ *
+ * @param filename File name - updated in place
+ */
+static void
+scrub_filename(char* filename)
+{
+    char* p;
+
+#define STRANGE_CHARS "/:"
+    p = strpbrk(filename, STRANGE_CHARS);
+    while (p)
+    {
+        *p = '_';
+        p = strpbrk(filename, STRANGE_CHARS);
+    }
+}
+
+/** Check if the path exists and is a regular file.
+ *
+ * \param path -- freed if the path doesn't exist or isn't a regular file
+ *
+ *  \return NULL or the path
+ */
+static gchar *
+check_path_return_if_valid(gchar *path)
+{
+    if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
+        return path;
+    g_free (path);
+    return NULL;
+}
+
+/** @fn char * xaccResolveFilePath (const char * filefrag)
+ *
+ *  @brief Create an absolute path when given a relative path;
+ *  otherwise return the argument.
+ *
+ * If passed a string which g_path_is_absolute declares an absolute
+ * path, return the argument. If the string begins with file:,
+ * file://, xml:, or xml://, remove that and return the rest.
+ *
+ * Otherwise, assume that filefrag is a well-formed relative path and
+ * try to find a file with its path relative to the current working
+ * directory, the installed system-wide data directory (e.g.,
+ * /usr/local/share/gnucash), the installed system configuration
+ * directory (e.g., /usr/local/etc/gnucash), or in the user's
+ * configuration directory (e.g., $HOME/.gnucash/data) in that
+ * order. If a matching file is found, return the absolute path to
+ * it. If one isn't found, return a absolute path relative to the
+ * user's configuration directory and note in the trace file that it
+ * needs to be created.
+ *
+ * @param filefrag
+ *
+ * @return An absolute file path.
+ */
+char *
+xaccResolveFilePath (const char * filefrag)
+{
+    int namelen;
+    gchar *fullpath = NULL, *tmp_path = NULL;
+
+    /* seriously invalid */
+    if (!filefrag)
+    {
+        g_critical("filefrag is NULL");
+        return NULL;
+    }
+
+    /* ---------------------------------------------------- */
+    /* OK, now we try to find or build an absolute file path */
+
+    /* check for an absolute file path */
+    if (g_path_is_absolute(filefrag))
+        return g_strdup (filefrag);
+
+    if (!g_ascii_strncasecmp(filefrag, "file:", 5))
+    {
+        if (!g_ascii_strncasecmp(filefrag, "file://", 7))
+            return g_strdup(filefrag + 7);
+        else
+            return g_strdup(filefrag + 5);
+    }
+    if ( g_ascii_strncasecmp( filefrag, "xml:", 4 ) == 0 )
+    {
+        if ( g_ascii_strncasecmp( filefrag, "xml://", 6 ) == 0 )
+            return g_strdup( filefrag + 6);
+        else
+            return g_strdup( filefrag + 4);
+    }
+
+
+    /* get conservative on the length so that sprintf(getpid()) works ... */
+    /* strlen ("/.LCK") + sprintf (%x%d) */
+    namelen = strlen (filefrag) + 25;
+
+    /* Look in the current working directory */
+    tmp_path = g_get_current_dir();
+    fullpath = g_build_filename(tmp_path, filefrag, (gchar *)NULL);
+    g_free(tmp_path);
+    fullpath = check_path_return_if_valid(fullpath);
+    if (fullpath != NULL)
+        return fullpath;
+
+    /* Look in the data dir (e.g. $PREFIX/share/gnucash) */
+    tmp_path = gnc_path_get_pkgdatadir();
+    fullpath = g_build_filename(tmp_path, filefrag, (gchar *)NULL);
+    g_free(tmp_path);
+    fullpath = check_path_return_if_valid(fullpath);
+    if (fullpath != NULL)
+        return fullpath;
+
+    /* Look in the config dir (e.g. $PREFIX/etc/gnucash) */
+    tmp_path = gnc_path_get_accountsdir();
+    fullpath = g_build_filename(tmp_path, filefrag, (gchar *)NULL);
+    g_free(tmp_path);
+    fullpath = check_path_return_if_valid(fullpath);
+    if (fullpath != NULL)
+        return fullpath;
+
+    /* Look in the users config dir (e.g. $HOME/.gnucash/data) */
+    fullpath = gnc_build_data_path(filefrag);
+    if (g_file_test(fullpath, G_FILE_TEST_IS_REGULAR))
+        return fullpath;
+    /* OK, it's not there. Note that it needs to be created and pass it
+     * back anyway */
+    g_warning("create new file %s", fullpath);
+    return fullpath;
+
+}
+
+/* ====================================================================== */
+
+/** @fn char * xaccResolveURL (const char * pathfrag)
+ *
+ *  @brief Return the passed-in string unless it starts with file:,
+ *  xml:, or is a raw relative path.
+ *
+ * Strings starting with http://, https://, or a "registered scheme"
+ * (see qof_backend_get_registered_access_method_list()) are returned
+ * as-is by this function.
+ *
+ * Strings which form an absolute path (as determined by
+ * g_path_is_absolute()) are passed to xaccResolveFilePath() and
+ * immediately returned as-is.
+ *
+ * Strings which begin with file: or xml: are passed to
+ * xaccResolveFilePath, which strips off the "scheme" part (file: or
+ * xml: plus // if present) and returns the rest unchanged. This
+ * result is passed back to the caller as-is if the original astring
+ * started with file:; if it started with xml:, then xml: is prepended
+ * before passing it back to the caller. Note that this has the effect
+ * of converting a URI of the form xml:///path/to/file into one of the
+ * form xml:/path/to/file.
+ *
+ * Strings which meet none of the above are passed to
+ * xaccResolveFilePath and the result returned to the caller.
+ *
+ * @param pathfrag the string to "resolve"
+ *
+ *  @return "resolved" string.
+ */
+char *
+xaccResolveURL (const char * pathfrag)
+{
+    GList* list;
+    GList* node;
+
+    /* seriously invalid */
+    if (!pathfrag) return NULL;
+
+    /* At this stage of checking, URL's are always, by definition,
+     * resolved.  If there's an error connecting, we'll find out later.
+     */
+
+    if (!g_ascii_strncasecmp (pathfrag, "http://", 7) ||
+            !g_ascii_strncasecmp (pathfrag, "https://", 8))
+    {
+        return g_strdup(pathfrag);
+    }
+
+    /* Check the URL against the list of registered access methods */
+    list = qof_backend_get_registered_access_method_list();
+    for ( node = list; node != NULL; node = node->next )
+    {
+        const gchar* access_method = node->data;
+        if ( strcmp( access_method, "file" ) != 0 &&
+                strcmp( access_method, "xml" ) != 0 )
+        {
+            gchar s[30];
+            sprintf( s, "%s://", access_method );
+            if ( !g_ascii_strncasecmp( pathfrag, s, strlen(s) ) )
+            {
+                g_list_free(list);
+                return g_strdup(pathfrag);
+            }
+        }
+    }
+    g_list_free(list);
+    /*
+     * xml: schemes are a special case, becuase gnc_file_do_save_as()
+     * relies on the phony scheme id being present in the returned path
+     * to distinguish the backend used to save the file. Note that this
+     * has the amusing effect of stripping the // from the phony scheme,
+     * so if it started out as xml:///path/to/data, it gets returned
+     * from here as xml:/path/to/data.
+     */
+    if (!g_ascii_strncasecmp (pathfrag, "xml:", 4))
+    {
+        return (g_strdup_printf( "xml:%s", xaccResolveFilePath (pathfrag)) );
+    }
+    return (xaccResolveFilePath (pathfrag));
+}
+
+/* ====================================================================== */
+
+/** @fn void gnc_validate_directory (const gchar *dirname)
+ *  @brief Check that the supplied directory path exists, is a directory, and that the user has adequate permissions to use it.
+ *
+ * @param dirname The path to check
+ */
+static void
+gnc_validate_directory (const gchar *dirname)
+{
+    struct stat statbuf;
+    gint rc;
+
+    rc = g_stat (dirname, &statbuf);
+    if (rc)
+    {
+        switch (errno)
+        {
+        case ENOENT:
+            rc = g_mkdir (dirname,
+#ifdef G_OS_WIN32
+                          0          /* The mode argument is ignored on windows */
+#else
+                          S_IRWXU    /* perms = S_IRWXU = 0700 */
+#endif
+                         );
+            if (rc)
+            {
+                g_fprintf(stderr,
+                          _("An error occurred while creating the directory:\n"
+                            "  %s\n"
+                            "Please correct the problem and restart GnuCash.\n"
+                            "The reported error was '%s' (errno %d).\n"),
+                          dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
+                exit(1);
+            }
+            g_stat (dirname, &statbuf);
+            break;
+
+        case EACCES:
+            g_fprintf(stderr,
+                      _("The directory\n"
+                        "  %s\n"
+                        "exists but cannot be accessed.  This program \n"
+                        "must have full access (read/write/execute) to \n"
+                        "the directory in order to function properly.\n"),
+                      dirname);
+            exit(1);
+
+        case ENOTDIR:
+            g_fprintf(stderr,
+                      _("The path\n"
+                        "  %s\n"
+                        "exists but it is not a directory. Please delete\n"
+                        "the file and start GnuCash again.\n"),
+                      dirname);
+            exit(1);
+
+        default:
+            g_fprintf(stderr,
+                      _("An unknown error occurred when validating that the\n"
+                        "  %s\n"
+                        "directory exists and is usable. Please correct the\n"
+                        "problem and restart GnuCash.  The reported error \n"
+                        "was '%s' (errno %d)."),
+                      dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
+            exit(1);
+        }
+    }
+
+    if ((statbuf.st_mode & S_IFDIR) != S_IFDIR)
+    {
+        g_fprintf(stderr,
+                  _("The path\n"
+                    "  %s\n"
+                    "exists but it is not a directory. Please delete\n"
+                    "the file and start GnuCash again.\n"),
+                  dirname);
+        exit(1);
+    }
+#ifndef G_OS_WIN32
+    /* The mode argument is ignored on windows anyway */
+    if ((statbuf.st_mode & S_IRWXU) != S_IRWXU)
+    {
+        g_fprintf(stderr,
+                  _("The permissions are wrong on the directory\n"
+                    "  %s\n"
+                    "They must be at least 'rwx' for the user.\n"),
+                  dirname);
+        exit(1);
+    }
+#endif
+}
+
+/** @fn const gchar * gnc_dotgnucash_dir ()
+ *  @brief Ensure that the user's configuration directory exists and is minimally populated.
+ *
+ *  Note that the default path is $HOME/.gnucash; This can be changed
+ *  by the environment variable $GNC_DOT_DIR.
+ *
+ *  @return An absolute path to the configuration directory
+ */
+const gchar *
+gnc_dotgnucash_dir (void)
+{
+    static gchar *dotgnucash = NULL;
+    gchar *tmp_dir;
+
+    if (dotgnucash)
+        return dotgnucash;
+
+    dotgnucash = g_strdup(g_getenv("GNC_DOT_DIR"));
+
+    if (!dotgnucash)
+    {
+        const gchar *home = g_get_home_dir();
+        if (!home)
+        {
+            g_warning("Cannot find home directory. Using tmp directory instead.");
+            home = g_get_tmp_dir();
+        }
+        g_assert(home);
+
+        dotgnucash = g_build_filename(home, ".gnucash", (gchar *)NULL);
+    }
+    gnc_validate_directory(dotgnucash);
+
+    /* Since we're in code that is only executed once.... */
+    tmp_dir = g_build_filename(dotgnucash, "books", (gchar *)NULL);
+    gnc_validate_directory(tmp_dir);
+    g_free(tmp_dir);
+    tmp_dir = g_build_filename(dotgnucash, "checks", (gchar *)NULL);
+    gnc_validate_directory(tmp_dir);
+    g_free(tmp_dir);
+
+    return dotgnucash;
+}
+
+/** @fn gchar * gnc_build_dotgnucash_path (const gchar *filename)
+ *  @brief Make a path to filename in the user's configuration directory.
+ *
+ * @param filename The name of the file
+ *
+ *  @return An absolute path.
+ */
+
+gchar *
+gnc_build_dotgnucash_path (const gchar *filename)
+{
+    return g_build_filename(gnc_dotgnucash_dir(), filename, (gchar *)NULL);
+}
+
+/** @fn gchar * gnc_build_book_path (const gchar *filename)
+ *  @brief Make a path to filename in the book subdirectory of the user's configuration directory.
+ *
+ * @param filename The name of the file
+ *
+ *  @return An absolute path.
+ */
+
+gchar *
+gnc_build_book_path (const gchar *filename)
+{
+    gchar* filename_dup = g_strdup(filename);
+    gchar* result = NULL;
+
+    scrub_filename(filename_dup);
+    result = g_build_filename(gnc_dotgnucash_dir(), "books",
+                              filename_dup, (gchar *)NULL);
+    g_free(filename_dup);
+    return result;
+}
+
+/** @fn gchar * gnc_build_data_path (const gchar *filename)
+ *  @brief Make a path to filename in the data subdirectory of the user's configuration directory.
+ *
+ * @param filename The name of the file
+ *
+ *  @return An absolute path.
+ */
+
+gchar *
+gnc_build_data_path (const gchar *filename)
+{
+    gchar* filename_dup = g_strdup(filename);
+    gchar* result;
+
+    scrub_filename(filename_dup);
+    result = g_build_filename(gnc_dotgnucash_dir(), "data", filename_dup, (gchar *)NULL);
+    g_free(filename_dup);
+    return result;
+}
+
+/* =============================== END OF FILE ========================== */

Copied: gnucash/trunk/src/core-utils/gnc-filepath-utils.h (from rev 18809, gnucash/trunk/src/engine/gnc-filepath-utils.h)
===================================================================
--- gnucash/trunk/src/core-utils/gnc-filepath-utils.h	                        (rev 0)
+++ gnucash/trunk/src/core-utils/gnc-filepath-utils.h	2010-03-04 16:32:54 UTC (rev 18811)
@@ -0,0 +1,50 @@
+/********************************************************************\
+ * gnc-filepath-utils.h -- file path resolutin utilitie             *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+/**
+ * @file gnc-filepath-utils.h
+ * @brief File path resolution utility functions
+ * @author Copyright (c) 1998-2004 Linas Vepstas <linas at linas.org>
+ * @author Copyright (c) 2000 Dave Peticolas
+ */
+
+#ifndef GNC_FILEPATH_UTILS_H
+#define GNC_FILEPATH_UTILS_H
+
+/** The xaccResolveFilePath() routine is a utility that will accept
+ *    a fragmentary filename as input, and resolve it into a fully
+ *    qualified path in the file system, i.e. a path that begins with
+ *    a leading slash.  First, the current working directory is
+ *    searched for the file.  Next, the directory $HOME/.gnucash/data,
+ *    and finally, a list of other (configurable) paths.  If the file
+ *    is not found, then the path $HOME/.gnucash/data is used.  If
+ *    $HOME is not defined, then the current working directory is
+ *    used.
+ */
+char * xaccResolveFilePath (const char * filefrag);
+char * xaccResolveURL (const char * pathfrag);
+
+const gchar *gnc_dotgnucash_dir (void);
+gchar *gnc_build_dotgnucash_path (const gchar *filename);
+gchar *gnc_build_book_path (const gchar *filename);
+gchar *gnc_build_data_path (const gchar *filename);
+
+#endif /* GNC_FILEPATH_UTILS_H */

Copied: gnucash/trunk/src/core-utils/gnc-path.c (from rev 18809, gnucash/trunk/src/engine/gnc-path.c)
===================================================================
--- gnucash/trunk/src/core-utils/gnc-path.c	                        (rev 0)
+++ gnucash/trunk/src/core-utils/gnc-path.c	2010-03-04 16:32:54 UTC (rev 18811)
@@ -0,0 +1,149 @@
+/********************************************************************\
+ * gnc-path.c -- Path lookup of gnucash installation locations      *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+#include "config.h"
+#include "gnc-path.h"
+#include "gncla-dir.h"
+#include <stdio.h>
+#include "binreloc.h"
+
+gchar *gnc_path_get_prefix()
+{
+    //printf("Returning prefix %s\n", gbr_find_prefix (PREFIX));
+    return gbr_find_prefix (PREFIX);
+}
+
+/** Returns the libdir path, usually
+ * "$prefix/lib". Needed for gnome_program_init().
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_libdir()
+{
+    //printf("Returning libdir %s\n", gbr_find_lib_dir (LIBDIR));
+    return gbr_find_lib_dir (LIBDIR);
+}
+
+/** Returns the datadir path, usually
+ * "$prefix/share/gnucash". Needed for gnome_program_init().
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_pkgdatadir()
+{
+    gchar *datadir = gbr_find_data_dir (DATADIR);
+    gchar *result = g_build_filename (datadir, "gnucash", (char*)NULL);
+    g_free (datadir);
+    //printf("Returning pkgdatadir %s\n", result);
+    return result;
+}
+
+/** Returns the sysconfdir path, usually
+ * "$prefix/etc/gnucash". Needed for gnome_program_init().
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_pkgsysconfdir()
+{
+    gchar *sysconfdir = gbr_find_etc_dir (SYSCONFDIR);
+    gchar *result = g_build_filename (sysconfdir, "gnucash", (char*)NULL);
+    g_free (sysconfdir);
+    //printf("Returning pkgsysconfdir %s\n", result);
+    return result;
+}
+
+
+/** Returns the pkglibdir path, usually
+ * "$prefix/lib/gnucash".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_pkglibdir()
+{
+    gchar *libdir = gnc_path_get_libdir ();
+    gchar *result = g_build_filename (libdir, "gnucash", (char*)NULL);
+    g_free (libdir);
+    //printf("Returning pkglibdir %s\n", result);
+    return result;
+}
+
+/** Returns the glade file path, usually
+ * "$prefix/share/gnucash/glade".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_gladedir()
+{
+    gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
+    gchar *result = g_build_filename (pkgdatadir, "glade", (char*)NULL);
+    g_free (pkgdatadir);
+    //printf("Returning gladedir %s\n", result);
+    return result;
+}
+
+/** Returns the localedir path, usually
+ * "$prefix/share/locale".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_localedir()
+{
+    gchar *prefix = gnc_path_get_prefix();
+    gchar *result = g_build_filename (prefix, LOCALE_DATADIRNAME, "locale", (char*)NULL);
+    g_free (prefix);
+    //printf("Returning localedir %s\n", result);
+    return result;
+}
+
+/** Returns the glade file path, usually
+ * "$prefix/share/gnucash/accounts".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_accountsdir()
+{
+    gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
+    gchar *result = g_build_filename (pkgdatadir, "accounts", (char*)NULL);
+    g_free (pkgdatadir);
+    //printf("Returning accountsdir %s\n", result);
+    return result;
+}
+
+/** Returns the gconf schema config source path, usually
+ * "$prefix/etc/gconf/gconf.xml.defaults".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_gconfdir(gboolean force_slashes)
+{
+    gchar *sysconfdir = gbr_find_etc_dir (SYSCONFDIR);
+    gchar *separator = G_DIR_SEPARATOR_S;
+    gchar *result;
+
+    if (force_slashes)
+    {
+        gchar **splitted;
+        splitted = g_strsplit (sysconfdir, "\\", -1);
+        g_free (sysconfdir);
+        sysconfdir = g_strjoinv ("/", splitted);
+        g_strfreev (splitted);
+        separator = "/";
+    }
+
+    result = g_build_path (separator, sysconfdir, "gconf", "gconf.xml.defaults",
+                           (gchar*)NULL);
+    g_free (sysconfdir);
+    //printf("Returning gconfdir %s\n", result);
+    return result;
+}
+

Copied: gnucash/trunk/src/core-utils/gnc-path.h (from rev 18809, gnucash/trunk/src/engine/gnc-path.h)
===================================================================
--- gnucash/trunk/src/core-utils/gnc-path.h	                        (rev 0)
+++ gnucash/trunk/src/core-utils/gnc-path.h	2010-03-04 16:32:54 UTC (rev 18811)
@@ -0,0 +1,88 @@
+/********************************************************************\
+ * gnc-path.h -- Path lookup of gnucash installation locations      *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+
+#ifndef GNC_PATH_H
+#define GNC_PATH_H
+
+#include <glib.h>
+
+/** Returns the installation prefix path, usually
+ * "$prefix". Needed for gnome_program_init().
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_prefix(void);
+
+/** Returns the libdir path, usually
+ * "$prefix/lib". Needed for gnome_program_init(void).
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_libdir(void);
+
+/** Returns the pkgdatadir path, usually
+ * "$prefix/share/gnucash". Needed for gnome_program_init(void).
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_pkgdatadir(void);
+
+/** Returns the pkgsysconfdir path, usually
+ * "$prefix/etc/gnucash". Needed for gnome_program_init(void).
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_pkgsysconfdir(void);
+
+
+/** Returns the pkglibdir path, usually
+ * "$prefix/lib/gnucash".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_pkglibdir(void);
+
+/** Returns the glade file path, usually
+ * "$prefix/share/gnucash/glade".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_gladedir(void);
+
+/** Returns the localedir path, usually
+ * "$prefix/share/locale".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_localedir(void);
+
+/** Returns the glade file path, usually
+ * "$prefix/share/gnucash/accounts".
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_accountsdir(void);
+
+/** Returns the gconf schema config source path, usually
+ * "$prefix/etc/gconf/gconf.xml.defaults".
+ *
+ * @param force_slashes Use slashes as separator of the elements
+ * of the path.
+ *
+ * @returns A newly allocated string. */
+gchar *gnc_path_get_gconfdir(gboolean force_slashes);
+
+
+
+#endif /* GNC_PATH_H */

Copied: gnucash/trunk/src/core-utils/gncla-dir.h.in (from rev 18809, gnucash/trunk/src/engine/gncla-dir.h.in)
===================================================================
--- gnucash/trunk/src/core-utils/gncla-dir.h.in	                        (rev 0)
+++ gnucash/trunk/src/core-utils/gncla-dir.h.in	2010-03-04 16:32:54 UTC (rev 18811)
@@ -0,0 +1,32 @@
+/***************************************************************************
+ *            gncla-dir.h
+ *
+ *  Mon Dec 20 20:27:48 2004
+ *  Copyright  2004  Neil Williams
+ *  linux at codehelp.co.uk
+ ****************************************************************************/
+
+/*
+ *  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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+#define PREFIX "@-prefix-@"
+#define DATADIR "@-datadir-@"
+#define SYSCONFDIR "@-sysconfdir-@"
+
+#define LIBDIR "@-libdir-@"
+
+#define LOCALE_DATADIRNAME "@-DATADIRNAME-@"

Modified: gnucash/trunk/src/engine/Makefile.am
===================================================================
--- gnucash/trunk/src/engine/Makefile.am	2010-03-04 10:31:41 UTC (rev 18810)
+++ gnucash/trunk/src/engine/Makefile.am	2010-03-04 16:32:54 UTC (rev 18811)
@@ -27,17 +27,14 @@
   Split.c \
   TransLog.c \
   Transaction.c \
-  binreloc.c \
   cap-gains.c \
   cashobjects.c \
   gnc-associate-account.c \
   gnc-budget.c \
   gnc-commodity.c \
   gnc-engine.c \
-  gnc-filepath-utils.c \
   gnc-hooks.c \
   gnc-lot.c \
-  gnc-path.c \
   gnc-pricedb.c \
   gnc-session.c \
   gnc-session-scm.c \
@@ -70,7 +67,6 @@
   Split.h \
   TransLog.h \
   Transaction.h \
-  binreloc.h \
   cap-gains.h \
   cashobjects.h \
   engine-helpers.h \
@@ -80,9 +76,7 @@
   gnc-commodity.h \
   gnc-engine.h \
   gnc-event.h \
-  gnc-filepath-utils.h \
   gnc-hooks.h \
-  gnc-path.h \
   gnc-pricedb.h \
   gnc-session.h \
   gnc-session-scm.h \
@@ -135,7 +129,6 @@
   extensions.txt \
   iso-4217-currencies.scm \
   iso-currencies-to-c \
-  gncla-dir.h.in \
   kvp_doc.txt \
   SX-book-p.h \
   engine.i \
@@ -178,20 +171,9 @@
 	-chmod u+x ${srcdir}/iso-currencies-to-c
 	GUILE_LOAD_PATH=@GNC_SRFI_LOAD_PATH@:${GUILE_LOAD_PATH} srcdir=${srcdir} ${srcdir}/iso-currencies-to-c
 
-gncla-dir.h: gncla-dir.h.in ${top_builddir}/config.status Makefile
-	rm -f $@.tmp
-	sed < $< > $@.tmp \
-		-e 's#@-DATADIRNAME-@#${DATADIRNAME}#g' \
-		-e 's#@-libdir-@#${libdir}#g' \
-		-e 's#@-sysconfdir-@#${sysconfdir}#g' \
-		-e 's#@-datadir-@#${datadir}#g' \
-		-e 's#@-prefix-@#${prefix}#g'
-	mv $@.tmp $@
+BUILT_SOURCES = iso-4217-currencies.c
 
-BUILT_SOURCES = iso-4217-currencies.c \
-  gncla-dir.h
-
-CLEANFILES = $(BUILT_SOURCES) gnucash .scm-links gncla-dir.h \
+CLEANFILES = $(BUILT_SOURCES) gnucash .scm-links \
 	${SCM_FILE_LINKS}
 MAINTAINERCLEANFILES = swig-engine.c
 

Deleted: gnucash/trunk/src/engine/binreloc.c
===================================================================
--- gnucash/trunk/src/engine/binreloc.c	2010-03-04 10:31:41 UTC (rev 18810)
+++ gnucash/trunk/src/engine/binreloc.c	2010-03-04 16:32:54 UTC (rev 18811)
@@ -1,782 +0,0 @@
-/*
- * BinReloc - a library for creating relocatable executables
- * Written by: Hongli Lai <h.lai at chello.nl>
- * http://autopackage.org/
- *
- * This source code is public domain. You can relicense this code
- * under whatever license you want.
- *
- * See http://autopackage.org/docs/binreloc/ for
- * more information and how to use this.
- */
-
-#ifndef __BINRELOC_C__
-#define __BINRELOC_C__
-#include "config.h"
-
-#ifdef ENABLE_BINRELOC
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#ifdef MAC_INTEGRATION
-#include <igemacintegration/ige-mac-bundle.h>
-#endif
-#endif /* ENABLE_BINRELOC */
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <string.h>
-#include "binreloc.h"
-#include <glib.h>
-
-G_BEGIN_DECLS
-#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION
-static IgeMacBundle *bundle = NULL;
-#endif
-
-/** @internal
- * Find the canonical filename of the executable. Returns the filename
- * (which must be freed) or NULL on error. If the parameter 'error' is
- * not NULL, the error code will be stored there, if an error occured.
- */
-static char *
-_br_find_exe (GbrInitError *error)
-{
-#ifndef ENABLE_BINRELOC
-    if (error)
-        *error = GBR_INIT_ERROR_DISABLED;
-    return NULL;
-#else
-#ifdef G_OS_WIN32
-    /* I *thought* this program code already included the
-       relocation code for windows. Unfortunately this is not
-       the case and we have to add this manually. This is only
-       one possibility; other ways of looking up the full path
-       of gnucash-bin.exe probably exist.*/
-    gchar *prefix;
-    gchar *result;
-
-    /* From the glib docs: When passed NULL, this function looks
-       up installation the directory of the main executable of
-       the current process */
-    prefix = g_win32_get_package_installation_directory_of_module (NULL);
-    result = g_build_filename (prefix,
-                               "bin", "gnucash-bin.exe",
-                               (char*)NULL);
-    g_free (prefix);
-    return result;
-#elif MAC_INTEGRATION
-    gchar *prefix = NULL, *result = NULL;
-    g_type_init();
-    bundle = ige_mac_bundle_new();
-    if (!bundle)
-    {
-        *error = GBR_INIT_ERROR_MAC_NOT_BUNDLE;
-        return NULL;
-    }
-    if (!ige_mac_bundle_get_is_app_bundle (bundle))
-    {
-        g_object_unref(bundle);
-        bundle = NULL;
-        *error = GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE;
-        return NULL;
-    }
-    ige_mac_bundle_setup_environment(bundle);
-    prefix = g_strdup(ige_mac_bundle_get_path(bundle));
-    result = g_build_filename(prefix, "Contents/MacOS",
-                              "gnucash-bin", NULL);
-    g_free(prefix);
-    return result;
-#else
-    char *path, *path2, *line, *result;
-    size_t buf_size;
-    ssize_t size;
-    struct stat stat_buf;
-    FILE *f;
-
-    /* Read from /proc/self/exe (symlink) */
-    if (sizeof (path) > SSIZE_MAX)
-        buf_size = SSIZE_MAX - 1;
-    else
-        buf_size = PATH_MAX - 1;
-    path = (char *) g_try_malloc (buf_size);
-    if (path == NULL)
-    {
-        /* Cannot allocate memory. */
-        if (error)
-            *error = GBR_INIT_ERROR_NOMEM;
-        return NULL;
-    }
-    path2 = (char *) g_try_malloc (buf_size);
-    if (path2 == NULL)
-    {
-        /* Cannot allocate memory. */
-        if (error)
-            *error = GBR_INIT_ERROR_NOMEM;
-        g_free (path);
-        return NULL;
-    }
-
-    strncpy (path2, "/proc/self/exe", buf_size - 1);
-
-    while (1)
-    {
-        int i;
-
-        size = readlink (path2, path, buf_size - 1);
-        if (size == -1)
-        {
-            /* Error. */
-            g_free (path2);
-            break;
-        }
-
-        /* readlink() success. */
-        path[size] = '\0';
-
-        /* Check whether the symlink's target is also a symlink.
-         * We want to get the final target. */
-        i = stat (path, &stat_buf);
-        if (i == -1)
-        {
-            /* Error. */
-            g_free (path2);
-            break;
-        }
-
-        /* stat() success. */
-        if (!S_ISLNK (stat_buf.st_mode))
-        {
-            /* path is not a symlink. Done. */
-            g_free (path2);
-            return path;
-        }
-
-        /* path is a symlink. Continue loop and resolve this. */
-        strncpy (path, path2, buf_size - 1);
-    }
-
-
-    /* readlink() or stat() failed; this can happen when the program is
-     * running in Valgrind 2.2. Read from /proc/self/maps as fallback. */
-
-    buf_size = PATH_MAX + 128;
-    line = (char *) g_try_realloc (path, buf_size);
-    if (line == NULL)
-    {
-        /* Cannot allocate memory. */
-        g_free (path);
-        if (error)
-            *error = GBR_INIT_ERROR_NOMEM;
-        return NULL;
-    }
-
-    f = fopen ("/proc/self/maps", "r");
-    if (f == NULL)
-    {
-        g_free (line);
-        if (error)
-            *error = GBR_INIT_ERROR_OPEN_MAPS;
-        return NULL;
-    }
-
-    /* The first entry should be the executable name. */
-    result = fgets (line, (int) buf_size, f);
-    if (result == NULL)
-    {
-        fclose (f);
-        g_free (line);
-        if (error)
-            *error = GBR_INIT_ERROR_READ_MAPS;
-        return NULL;
-    }
-
-    /* Get rid of newline character. */
-    buf_size = strlen (line);
-    if (buf_size <= 0)
-    {
-        /* Huh? An empty string? */
-        fclose (f);
-        g_free (line);
-        if (error)
-            *error = GBR_INIT_ERROR_INVALID_MAPS;
-        return NULL;
-    }
-    if (line[buf_size - 1] == 10)
-        line[buf_size - 1] = 0;
-
-    /* Extract the filename; it is always an absolute path. */
-    path = strchr (line, '/');
-
-    /* Sanity check. */
-    if (strstr (line, " r-xp ") == NULL || path == NULL)
-    {
-        fclose (f);
-        g_free (line);
-        if (error)
-            *error = GBR_INIT_ERROR_INVALID_MAPS;
-        return NULL;
-    }
-
-    path = g_strdup (path);
-    g_free (line);
-    fclose (f);
-    return path;
-#endif /* G_OS_WINDOWS */
-#endif /* ENABLE_BINRELOC */
-}
-
-
-/** @internal
- * Find the canonical filename of the executable which owns symbol.
- * Returns a filename which must be freed, or NULL on error.
- */
-static char *
-_br_find_exe_for_symbol (const void *symbol, GbrInitError *error)
-{
-#ifndef ENABLE_BINRELOC
-    if (error)
-        *error = GBR_INIT_ERROR_DISABLED;
-    return (char *) NULL;
-#else
-#if defined G_OS_WIN32
-    g_warning ("_br_find_exe_for_symbol not implemented on win32.");
-    if (error)
-        *error = GBR_INIT_ERROR_DISABLED;
-    return (char *) NULL;
-#else
-#define SIZE PATH_MAX + 100
-    FILE *f;
-    size_t address_string_len;
-    char *address_string, line[SIZE], *found;
-
-    if (symbol == NULL)
-        return (char *) NULL;
-
-    f = fopen ("/proc/self/maps", "r");
-    if (f == NULL)
-        return (char *) NULL;
-
-    address_string_len = 4;
-    address_string = (char *) g_try_malloc (address_string_len);
-    found = (char *) NULL;
-
-    while (!feof (f))
-    {
-        char *start_addr, *end_addr, *end_addr_end, *file;
-        void *start_addr_p, *end_addr_p;
-        size_t len;
-
-        if (fgets (line, SIZE, f) == NULL)
-            break;
-
-        /* Sanity check. */
-        if (strstr (line, " r-xp ") == NULL || strchr (line, '/') == NULL)
-            continue;
-
-        /* Parse line. */
-        start_addr = line;
-        end_addr = strchr (line, '-');
-        file = strchr (line, '/');
-
-        /* More sanity check. */
-        if (!(file > end_addr && end_addr != NULL && end_addr[0] == '-'))
-            continue;
-
-        end_addr[0] = '\0';
-        end_addr++;
-        end_addr_end = strchr (end_addr, ' ');
-        if (end_addr_end == NULL)
-            continue;
-
-        end_addr_end[0] = '\0';
-        len = strlen (file);
-        if (len == 0)
-            continue;
-        if (file[len - 1] == '\n')
-            file[len - 1] = '\0';
-
-        /* Get rid of "(deleted)" from the filename. */
-        len = strlen (file);
-        if (len > 10 && strcmp (file + len - 10, " (deleted)") == 0)
-            file[len - 10] = '\0';
-
-        /* I don't know whether this can happen but better safe than sorry. */
-        len = strlen (start_addr);
-        if (len != strlen (end_addr))
-            continue;
-
-
-        /* Transform the addresses into a string in the form of 0xdeadbeef,
-         * then transform that into a pointer. */
-        if (address_string_len < len + 3)
-        {
-            address_string_len = len + 3;
-            address_string = (char *) g_try_realloc (address_string, address_string_len);
-        }
-
-        memcpy (address_string, "0x", 2);
-        memcpy (address_string + 2, start_addr, len);
-        address_string[2 + len] = '\0';
-        sscanf (address_string, "%p", &start_addr_p);
-
-        memcpy (address_string, "0x", 2);
-        memcpy (address_string + 2, end_addr, len);
-        address_string[2 + len] = '\0';
-        sscanf (address_string, "%p", &end_addr_p);
-
-
-        if (symbol >= start_addr_p && symbol < end_addr_p)
-        {
-            found = file;
-            break;
-        }
-    }
-
-    g_free (address_string);
-    fclose (f);
-
-    if (found == NULL)
-        return (char *) NULL;
-    else
-        return g_strdup (found);
-#endif /* G_OS_WIN32 */
-#endif /* ENABLE_BINRELOC */
-}
-
-
-static gchar *exe = NULL;
-
-static void set_gerror (GError **error, GbrInitError errcode);
-
-
-/** Initialize the BinReloc library (for applications).
- *
- * This function must be called before using any other BinReloc functions.
- * It attempts to locate the application's canonical filename.
- *
- * @note If you want to use BinReloc for a library, then you should call
- *       gbr_init_lib() instead.
- *
- * @param error  If BinReloc failed to initialize, then the error report will
- *               be stored in this variable. Set to NULL if you don't want an
- *               error report. See the #GbrInitError for a list of error
- *               codes.
- *
- * @returns TRUE on success, FALSE if BinReloc failed to initialize.
- */
-gboolean
-gbr_init (GError **error)
-{
-    GbrInitError errcode = 0;
-
-    /* Locate the application's filename. */
-    exe = _br_find_exe (&errcode);
-    if (exe != NULL)
-        /* Success! */
-        return TRUE;
-    else
-    {
-        /* Failed :-( */
-        set_gerror (error, errcode);
-        return FALSE;
-    }
-}
-
-
-/** Initialize the BinReloc library (for libraries).
- *
- * This function must be called before using any other BinReloc functions.
- * It attempts to locate the calling library's canonical filename.
- *
- * @note The BinReloc source code MUST be included in your library, or this
- *       function won't work correctly.
- *
- * @returns TRUE on success, FALSE if a filename cannot be found.
- */
-gboolean
-gbr_init_lib (GError **error)
-{
-    GbrInitError errcode = 0;
-
-    exe = _br_find_exe_for_symbol ((const void *) "", &errcode);
-    if (exe != NULL)
-        /* Success! */
-        return TRUE;
-    else
-    {
-        /* Failed :-( */
-        set_gerror (error, errcode);
-        return exe != NULL;
-    }
-}
-
-
-static void
-set_gerror (GError **error, GbrInitError errcode)
-{
-    gchar *error_message;
-
-    if (error == NULL)
-        return;
-
-    switch (errcode)
-    {
-    case GBR_INIT_ERROR_NOMEM:
-        error_message = "Cannot allocate memory.";
-        break;
-    case GBR_INIT_ERROR_OPEN_MAPS:
-        error_message = "Unable to open /proc/self/maps for reading.";
-        break;
-    case GBR_INIT_ERROR_READ_MAPS:
-        error_message = "Unable to read from /proc/self/maps.";
-        break;
-    case GBR_INIT_ERROR_INVALID_MAPS:
-        error_message = "The file format of /proc/self/maps is invalid.";
-        break;
-    case GBR_INIT_ERROR_MAC_NOT_BUNDLE:
-        error_message = "Binreloc did not find a bundle";
-        break;
-    case GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE:
-        error_message = "Binreloc found that the bundle is not an app bundle";
-        break;
-    case GBR_INIT_ERROR_DISABLED:
-        error_message = "Binary relocation support is disabled.";
-        break;
-    default:
-        error_message = "Unknown error.";
-        break;
-    };
-    g_set_error (error, g_quark_from_static_string ("GBinReloc"),
-                 errcode, "%s", error_message);
-}
-
-
-/** Find the canonical filename of the current application.
- *
- * @param default_exe  A default filename which will be used as fallback.
- * @returns A string containing the application's canonical filename,
- *          which must be freed when no longer necessary. If BinReloc is
- *          not initialized, or if the initialization function failed,
- *          then a copy of default_exe will be returned. If default_exe
- *          is NULL, then NULL will be returned.
- */
-gchar *
-gbr_find_exe (const gchar *default_exe)
-{
-    if (exe == NULL)
-    {
-        /* BinReloc is not initialized. */
-        if (default_exe != NULL)
-            return g_strdup (default_exe);
-        else
-            return NULL;
-    }
-    return g_strdup (exe);
-}
-
-
-/** Locate the directory in which the current application is installed.
- *
- * The prefix is generated by the following pseudo-code evaluation:
- * \code
- * dirname(exename)
- * \endcode
- *
- * @param default_dir  A default directory which will used as fallback.
- * @return A string containing the directory, which must be freed when no
- *         longer necessary. If BinReloc is not initialized, or if the
- *         initialization function failed, then a copy of default_dir
- *         will be returned. If default_dir is NULL, then NULL will be
- *         returned.
- */
-gchar *
-gbr_find_exe_dir (const gchar *default_dir)
-{
-    if (exe == NULL)
-    {
-        /* BinReloc not initialized. */
-        if (default_dir != NULL)
-            return g_strdup (default_dir);
-        else
-            return NULL;
-    }
-
-    return g_path_get_dirname (exe);
-}
-
-
-/** Locate the prefix in which the current application is installed.
- *
- * The prefix is generated by the following pseudo-code evaluation:
- * \code
- * dirname(dirname(exename))
- * \endcode
- *
- * @param default_prefix  A default prefix which will used as fallback.
- * @return A string containing the prefix, which must be freed when no
- *         longer necessary. If BinReloc is not initialized, or if the
- *         initialization function failed, then a copy of default_prefix
- *         will be returned. If default_prefix is NULL, then NULL will be
- *         returned.
- */
-gchar *
-gbr_find_prefix (const gchar *default_prefix)
-{
-    gchar *dir1, *dir2;
-
-#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION
-    gchar *prefix = NULL, *result = NULL;
-    if (bundle == NULL)
-    {
-        /* BinReloc not initialized. */
-        if (default_prefix != NULL)
-            return g_strdup (default_prefix);
-        else
-            return NULL;
-    }
-    prefix = g_strdup(ige_mac_bundle_get_path(bundle));
-    result = g_build_filename(prefix, "Contents/Resources", NULL);
-    g_free(prefix);
-    return result;
-#else
-
-    if (exe == NULL)
-    {
-        /* BinReloc not initialized. */
-        if (default_prefix != NULL)
-            return g_strdup (default_prefix);
-        else
-            return NULL;
-    }
-    dir1 = g_path_get_dirname (exe);
-    dir2 = g_path_get_dirname (dir1);
-    g_free (dir1);
-    return dir2;
-#endif //ENABLE_BINRELOC && MAC_INTEGRATION
-}
-
-
-/** Locate the application's binary folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/bin"
- * \endcode
- *
- * @param default_bin_dir  A default path which will used as fallback.
- * @return A string containing the bin folder's path, which must be freed when
- *         no longer necessary. If BinReloc is not initialized, or if the
- *         initialization function failed, then a copy of default_bin_dir will
- *         be returned. If default_bin_dir is NULL, then NULL will be returned.
- */
-gchar *
-gbr_find_bin_dir (const gchar *default_bin_dir)
-{
-    gchar *prefix, *dir;
-#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION
-    if (bundle == NULL)
-    {
-        /* BinReloc not initialized. */
-        if (default_bin_dir != NULL)
-            return g_strdup (default_bin_dir);
-        else
-            return NULL;
-    }
-    prefix = g_strdup(ige_mac_bundle_get_path(bundle));
-    dir = g_build_filename(prefix, "Contents/MacOS", NULL);
-    g_free(prefix);
-    return dir;
-#else
-
-    prefix = gbr_find_prefix (NULL);
-    if (prefix == NULL)
-    {
-        /* BinReloc not initialized. */
-        if (default_bin_dir != NULL)
-            return g_strdup (default_bin_dir);
-        else
-            return NULL;
-    }
-
-    dir = g_build_filename (prefix, "bin", NULL);
-    g_free (prefix);
-    return dir;
-#endif //ENABLE_BINRELOC && MAC_INTEGRATION
-}
-
-
-/** Locate the application's superuser binary folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/sbin"
- * \endcode
- *
- * @param default_sbin_dir  A default path which will used as fallback.
- * @return A string containing the sbin folder's path, which must be freed when
- *         no longer necessary. If BinReloc is not initialized, or if the
- *         initialization function failed, then a copy of default_sbin_dir will
- *         be returned. If default_bin_dir is NULL, then NULL will be returned.
- */
-gchar *
-gbr_find_sbin_dir (const gchar *default_sbin_dir)
-{
-    gchar *prefix, *dir;
-
-    prefix = gbr_find_prefix (NULL);
-    if (prefix == NULL)
-    {
-        /* BinReloc not initialized. */
-        if (default_sbin_dir != NULL)
-            return g_strdup (default_sbin_dir);
-        else
-            return NULL;
-    }
-
-    dir = g_build_filename (prefix, "sbin", NULL);
-    g_free (prefix);
-    return dir;
-}
-
-
-/** Locate the application's data folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/share"
- * \endcode
- *
- * @param default_data_dir  A default path which will used as fallback.
- * @return A string containing the data folder's path, which must be freed when
- *         no longer necessary. If BinReloc is not initialized, or if the
- *         initialization function failed, then a copy of default_data_dir
- *         will be returned. If default_data_dir is NULL, then NULL will be
- *         returned.
- */
-gchar *
-gbr_find_data_dir (const gchar *default_data_dir)
-{
-    gchar *prefix, *dir;
-
-    prefix = gbr_find_prefix (NULL);
-    if (prefix == NULL)
-    {
-        /* BinReloc not initialized. */
-        if (default_data_dir != NULL)
-            return g_strdup (default_data_dir);
-        else
-            return NULL;
-    }
-
-    dir = g_build_filename (prefix, "share", NULL);
-    g_free (prefix);
-    return dir;
-}
-
-
-/** Locate the application's library folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/lib"
- * \endcode
- *
- * @param default_lib_dir  A default path which will used as fallback.
- * @return A string containing the library folder's path, which must be freed when
- *         no longer necessary. If BinReloc is not initialized, or if the
- *         initialization function failed, then a copy of default_lib_dir will be returned.
- *         If default_lib_dir is NULL, then NULL will be returned.
- */
-gchar *
-gbr_find_lib_dir (const gchar *default_lib_dir)
-{
-    gchar *prefix, *dir;
-
-    prefix = gbr_find_prefix (NULL);
-    if (prefix == NULL)
-    {
-        /* BinReloc not initialized. */
-        if (default_lib_dir != NULL)
-            return g_strdup (default_lib_dir);
-        else
-            return NULL;
-    }
-
-    dir = g_build_filename (prefix, "lib", NULL);
-    g_free (prefix);
-    return dir;
-}
-
-
-/** Locate the application's libexec folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/libexec"
- * \endcode
- *
- * @param default_libexec_dir  A default path which will used as fallback.
- * @return A string containing the libexec folder's path, which must be freed when
- *         no longer necessary. If BinReloc is not initialized, or if the initialization
- *         function failed, then a copy of default_libexec_dir will be returned.
- *         If default_libexec_dir is NULL, then NULL will be returned.
- */
-gchar *
-gbr_find_libexec_dir (const gchar *default_libexec_dir)
-{
-    gchar *prefix, *dir;
-
-    prefix = gbr_find_prefix (NULL);
-    if (prefix == NULL)
-    {
-        /* BinReloc not initialized. */
-        if (default_libexec_dir != NULL)
-            return g_strdup (default_libexec_dir);
-        else
-            return NULL;
-    }
-
-    dir = g_build_filename (prefix, "libexec", NULL);
-    g_free (prefix);
-    return dir;
-}
-
-
-/** Locate the application's configuration files folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/etc"
- * \endcode
- *
- * @param default_etc_dir  A default path which will used as fallback.
- * @return A string containing the etc folder's path, which must be freed when
- *         no longer necessary. If BinReloc is not initialized, or if the initialization
- *         function failed, then a copy of default_etc_dir will be returned.
- *         If default_etc_dir is NULL, then NULL will be returned.
- */
-gchar *
-gbr_find_etc_dir (const gchar *default_etc_dir)
-{
-    gchar *prefix, *dir;
-
-    prefix = gbr_find_prefix (NULL);
-    if (prefix == NULL)
-    {
-        /* BinReloc not initialized. */
-        if (default_etc_dir != NULL)
-            return g_strdup (default_etc_dir);
-        else
-            return NULL;
-    }
-
-    dir = g_build_filename (prefix, "etc", NULL);
-    g_free (prefix);
-    return dir;
-}
-
-
-G_END_DECLS
-
-#endif /* __BINRELOC_C__ */

Deleted: gnucash/trunk/src/engine/binreloc.h
===================================================================
--- gnucash/trunk/src/engine/binreloc.h	2010-03-04 10:31:41 UTC (rev 18810)
+++ gnucash/trunk/src/engine/binreloc.h	2010-03-04 16:32:54 UTC (rev 18811)
@@ -1,71 +0,0 @@
-/*
- * BinReloc - a library for creating relocatable executables
- * Written by: Hongli Lai <h.lai at chello.nl>
- * http://autopackage.org/
- *
- * This source code is public domain. You can relicense this code
- * under whatever license you want.
- *
- * See http://autopackage.org/docs/binreloc/ for
- * more information and how to use this.
- */
-
-#ifndef __BINRELOC_H__
-#define __BINRELOC_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-
-/** These error codes can be returned by br_init(), br_init_lib(), gbr_init() or gbr_init_lib(). */
-typedef enum
-{
-    /** Cannot allocate memory. */
-    GBR_INIT_ERROR_NOMEM,
-    /** Unable to open /proc/self/maps; see errno for details. */
-    GBR_INIT_ERROR_OPEN_MAPS,
-    /** Unable to read from /proc/self/maps; see errno for details. */
-    GBR_INIT_ERROR_READ_MAPS,
-    /** The file format of /proc/self/maps is invalid; kernel bug? */
-    GBR_INIT_ERROR_INVALID_MAPS,
-    /** BinReloc determined that gnucash is not running from a bundle */
-    GBR_INIT_ERROR_MAC_NOT_BUNDLE,
-    /** Binreloc determined that the bundle is not an app bundle */
-    GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE,
-    /** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */
-    GBR_INIT_ERROR_DISABLED
-} GbrInitError;
-
-
-#ifndef BINRELOC_RUNNING_DOXYGEN
-/* Mangle symbol names to avoid symbol collisions with other ELF objects. */
-#define gbr_find_exe         ffEt66859784967989_gbr_find_exe
-#define gbr_find_exe_dir     ffEt66859784967989_gbr_find_exe_dir
-#define gbr_find_prefix      ffEt66859784967989_gbr_find_prefix
-#define gbr_find_bin_dir     ffEt66859784967989_gbr_find_bin_dir
-#define gbr_find_sbin_dir    ffEt66859784967989_gbr_find_sbin_dir
-#define gbr_find_data_dir    ffEt66859784967989_gbr_find_data_dir
-#define gbr_find_lib_dir     ffEt66859784967989_gbr_find_lib_dir
-#define gbr_find_libexec_dir ffEt66859784967989_gbr_find_libexec_dir
-#define gbr_find_etc_dir     ffEt66859784967989_gbr_find_etc_dir
-
-
-#endif
-gboolean gbr_init             (GError **error);
-gboolean gbr_init_lib         (GError **error);
-
-gchar   *gbr_find_exe         (const gchar *default_exe);
-gchar   *gbr_find_exe_dir     (const gchar *default_dir);
-gchar   *gbr_find_prefix      (const gchar *default_prefix);
-gchar   *gbr_find_bin_dir     (const gchar *default_bin_dir);
-gchar   *gbr_find_sbin_dir    (const gchar *default_sbin_dir);
-gchar   *gbr_find_data_dir    (const gchar *default_data_dir);
-gchar   *gbr_find_lib_dir     (const gchar *default_lib_dir);
-gchar   *gbr_find_libexec_dir (const gchar *default_libexec_dir);
-gchar   *gbr_find_etc_dir     (const gchar *default_etc_dir);
-
-
-G_END_DECLS
-
-#endif /* __BINRELOC_H__ */

Deleted: gnucash/trunk/src/engine/gnc-filepath-utils.c
===================================================================
--- gnucash/trunk/src/engine/gnc-filepath-utils.c	2010-03-04 10:31:41 UTC (rev 18810)
+++ gnucash/trunk/src/engine/gnc-filepath-utils.c	2010-03-04 16:32:54 UTC (rev 18811)
@@ -1,495 +0,0 @@
-/********************************************************************\
- * gnc-filepath-utils.c -- file path resolutin utilitie             *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
-\********************************************************************/
-
-/*
- * @file gnc-filepath-utils.c
- * @brief file path resolution utilities
- * @author Copyright (c) 1998-2004 Linas Vepstas <linas at linas.org>
- * @author Copyright (c) 2000 Dave Peticolas
- *
- * XXX this file does not belong in the gnucash engine; it is here
- * for the moment only because both the file backend and the app-file
- * GUI code make use of it.
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <glib/gprintf.h>
-#include <glib/gstdio.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-#include <errno.h>
-
-#include "gnc-engine.h"
-#include "gnc-path.h"
-#include "gnc-filepath-utils.h"
-
-#ifdef _MSC_VER
-#include <glib/gwin32.h>
-#define PATH_MAX MAXPATHLEN
-#endif
-
-static QofLogModule log_module = GNC_MOD_BACKEND;
-
-
-/**
- * Scrubs a filename by changing "strange" chars (e.g. those that are not
- * valid in a win32 file name) to "_".
- *
- * @param filename File name - updated in place
- */
-static void
-scrub_filename(char* filename)
-{
-    char* p;
-
-#define STRANGE_CHARS "/:"
-    p = strpbrk(filename, STRANGE_CHARS);
-    while (p)
-    {
-        *p = '_';
-        p = strpbrk(filename, STRANGE_CHARS);
-    }
-}
-
-/** Check if the path exists and is a regular file.
- *
- * \param path -- freed if the path doesn't exist or isn't a regular file
- *
- *  \return NULL or the path
- */
-static gchar *
-check_path_return_if_valid(gchar *path)
-{
-    ENTER("Path: %s", path);
-    if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
-    {
-        LEAVE("found %s", path);
-        return path;
-    }
-    g_free (path);
-    return NULL;
-}
-
-/** @fn char * xaccResolveFilePath (const char * filefrag)
- *
- *  @brief Create an absolute path when given a relative path;
- *  otherwise return the argument.
- *
- * If passed a string which g_path_is_absolute declares an absolute
- * path, return the argument. If the string begins with file:,
- * file://, xml:, or xml://, remove that and return the rest.
- *
- * Otherwise, assume that filefrag is a well-formed relative path and
- * try to find a file with its path relative to the current working
- * directory, the installed system-wide data directory (e.g.,
- * /usr/local/share/gnucash), the installed system configuration
- * directory (e.g., /usr/local/etc/gnucash), or in the user's
- * configuration directory (e.g., $HOME/.gnucash/data) in that
- * order. If a matching file is found, return the absolute path to
- * it. If one isn't found, return a absolute path relative to the
- * user's configuration directory and note in the trace file that it
- * needs to be created.
- *
- * @param filefrag
- *
- * @return An absolute file path.
- */
-char *
-xaccResolveFilePath (const char * filefrag)
-{
-    int namelen;
-    gchar *fullpath = NULL, *tmp_path = NULL;
-
-    /* seriously invalid */
-    if (!filefrag)
-    {
-        PERR("filefrag is NULL");
-        return NULL;
-    }
-
-    ENTER ("filefrag=%s", filefrag);
-
-    /* ---------------------------------------------------- */
-    /* OK, now we try to find or build an absolute file path */
-
-    /* check for an absolute file path */
-    if (g_path_is_absolute(filefrag))
-    {
-        LEAVE("filefrag is absolute path");
-        return g_strdup (filefrag);
-    }
-
-    if (!g_ascii_strncasecmp(filefrag, "file:", 5))
-    {
-        LEAVE("filefrag is file uri");
-        if (!g_ascii_strncasecmp(filefrag, "file://", 7))
-            return g_strdup(filefrag + 7);
-        else
-            return g_strdup(filefrag + 5);
-    }
-    if ( g_ascii_strncasecmp( filefrag, "xml:", 4 ) == 0 )
-    {
-        LEAVE( "filefrag is xml file uri" );
-        if ( g_ascii_strncasecmp( filefrag, "xml://", 6 ) == 0 )
-            return g_strdup( filefrag + 6);
-        else
-            return g_strdup( filefrag + 4);
-    }
-
-
-    /* get conservative on the length so that sprintf(getpid()) works ... */
-    /* strlen ("/.LCK") + sprintf (%x%d) */
-    namelen = strlen (filefrag) + 25;
-
-    /* Look in the current working directory */
-    tmp_path = g_get_current_dir();
-    fullpath = g_build_filename(tmp_path, filefrag, (gchar *)NULL);
-    g_free(tmp_path);
-    fullpath = check_path_return_if_valid(fullpath);
-    if (fullpath != NULL)
-    {
-        LEAVE("found %s", fullpath);
-        return fullpath;
-    }
-
-    /* Look in the data dir (e.g. $PREFIX/share/gnucash) */
-    tmp_path = gnc_path_get_pkgdatadir();
-    fullpath = g_build_filename(tmp_path, filefrag, (gchar *)NULL);
-    g_free(tmp_path);
-    fullpath = check_path_return_if_valid(fullpath);
-    if (fullpath != NULL)
-    {
-        LEAVE("found %s", fullpath);
-        return fullpath;
-    }
-
-    /* Look in the config dir (e.g. $PREFIX/etc/gnucash) */
-    tmp_path = gnc_path_get_accountsdir();
-    fullpath = g_build_filename(tmp_path, filefrag, (gchar *)NULL);
-    g_free(tmp_path);
-    fullpath = check_path_return_if_valid(fullpath);
-    if (fullpath != NULL)
-    {
-        LEAVE("found %s", fullpath);
-        return fullpath;
-    }
-
-    /* Look in the users config dir (e.g. $HOME/.gnucash/data) */
-    fullpath = gnc_build_data_path(filefrag);
-    if (g_file_test(fullpath, G_FILE_TEST_IS_REGULAR))
-    {
-        LEAVE("found %s", fullpath);
-        return fullpath;
-    }
-    /* OK, it's not there. Note that it needs to be created and pass it
-     * back anyway */
-    LEAVE("create new file %s", fullpath);
-    return fullpath;
-
-}
-
-/* ====================================================================== */
-
-/** @fn char * xaccResolveURL (const char * pathfrag)
- *
- *  @brief Return the passed-in string unless it starts with file:,
- *  xml:, or is a raw relative path.
- *
- * Strings starting with http://, https://, or a "registered scheme"
- * (see qof_backend_get_registered_access_method_list()) are returned
- * as-is by this function.
- *
- * Strings which form an absolute path (as determined by
- * g_path_is_absolute()) are passed to xaccResolveFilePath() and
- * immediately returned as-is.
- *
- * Strings which begin with file: or xml: are passed to
- * xaccResolveFilePath, which strips off the "scheme" part (file: or
- * xml: plus // if present) and returns the rest unchanged. This
- * result is passed back to the caller as-is if the original astring
- * started with file:; if it started with xml:, then xml: is prepended
- * before passing it back to the caller. Note that this has the effect
- * of converting a URI of the form xml:///path/to/file into one of the
- * form xml:/path/to/file.
- *
- * Strings which meet none of the above are passed to
- * xaccResolveFilePath and the result returned to the caller.
- *
- * @param pathfrag the string to "resolve"
- *
- *  @return "resolved" string.
- */
-char *
-xaccResolveURL (const char * pathfrag)
-{
-    GList* list;
-    GList* node;
-
-    /* seriously invalid */
-    if (!pathfrag) return NULL;
-
-    /* At this stage of checking, URL's are always, by definition,
-     * resolved.  If there's an error connecting, we'll find out later.
-     */
-
-    if (!g_ascii_strncasecmp (pathfrag, "http://", 7) ||
-            !g_ascii_strncasecmp (pathfrag, "https://", 8))
-    {
-        return g_strdup(pathfrag);
-    }
-
-    /* Check the URL against the list of registered access methods */
-    list = qof_backend_get_registered_access_method_list();
-    for ( node = list; node != NULL; node = node->next )
-    {
-        const gchar* access_method = node->data;
-        if ( strcmp( access_method, "file" ) != 0 &&
-                strcmp( access_method, "xml" ) != 0 )
-        {
-            gchar s[30];
-            sprintf( s, "%s://", access_method );
-            if ( !g_ascii_strncasecmp( pathfrag, s, strlen(s) ) )
-            {
-                g_list_free(list);
-                return g_strdup(pathfrag);
-            }
-        }
-    }
-    g_list_free(list);
-    /*
-     * xml: schemes are a special case, becuase gnc_file_do_save_as()
-     * relies on the phony scheme id being present in the returned path
-     * to distinguish the backend used to save the file. Note that this
-     * has the amusing effect of stripping the // from the phony scheme,
-     * so if it started out as xml:///path/to/data, it gets returned
-     * from here as xml:/path/to/data.
-     */
-    if (!g_ascii_strncasecmp (pathfrag, "xml:", 4))
-    {
-        return (g_strdup_printf( "xml:%s", xaccResolveFilePath (pathfrag)) );
-    }
-    return (xaccResolveFilePath (pathfrag));
-}
-
-/* ====================================================================== */
-
-/** @fn void gnc_validate_directory (const gchar *dirname)
- *  @brief Check that the supplied directory path exists, is a directory, and that the user has adequate permissions to use it.
- *
- * @param dirname The path to check
- */
-static void
-gnc_validate_directory (const gchar *dirname)
-{
-    struct stat statbuf;
-    gint rc;
-
-    rc = g_stat (dirname, &statbuf);
-    if (rc)
-    {
-        switch (errno)
-        {
-        case ENOENT:
-            rc = g_mkdir (dirname,
-#ifdef G_OS_WIN32
-                          0          /* The mode argument is ignored on windows */
-#else
-                          S_IRWXU    /* perms = S_IRWXU = 0700 */
-#endif
-                         );
-            if (rc)
-            {
-                g_fprintf(stderr,
-                          _("An error occurred while creating the directory:\n"
-                            "  %s\n"
-                            "Please correct the problem and restart GnuCash.\n"
-                            "The reported error was '%s' (errno %d).\n"),
-                          dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
-                exit(1);
-            }
-            g_stat (dirname, &statbuf);
-            break;
-
-        case EACCES:
-            g_fprintf(stderr,
-                      _("The directory\n"
-                        "  %s\n"
-                        "exists but cannot be accessed.  This program \n"
-                        "must have full access (read/write/execute) to \n"
-                        "the directory in order to function properly.\n"),
-                      dirname);
-            exit(1);
-
-        case ENOTDIR:
-            g_fprintf(stderr,
-                      _("The path\n"
-                        "  %s\n"
-                        "exists but it is not a directory. Please delete\n"
-                        "the file and start GnuCash again.\n"),
-                      dirname);
-            exit(1);
-
-        default:
-            g_fprintf(stderr,
-                      _("An unknown error occurred when validating that the\n"
-                        "  %s\n"
-                        "directory exists and is usable. Please correct the\n"
-                        "problem and restart GnuCash.  The reported error \n"
-                        "was '%s' (errno %d)."),
-                      dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
-            exit(1);
-        }
-    }
-
-    if ((statbuf.st_mode & S_IFDIR) != S_IFDIR)
-    {
-        g_fprintf(stderr,
-                  _("The path\n"
-                    "  %s\n"
-                    "exists but it is not a directory. Please delete\n"
-                    "the file and start GnuCash again.\n"),
-                  dirname);
-        exit(1);
-    }
-#ifndef G_OS_WIN32
-    /* The mode argument is ignored on windows anyway */
-    if ((statbuf.st_mode & S_IRWXU) != S_IRWXU)
-    {
-        g_fprintf(stderr,
-                  _("The permissions are wrong on the directory\n"
-                    "  %s\n"
-                    "They must be at least 'rwx' for the user.\n"),
-                  dirname);
-        exit(1);
-    }
-#endif
-}
-
-/** @fn const gchar * gnc_dotgnucash_dir ()
- *  @brief Ensure that the user's configuration directory exists and is minimally populated.
- *
- *  Note that the default path is $HOME/.gnucash; This can be changed
- *  by the environment variable $GNC_DOT_DIR.
- *
- *  @return An absolute path to the configuration directory
- */
-const gchar *
-gnc_dotgnucash_dir (void)
-{
-    static gchar *dotgnucash = NULL;
-    gchar *tmp_dir;
-
-    if (dotgnucash)
-        return dotgnucash;
-
-    dotgnucash = g_strdup(g_getenv("GNC_DOT_DIR"));
-
-    if (!dotgnucash)
-    {
-        const gchar *home = g_get_home_dir();
-        if (!home)
-        {
-            g_warning("Cannot find home directory. Using tmp directory instead.");
-            home = g_get_tmp_dir();
-        }
-        g_assert(home);
-
-        dotgnucash = g_build_filename(home, ".gnucash", (gchar *)NULL);
-    }
-    gnc_validate_directory(dotgnucash);
-
-    /* Since we're in code that is only executed once.... */
-    tmp_dir = g_build_filename(dotgnucash, "books", (gchar *)NULL);
-    gnc_validate_directory(tmp_dir);
-    g_free(tmp_dir);
-    tmp_dir = g_build_filename(dotgnucash, "checks", (gchar *)NULL);
-    gnc_validate_directory(tmp_dir);
-    g_free(tmp_dir);
-
-    return dotgnucash;
-}
-
-/** @fn gchar * gnc_build_dotgnucash_path (const gchar *filename)
- *  @brief Make a path to filename in the user's configuration directory.
- *
- * @param filename The name of the file
- *
- *  @return An absolute path.
- */
-
-gchar *
-gnc_build_dotgnucash_path (const gchar *filename)
-{
-    return g_build_filename(gnc_dotgnucash_dir(), filename, (gchar *)NULL);
-}
-
-/** @fn gchar * gnc_build_book_path (const gchar *filename)
- *  @brief Make a path to filename in the book subdirectory of the user's configuration directory.
- *
- * @param filename The name of the file
- *
- *  @return An absolute path.
- */
-
-gchar *
-gnc_build_book_path (const gchar *filename)
-{
-    gchar* filename_dup = g_strdup(filename);
-    gchar* result = NULL;
-
-    scrub_filename(filename_dup);
-    result = g_build_filename(gnc_dotgnucash_dir(), "books",
-                              filename_dup, (gchar *)NULL);
-    g_free(filename_dup);
-    return result;
-}
-
-/** @fn gchar * gnc_build_data_path (const gchar *filename)
- *  @brief Make a path to filename in the data subdirectory of the user's configuration directory.
- *
- * @param filename The name of the file
- *
- *  @return An absolute path.
- */
-
-gchar *
-gnc_build_data_path (const gchar *filename)
-{
-    gchar* filename_dup = g_strdup(filename);
-    gchar* result;
-
-    scrub_filename(filename_dup);
-    result = g_build_filename(gnc_dotgnucash_dir(), "data", filename_dup, (gchar *)NULL);
-    g_free(filename_dup);
-    return result;
-}
-
-/* =============================== END OF FILE ========================== */

Deleted: gnucash/trunk/src/engine/gnc-filepath-utils.h
===================================================================
--- gnucash/trunk/src/engine/gnc-filepath-utils.h	2010-03-04 10:31:41 UTC (rev 18810)
+++ gnucash/trunk/src/engine/gnc-filepath-utils.h	2010-03-04 16:32:54 UTC (rev 18811)
@@ -1,54 +0,0 @@
-/********************************************************************\
- * gnc-filepath-utils.h -- file path resolutin utilitie             *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
-\********************************************************************/
-
-/**
- * @file gnc-filepath-utils.h
- * @brief File path resolution utility functions
- * @author Copyright (c) 1998-2004 Linas Vepstas <linas at linas.org>
- * @author Copyright (c) 2000 Dave Peticolas
- *
- * XXX this file does not belong in the gnucash engine; it is here
- * for the moment only because both the file backend and the app-file
- * GUI code make use of it. It should be moved away someday.
- */
-
-#ifndef GNC_FILEPATH_UTILS_H
-#define GNC_FILEPATH_UTILS_H
-
-/** The xaccResolveFilePath() routine is a utility that will accept
- *    a fragmentary filename as input, and resolve it into a fully
- *    qualified path in the file system, i.e. a path that begins with
- *    a leading slash.  First, the current working directory is
- *    searched for the file.  Next, the directory $HOME/.gnucash/data,
- *    and finally, a list of other (configurable) paths.  If the file
- *    is not found, then the path $HOME/.gnucash/data is used.  If
- *    $HOME is not defined, then the current working directory is
- *    used.
- */
-char * xaccResolveFilePath (const char * filefrag);
-char * xaccResolveURL (const char * pathfrag);
-
-const gchar *gnc_dotgnucash_dir (void);
-gchar *gnc_build_dotgnucash_path (const gchar *filename);
-gchar *gnc_build_book_path (const gchar *filename);
-gchar *gnc_build_data_path (const gchar *filename);
-
-#endif /* GNC_FILEPATH_UTILS_H */

Deleted: gnucash/trunk/src/engine/gnc-path.c
===================================================================
--- gnucash/trunk/src/engine/gnc-path.c	2010-03-04 10:31:41 UTC (rev 18810)
+++ gnucash/trunk/src/engine/gnc-path.c	2010-03-04 16:32:54 UTC (rev 18811)
@@ -1,149 +0,0 @@
-/********************************************************************\
- * gnc-path.c -- Path lookup of gnucash installation locations      *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
-\********************************************************************/
-
-#include "config.h"
-#include "gnc-path.h"
-#include "gncla-dir.h"
-#include <stdio.h>
-#include "binreloc.h"
-
-gchar *gnc_path_get_prefix()
-{
-    //printf("Returning prefix %s\n", gbr_find_prefix (PREFIX));
-    return gbr_find_prefix (PREFIX);
-}
-
-/** Returns the libdir path, usually
- * "$prefix/lib". Needed for gnome_program_init().
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_libdir()
-{
-    //printf("Returning libdir %s\n", gbr_find_lib_dir (LIBDIR));
-    return gbr_find_lib_dir (LIBDIR);
-}
-
-/** Returns the datadir path, usually
- * "$prefix/share/gnucash". Needed for gnome_program_init().
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_pkgdatadir()
-{
-    gchar *datadir = gbr_find_data_dir (DATADIR);
-    gchar *result = g_build_filename (datadir, "gnucash", (char*)NULL);
-    g_free (datadir);
-    //printf("Returning pkgdatadir %s\n", result);
-    return result;
-}
-
-/** Returns the sysconfdir path, usually
- * "$prefix/etc/gnucash". Needed for gnome_program_init().
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_pkgsysconfdir()
-{
-    gchar *sysconfdir = gbr_find_etc_dir (SYSCONFDIR);
-    gchar *result = g_build_filename (sysconfdir, "gnucash", (char*)NULL);
-    g_free (sysconfdir);
-    //printf("Returning pkgsysconfdir %s\n", result);
-    return result;
-}
-
-
-/** Returns the pkglibdir path, usually
- * "$prefix/lib/gnucash".
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_pkglibdir()
-{
-    gchar *libdir = gnc_path_get_libdir ();
-    gchar *result = g_build_filename (libdir, "gnucash", (char*)NULL);
-    g_free (libdir);
-    //printf("Returning pkglibdir %s\n", result);
-    return result;
-}
-
-/** Returns the glade file path, usually
- * "$prefix/share/gnucash/glade".
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_gladedir()
-{
-    gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
-    gchar *result = g_build_filename (pkgdatadir, "glade", (char*)NULL);
-    g_free (pkgdatadir);
-    //printf("Returning gladedir %s\n", result);
-    return result;
-}
-
-/** Returns the localedir path, usually
- * "$prefix/share/locale".
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_localedir()
-{
-    gchar *prefix = gnc_path_get_prefix();
-    gchar *result = g_build_filename (prefix, LOCALE_DATADIRNAME, "locale", (char*)NULL);
-    g_free (prefix);
-    //printf("Returning localedir %s\n", result);
-    return result;
-}
-
-/** Returns the glade file path, usually
- * "$prefix/share/gnucash/accounts".
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_accountsdir()
-{
-    gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
-    gchar *result = g_build_filename (pkgdatadir, "accounts", (char*)NULL);
-    g_free (pkgdatadir);
-    //printf("Returning accountsdir %s\n", result);
-    return result;
-}
-
-/** Returns the gconf schema config source path, usually
- * "$prefix/etc/gconf/gconf.xml.defaults".
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_gconfdir(gboolean force_slashes)
-{
-    gchar *sysconfdir = gbr_find_etc_dir (SYSCONFDIR);
-    gchar *separator = G_DIR_SEPARATOR_S;
-    gchar *result;
-
-    if (force_slashes)
-    {
-        gchar **splitted;
-        splitted = g_strsplit (sysconfdir, "\\", -1);
-        g_free (sysconfdir);
-        sysconfdir = g_strjoinv ("/", splitted);
-        g_strfreev (splitted);
-        separator = "/";
-    }
-
-    result = g_build_path (separator, sysconfdir, "gconf", "gconf.xml.defaults",
-                           (gchar*)NULL);
-    g_free (sysconfdir);
-    //printf("Returning gconfdir %s\n", result);
-    return result;
-}
-

Deleted: gnucash/trunk/src/engine/gnc-path.h
===================================================================
--- gnucash/trunk/src/engine/gnc-path.h	2010-03-04 10:31:41 UTC (rev 18810)
+++ gnucash/trunk/src/engine/gnc-path.h	2010-03-04 16:32:54 UTC (rev 18811)
@@ -1,88 +0,0 @@
-/********************************************************************\
- * gnc-path.h -- Path lookup of gnucash installation locations      *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
-\********************************************************************/
-
-
-#ifndef GNC_PATH_H
-#define GNC_PATH_H
-
-#include <glib.h>
-
-/** Returns the installation prefix path, usually
- * "$prefix". Needed for gnome_program_init().
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_prefix(void);
-
-/** Returns the libdir path, usually
- * "$prefix/lib". Needed for gnome_program_init(void).
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_libdir(void);
-
-/** Returns the pkgdatadir path, usually
- * "$prefix/share/gnucash". Needed for gnome_program_init(void).
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_pkgdatadir(void);
-
-/** Returns the pkgsysconfdir path, usually
- * "$prefix/etc/gnucash". Needed for gnome_program_init(void).
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_pkgsysconfdir(void);
-
-
-/** Returns the pkglibdir path, usually
- * "$prefix/lib/gnucash".
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_pkglibdir(void);
-
-/** Returns the glade file path, usually
- * "$prefix/share/gnucash/glade".
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_gladedir(void);
-
-/** Returns the localedir path, usually
- * "$prefix/share/locale".
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_localedir(void);
-
-/** Returns the glade file path, usually
- * "$prefix/share/gnucash/accounts".
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_accountsdir(void);
-
-/** Returns the gconf schema config source path, usually
- * "$prefix/etc/gconf/gconf.xml.defaults".
- *
- * @param force_slashes Use slashes as separator of the elements
- * of the path.
- *
- * @returns A newly allocated string. */
-gchar *gnc_path_get_gconfdir(gboolean force_slashes);
-
-
-
-#endif /* GNC_PATH_H */

Deleted: gnucash/trunk/src/engine/gncla-dir.h.in
===================================================================
--- gnucash/trunk/src/engine/gncla-dir.h.in	2010-03-04 10:31:41 UTC (rev 18810)
+++ gnucash/trunk/src/engine/gncla-dir.h.in	2010-03-04 16:32:54 UTC (rev 18811)
@@ -1,32 +0,0 @@
-/***************************************************************************
- *            gncla-dir.h
- *
- *  Mon Dec 20 20:27:48 2004
- *  Copyright  2004  Neil Williams
- *  linux at codehelp.co.uk
- ****************************************************************************/
-
-/*
- *  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, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- *  02110-1301, USA.
- */
-
-#define PREFIX "@-prefix-@"
-#define DATADIR "@-datadir-@"
-#define SYSCONFDIR "@-sysconfdir-@"
-
-#define LIBDIR "@-libdir-@"
-
-#define LOCALE_DATADIRNAME "@-DATADIRNAME-@"



More information about the gnucash-changes mailing list