add_row (table, N_("Version"), version);
add_row (table, N_("Host System"), host_system);
add_row (table, N_("Build System"), build_system);
- add_row (table, N_("Locale Directory"), relocate (locale_dir));
+
+ char *allocated;
+ add_row (table, N_("Locale Directory"), relocate2 (locale_dir, &allocated));
+ free (allocated);
+
add_row (table, N_("Compiler Version"),
#ifdef __VERSION__
__VERSION__
if (home != NULL)
string_array_append_nocopy (&the_include_path,
xasprintf ("%s/.pspp", home));
- string_array_append (&the_include_path, relocate (PKGDATADIR));
+ string_array_append_nocopy (&the_include_path, relocate_clone (PKGDATADIR));
string_array_clone (&default_include_path, &the_include_path);
}
const char *
prepare_diagnostic_information (void)
{
+ char *allocated;
+
diagnostic_information_bytes += append_message (diagnostic_information, diagnostic_information_bytes, "version: %s\n", version);
diagnostic_information_bytes += append_message (diagnostic_information, diagnostic_information_bytes, "host_system: %s\n", host_system);
diagnostic_information_bytes += append_message (diagnostic_information, diagnostic_information_bytes, "build_system: %s\n", build_system);
- diagnostic_information_bytes += append_message (diagnostic_information, diagnostic_information_bytes, "locale_dir: %s\n", relocate (locale_dir));
+ diagnostic_information_bytes += append_message (diagnostic_information, diagnostic_information_bytes, "locale_dir: %s\n", relocate2 (locale_dir, &allocated));
diagnostic_information_bytes += append_message (diagnostic_information, diagnostic_information_bytes, "compiler version: %s\n",
#ifdef __VERSION__
__VERSION__
#endif
);
+ free (allocated);
+
return diagnostic_information;
}
}
}
+/* Returns a relocated version of S as a malloc()'d string that the caller must
+ eventually free(). */
+char *
+relocate_clone (const char *s)
+{
+ char *r = CONST_CAST (char *, relocate (s));
+ return r != s ? r : xstrdup (s);
+}
+/* Formats FORMAT in a printf()-like manner and returns a relocated version of
+ it. The caller must eventually free() the returned string. */
+char * PRINTF_FORMAT (1, 2) MALLOC_LIKE
+relocate_format (const char *format, ...)
+{
+ va_list args;
+ va_start (args, format);
+ char *s = xvasprintf (format, args);
+ va_end (args);
+
+ char *r = CONST_CAST (char *, relocate (s));
+ if (r != s)
+ free (s);
+ return r;
+}
\f
/* Operations on uint8_t "strings" */
/* Other */
/* calls relocate from gnulib on ST */
void ds_relocate (struct string *st);
-
+char *relocate_clone (const char *);
+char *relocate_format (const char *, ...)
+ PRINTF_FORMAT (1, 2) MALLOC_LIKE;
void u8_buf_copy_rpad (uint8_t *dst, size_t dst_size,
const uint8_t *src, size_t src_size,
#include "builder-wrapper.h"
+#include "libpspp/str.h"
-GtkBuilder *
+
+static GtkBuilder *
builder_new_real (const gchar *name)
{
GtkBuilder *builder = gtk_builder_new ();
return builder;
}
+GtkBuilder *
+builder_new (const gchar *name)
+{
+ char *full_name = relocate_format ("%s/%s", PKGDATADIR, name);
+ GtkBuilder *builder = builder_new_real (full_name);
+ free (full_name);
+
+ return builder;
+}
+
GObject *
get_object_assert (GtkBuilder *builder, const gchar *name, GType type)
{
#include "relocatable.h"
#include "gl/configmake.h"
-GtkBuilder *builder_new_real (const gchar *name);
-
-#define builder_new(NAME) (builder_new_real (relocate (PKGDATADIR "/" NAME)))
+GtkBuilder *builder_new (const gchar *name);
GObject *get_object_assert (GtkBuilder *builder, const gchar *name, GType type);
GtkWidget * get_widget_assert (GtkBuilder *builder, const gchar *name);
online_help (const char *page)
{
GError *htmlerr = NULL;
- gchar *htmlfilename = NULL;
- gchar *htmlfullname = NULL;
gchar *htmluri = NULL;
+ char *htmlfilename;
if (page == NULL)
- {
- htmlfilename = g_strdup ("index.html");
- }
+ htmlfilename = xstrdup ("index.html");
else
{
gchar **tokens = NULL;
tokens = g_strsplit (page, "#", maxtokens);
for (idx = 0; idx < maxtokens && tokens[idx]; idx++)
;
- htmlfilename = g_strdup_printf ("%s.html", tokens[idx-1]);
+ htmlfilename = xasprintf ("%s.html", tokens[idx-1]);
g_strfreev (tokens);
}
/* Hint: pspp.html is a directory...*/
- htmlfullname = g_strdup_printf ("%s/%s", relocate (DOCDIR "/pspp.html"),
- htmlfilename);
- if (g_file_test (relocate (DOCDIR "/pspp.html"), G_FILE_TEST_IS_DIR))
+ char *htmldir = relocate_clone (DOCDIR "/pspp.html");
+ char *htmlfullname = xasprintf ("%s/%s", htmldir, htmlfilename);
+ if (g_file_test (htmldir, G_FILE_TEST_IS_DIR))
{
GError *urierr = NULL;
htmluri = g_filename_to_uri (htmlfullname,NULL, &urierr);
else
htmluri = g_strdup_printf (PACKAGE_URL "manual/html_node/%s",
htmlfilename);
- g_free (htmlfullname);
- g_free (htmlfilename);
+ free (htmlfullname);
+ free (htmldir);
+ free (htmlfilename);
#ifdef _WIN32
bool ok = open_windows_help (htmluri, &htmlerr);
{
GtkWidget *sp = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- const gchar *filename = PKGDATADIR "/splash.png";
- const char *relocated_filename = relocate (filename);
- GtkWidget *l = gtk_image_new_from_file (relocated_filename);
- if (filename != relocated_filename)
- free (CONST_CAST (char *, relocated_filename));
+ char *splash = relocate_clone (PKGDATADIR"/splash.png");
+ GtkWidget *l = gtk_image_new_from_file (splash);
+ free (splash);
gtk_container_add (GTK_CONTAINER (sp), l);
gtk_window_set_type_hint (GTK_WINDOW (sp),
gchar **new_paths = g_strdupv ((gchar **)existing_paths);
int n = g_strv_length ((gchar **) existing_paths);
+ char *pkg_data_dir = relocate_clone (PKGDATADIR);
new_paths = g_realloc (new_paths, (n + 2) * sizeof (*new_paths));
- new_paths[n] = g_strdup (relocate (PKGDATADIR));
+ new_paths[n] = g_strdup (pkg_data_dir);
new_paths[n+1] = NULL;
+ free (pkg_data_dir);
lm = gtk_source_language_manager_new ();
gtk_source_language_manager_set_search_path (lm, new_paths);
{
GtkWidget *dialog = psppire_window_file_chooser_dialog (de);
- gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), relocate (examples_dir), NULL);
+ char *dir = relocate_clone (examples_dir);
+ gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), dir, NULL);
+ free (dir);
switch (gtk_dialog_run (GTK_DIALOG (dialog)))
{