Commit 2b2caeca authored by Stepan Kasal's avatar Stepan Kasal

gnm_sys_lib_dir() and such now just return the string;

they don't allocate any memory.
parent dce94bf0
2005-04-20 Stepan Kasal <kasal@ucw.cz>
gnm_sys_lib_dir() and such now just return the string;
they don't take any parameter and don't allocate anything.
* src/libgnumeric.h (gnumeric_lib_dir, gnumeric_data_dir):
Move to gutils.h; #include "gutils.h".
(gnumeric_icon_dir, gnumeric_locale_dir): Move to gutils.c
and make static.
* src/libgnumeric.c: Likewise.
(gnm_pre_parse_init): Call gutils_init instead of doing it.
(gnm_shutdown): Call gutils_shutdown instead of doing it.
* gutils.h:
* gutils.c (gutils_init, gutils_shutdown): New functions.
(gnumeric_usr_dir): New static variable, set up in gutils_init.
(gnm_sys_lib_dir, gnm_sys_data_dir, gnm_usr_dir): Just return
the static string; all callers fixed.
(gnm_sys_glade_dir, gnm_sys_plugin_dir, gnm_usr_plugin_dir):
Nuked; callers fixed to build the string themselves.
(gnm_icon_dir, gnm_locale_dir): New wrappers; callers fixed.
(PLUGIN_SUFFIX): Renamed to ...
(PLUGIN_SUBDIR): ..., and moved to .h.
* src/gui-util.c (gnumeric_icondir): This function was removed;
callers fixed to use gnm_icon_dir.
* src/sheet-object-image.c: Include goffice/utils/go-glib-extras.h
2005-04-20 Ivan, Wong Yat Cheung <email@ivanwong.info>
* src/wbc-gtk.c (wbc_gtk_init_font_name): Set
......
2005-04-20 Stepan Kasal <kasal@ucw.cz>
gnm_sys_lib_dir() and such now just return the string;
they don't take any parameter and don't allocate anything.
* src/libgnumeric.h (gnumeric_lib_dir, gnumeric_data_dir):
Move to gutils.h; #include "gutils.h".
(gnumeric_icon_dir, gnumeric_locale_dir): Move to gutils.c
and make static.
* src/libgnumeric.c: Likewise.
(gnm_pre_parse_init): Call gutils_init instead of doing it.
(gnm_shutdown): Call gutils_shutdown instead of doing it.
* gutils.h:
* gutils.c (gutils_init, gutils_shutdown): New functions.
(gnumeric_usr_dir): New static variable, set up in gutils_init.
(gnm_sys_lib_dir, gnm_sys_data_dir, gnm_usr_dir): Just return
the static string; all callers fixed.
(gnm_sys_glade_dir, gnm_sys_plugin_dir, gnm_usr_plugin_dir):
Nuked; callers fixed to build the string themselves.
(gnm_icon_dir, gnm_locale_dir): New wrappers; callers fixed.
(PLUGIN_SUFFIX): Renamed to ...
(PLUGIN_SUBDIR): ..., and moved to .h.
* src/gui-util.c (gnumeric_icondir): This function was removed;
callers fixed to use gnm_icon_dir.
* src/sheet-object-image.c: Include goffice/utils/go-glib-extras.h
2005-04-20 Ivan, Wong Yat Cheung <email@ivanwong.info>
* src/wbc-gtk.c (wbc_gtk_init_font_name): Set
......
......@@ -284,7 +284,7 @@ dialog_about (WorkbookControlGUI *wbcg)
GOG_STYLED_OBJECT (state->graph)->style, 70.);
#if 0
gog_style_set_fill_image_filename (GOG_STYLED_OBJECT (state->graph)->style,
gnumeric_icondir ("gnumeric-about.png"));
g_build_filename (gnm_icon_dir (), "gnumeric-about.png", NULL));
#endif
/* A bar plot of the current contributors activities */
......
......@@ -239,8 +239,9 @@ static void
pm_gui_load_directory_page (PluginManagerGUI *pm_gui)
{
GtkTreeIter iter;
char * sys_plugins = gnm_sys_plugin_dir ();
char * usr_plugins = gnm_usr_plugin_dir ();
char * sys_plugins = g_build_filename (gnm_sys_lib_dir (), PLUGIN_SUBDIR, NULL);
char * usr_plugins = (gnm_usr_dir () == NULL ? NULL :
g_build_filename (gnm_usr_dir (), PLUGIN_SUBDIR, NULL));
char * go_plugins = go_plugins_get_plugin_dir ();
GSList *plugin_dirs;
gchar const *plugin_path_env;
......
......@@ -649,7 +649,9 @@ gnm_plugins_init (GOCmdContext *context)
{
char const *env_var;
GSList *dir_list = go_slist_create (
gnm_sys_plugin_dir (), gnm_usr_plugin_dir (),
g_build_filename (gnm_sys_lib_dir (), PLUGIN_SUBDIR, NULL),
(gnm_usr_dir () == NULL ? NULL :
g_build_filename (gnm_usr_dir (), PLUGIN_SUBDIR, NULL)),
NULL);
dir_list = g_slist_concat (dir_list,
go_string_slist_copy (gnm_app_prefs->plugin_extra_dirs));
......
......@@ -1357,16 +1357,20 @@ gnm_conf_init_extras (void)
node = go_conf_get_node (root, AUTOFORMAT_GCONF_DIR);
prefs.autoformat.extra_dirs = go_conf_load_str_list (node, AUTOFORMAT_GCONF_EXTRA_DIRS);
tmp = go_conf_load_string (node, AUTOFORMAT_GCONF_SYS_DIR);
if (tmp == NULL)
tmp = g_strdup ("autoformat-templates");
prefs.autoformat.sys_dir = gnm_sys_data_dir (tmp);
g_free (tmp);
tmp = go_conf_load_string (node, AUTOFORMAT_GCONF_USR_DIR);
if (tmp == NULL)
tmp = g_strdup ("autoformat-templates");
prefs.autoformat.usr_dir = gnm_usr_dir (tmp);
prefs.autoformat.sys_dir = g_build_filename (gnm_sys_data_dir (), tmp, NULL);
g_free (tmp);
if (gnm_usr_dir () != NULL) {
tmp = go_conf_load_string (node, AUTOFORMAT_GCONF_USR_DIR);
if (tmp == NULL)
tmp = g_strdup ("autoformat-templates");
prefs.autoformat.usr_dir = g_build_filename (gnm_usr_dir (), tmp, NULL);
g_free (tmp);
}
go_conf_free_node (node);
prefs.xml_compression_level = go_conf_load_int (
......
......@@ -228,7 +228,7 @@ gui_file_open (WorkbookControlGUI *wbcg, char const *default_format)
/* Add Templates bookmark */
{
char *templates = gnm_sys_data_dir ("templates");
char *templates = g_build_filename (gnm_sys_data_dir (), "templates", NULL);
gtk_file_chooser_add_shortcut_folder (fsel, templates, NULL);
g_free (templates);
}
......
......@@ -433,12 +433,10 @@ gnm_glade_xml_new (GOCmdContext *cc, char const *gladefile,
g_return_val_if_fail (gladefile != NULL, NULL);
if (!g_path_is_absolute (gladefile)) {
char *d = gnm_sys_glade_dir ();
f = g_build_filename (d, gladefile, NULL);
g_free (d);
} else
if (g_path_is_absolute (gladefile))
f = g_strdup (gladefile);
else
f = g_build_filename (gnm_sys_data_dir (), "glade", gladefile, NULL);
gui = glade_xml_new (f, root, domain);
if (gui == NULL && cc != NULL) {
......@@ -569,7 +567,7 @@ go_combo_color_get_style_color (GtkWidget *go_combo_color)
void
gnumeric_init_help_button (GtkWidget *w, char const *link)
{
go_gtk_help_button_init (w, gnm_sys_data_dir (NULL), "gnumeric", link);
go_gtk_help_button_init (w, gnm_sys_data_dir (), "gnumeric", link);
}
char *
......@@ -724,16 +722,10 @@ int_to_entry (GtkEntry *entry, gint the_int)
}
}
char *
gnumeric_icondir (char const *filename)
{
return g_build_filename (gnumeric_icon_dir, filename, NULL);
}
GtkWidget *
gnumeric_load_image (char const *filename)
{
char *path = gnumeric_icondir (filename);
char *path = g_build_filename (gnm_icon_dir (), filename, NULL);
GtkWidget *image = gtk_image_new_from_file (path);
g_free (path);
......@@ -750,7 +742,7 @@ gnumeric_load_image (char const *filename)
GdkPixbuf *
gnumeric_load_pixbuf (char const *filename)
{
char *path = gnumeric_icondir (filename);
char *path = g_build_filename (gnm_icon_dir (), filename, NULL);
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (path, NULL);
g_free (path);
return pixbuf;
......
......@@ -93,7 +93,6 @@ void int_to_entry (GtkEntry *entry, gint the_int);
GtkWidget *gnumeric_load_image (char const *name);
GdkPixbuf *gnumeric_load_pixbuf (char const *name);
char *gnumeric_icondir (char const *subdir);
GdkPixbuf *gnm_pixbuf_tile (GdkPixbuf const *src, int w, int h);
......
......@@ -11,11 +11,11 @@
#include <glib/gi18n.h>
#include "gnumeric.h"
#include "gutils.h"
#include "gnumeric-paths.h"
#include "sheet.h"
#include "ranges.h"
#include "mathfunc.h"
#include "libgnumeric.h"
#include <stdlib.h>
#include <math.h>
......@@ -28,52 +28,83 @@
#include <errno.h>
#include <gsf/gsf-impl-utils.h>
char *
gnm_sys_data_dir (char const *subdir)
#ifndef G_OS_WIN32
const char *gnumeric_lib_dir = GNUMERIC_LIBDIR;
const char *gnumeric_data_dir = GNUMERIC_DATADIR;
static const char gnumeric_icon_dir[] = GNUMERIC_ICONDIR;
static const char gnumeric_locale_dir[] = GNUMERIC_LOCALEDIR;
#else
const char *gnumeric_lib_dir;
const char *gnumeric_data_dir;
static const char *priv_lib_dir;
static const char *priv_data_dir;
static const char *gnumeric_icon_dir;
static const char *gnumeric_locale_dir;
#endif
static const char *gnumeric_usr_dir;
void
gutils_init (void)
{
if (subdir == NULL)
return (char *)gnumeric_data_dir;
return g_build_filename (gnumeric_data_dir, subdir, NULL);
char const *home_dir;
#ifdef G_OS_WIN32
gchar *dir = g_win32_get_package_installation_directory (NULL, NULL);
priv_lib_dir = gnumeric_lib_dir = g_build_filename (dir,
"lib", "gnumeric", GNUMERIC_VERSION, NULL);
priv_data_dir = gnumeric_data_dir = g_build_filename (dir,
"share", "gnumeric", GNUMERIC_VERSION, NULL);
gnumeric_icon_dir = g_build_filename (dir,
"share", "pixmaps", "gnumeric", NULL);
gnumeric_locale_dir = g_build_filename (dir,
"share", "locale", NULL);
g_free (dir);
#endif
home_dir = g_get_home_dir ();
gnumeric_usr_dir = (home_dir == NULL ? NULL :
g_build_filename (home_dir, ".gnumeric", GNUMERIC_VERSION, NULL));
}
char *
gnm_sys_lib_dir (char const *subdir)
void
gutils_shutdown (void)
{
return g_build_filename (gnumeric_lib_dir, subdir, NULL);
#ifdef G_OS_WIN32
g_free (priv_lib_dir);
g_free (priv_data_dir);
g_free (gnumeric_icon_dir);
g_free (gnumeric_locale_dir);
g_free (gnumeric_usr_dir);
#endif
}
#define GLADE_SUFFIX "glade"
#define PLUGIN_SUFFIX "plugins"
char *
gnm_sys_glade_dir (void)
char const *
gnm_sys_lib_dir (void)
{
return gnm_sys_data_dir (GLADE_SUFFIX);
return gnumeric_lib_dir;
}
char *
gnm_sys_plugin_dir (void)
char const *
gnm_sys_data_dir (void)
{
return gnm_sys_lib_dir (PLUGIN_SUFFIX);
return gnumeric_data_dir;
}
char *
gnm_usr_dir (char const *subdir)
char const *
gnm_icon_dir (void)
{
char const *home_dir = g_get_home_dir ();
if (!home_dir)
return NULL;
return gnumeric_icon_dir;
}
return g_build_filename (home_dir, ".gnumeric",
GNUMERIC_VERSION, subdir,
NULL);
char const *
gnm_locale_dir (void)
{
return gnumeric_locale_dir;
}
char *
gnm_usr_plugin_dir (void)
char const *
gnm_usr_dir (void)
{
return gnm_usr_dir (PLUGIN_SUFFIX);
return gnumeric_usr_dir;
}
int
......
......@@ -3,13 +3,23 @@
#include <goffice/utils/regutf8.h>
void gutils_init (void);
void gutils_shutdown (void);
/* System and user paths */
char *gnm_sys_lib_dir (char const *subdir);
char *gnm_sys_data_dir (char const *subdir);
char *gnm_sys_glade_dir (void);
char *gnm_sys_plugin_dir (void);
char *gnm_usr_dir (char const *subdir);
char *gnm_usr_plugin_dir (void);
char const *gnm_sys_lib_dir (void);
char const *gnm_sys_data_dir (void);
char const *gnm_icon_dir (void);
char const *gnm_locale_dir (void);
char const *gnm_usr_dir (void);
#define PLUGIN_SUBDIR "plugins"
/* The right way to access these is via gnm_sys_lib_dir() and
gnm_sys_data_dir(), but option processing needs write access.
*/
extern const char *gnumeric_lib_dir;
extern const char *gnumeric_data_dir;
int gnumeric_regcomp_XL (go_regex_t *preg, char const *pattern, int cflags);
......
......@@ -42,7 +42,6 @@
#include "gnm-plugin.h"
#include "mathfunc.h"
#include "hlink.h"
#include "gnumeric-paths.h"
#include "gnm-plugin.h"
#include <goffice/goffice.h>
#include <goffice/app/go-plugin-service.h>
......@@ -62,18 +61,6 @@ int print_debugging = 0;
gboolean initial_workbook_open_complete = FALSE;
char *x_geometry;
#ifndef G_OS_WIN32
const char *gnumeric_lib_dir = GNUMERIC_LIBDIR;
const char *gnumeric_data_dir = GNUMERIC_DATADIR;
const char *gnumeric_icon_dir = GNUMERIC_ICONDIR;
const char *gnumeric_locale_dir = GNUMERIC_LOCALEDIR;
#else
char *gnumeric_lib_dir;
char *gnumeric_data_dir;
char *gnumeric_icon_dir;
char *gnumeric_locale_dir;
#endif
/**
* gnm_pre_parse_init :
* @gnumeric_binary : argv[0]
......@@ -88,24 +75,10 @@ gnm_pre_parse_init (char const* gnumeric_binary)
/* Make stdout line buffered - we only use it for debug info */
setvbuf (stdout, NULL, _IOLBF, 0);
#ifdef G_OS_WIN32
{
gchar *dir;
dir = g_win32_get_package_installation_directory (NULL, NULL);
gnumeric_data_dir = g_build_filename (dir,
"share", "gnumeric", GNUMERIC_VERSION, NULL);
gnumeric_icon_dir = g_build_filename (dir,
"share", "pixmaps", "gnumeric", NULL);
gnumeric_locale_dir = g_build_filename (dir,
"share", "locale", NULL);
gnumeric_lib_dir = g_build_filename (dir,
"lib", "gnumeric", GNUMERIC_VERSION, NULL);
g_free (dir);
}
#endif
gutils_init ();
bindtextdomain (GETTEXT_PACKAGE, gnumeric_locale_dir);
bindtextdomain (GETTEXT_PACKAGE "-functions", gnumeric_locale_dir);
bindtextdomain (GETTEXT_PACKAGE, gnm_locale_dir ());
bindtextdomain (GETTEXT_PACKAGE "-functions", gnm_locale_dir ());
textdomain (GETTEXT_PACKAGE);
/* Force all of the locale segments to update from the environment.
......@@ -229,10 +202,5 @@ gnm_shutdown (void)
libgoffice_shutdown ();
plugin_services_shutdown ();
g_object_unref (gnm_app_get_app ());
#ifdef G_OS_WIN32
g_free (gnumeric_lib_dir);
g_free (gnumeric_data_dir);
g_free (gnumeric_icon_dir);
g_free (gnumeric_locale_dir);
#endif
gutils_shutdown ();
}
#ifndef GNUMERIC_LIBGNUMERIC_H
#define GNUMERIC_LIBGNUMERIC_H
#include "gutils.h"
#ifdef WIN32
#define POPT_STATIC
#endif
......@@ -14,18 +16,6 @@ extern int print_debugging;
extern gboolean initial_workbook_open_complete;
extern char *x_geometry;
#ifndef G_OS_WIN32
extern const char *gnumeric_lib_dir;
extern const char *gnumeric_data_dir;
extern const char *gnumeric_icon_dir;
extern const char *gnumeric_locale_dir;
#else
extern char *gnumeric_lib_dir;
extern char *gnumeric_data_dir;
extern char *gnumeric_icon_dir;
extern char *gnumeric_locale_dir;
#endif
void gnm_pre_parse_init (char const* gnumeric_binary);
void gnm_common_init (gboolean fast);
int gnm_dump_func_defs (char const* filename,
......
......@@ -170,8 +170,8 @@ gnumeric_arg_parse (int argc, char const *argv [])
argc, (char **)argv,
GNOME_PARAM_APP_PREFIX, GNUMERIC_PREFIX,
GNOME_PARAM_APP_SYSCONFDIR, GNUMERIC_SYSCONFDIR,
GNOME_PARAM_APP_DATADIR, gnumeric_data_dir,
GNOME_PARAM_APP_LIBDIR, gnumeric_lib_dir,
GNOME_PARAM_APP_DATADIR, gnm_sys_data_dir (),
GNOME_PARAM_APP_LIBDIR, gnm_sys_lib_dir (),
GNOME_PARAM_POPT_TABLE, gnumeric_popt_options,
NULL);
......@@ -298,7 +298,7 @@ main (int argc, char const *argv [])
if (gnumeric_show_version) {
g_print (_("gnumeric version '%s'\ndatadir := '%s'\nlibdir := '%s'\n"),
GNUMERIC_VERSION, gnumeric_data_dir, gnumeric_lib_dir);
GNUMERIC_VERSION, gnm_sys_data_dir (), gnm_sys_lib_dir ());
return 0;
}
......
......@@ -9,8 +9,8 @@
#include <gnumeric-config.h>
#include <glib.h>
#include <gnumeric.h>
#include <libgnumeric.h>
#include "gnumeric.h"
#include "libgnumeric.h"
#include "gnumeric-paths.h"
#include "bonobo-io.h"
#include <bonobo/bonobo-ui-main.h>
......
......@@ -38,6 +38,7 @@
#include "number-match.h"
#include "dialogs.h"
#include "style-color.h"
#include "gutils.h"
#include <goffice/utils/regutf8.h>
#include <goffice/cut-n-paste/foocanvas/foo-canvas-widget.h>
......
......@@ -17,6 +17,7 @@
#include "gui-file.h"
#include "application.h"
#include <goffice/utils/go-glib-extras.h>
#include <goffice/utils/go-libxml-extras.h>
#include <gsf/gsf-impl-utils.h>
#include <gsf/gsf-output-stdio.h>
......
......@@ -15,13 +15,13 @@
#include "libgnumeric.h"
#include "gnumeric-paths.h"
#include "gnm-plugin.h"
#include "command-context-stderr.h"
#include "command-context.h"
#include <goffice/app/io-context.h>
#include "command-context-stderr.h"
#include "workbook-view.h"
#include <goffice/app/file.h>
#include <goffice/utils/go-file.h>
#include <goffice/app/io-context.h>
#include <goffice/app/go-cmd-context.h>
#include <goffice/utils/go-file.h>
#include <gsf/gsf-utils.h>
#include <string.h>
......@@ -195,7 +195,7 @@ main (int argc, char const *argv [])
if (ssconvert_show_version) {
printf (_("ssconvert version '%s'\ndatadir := '%s'\nlibdir := '%s'\n"),
GNUMERIC_VERSION, gnumeric_data_dir, gnumeric_lib_dir);
GNUMERIC_VERSION, gnm_sys_data_dir (), gnm_sys_lib_dir ());
poptFreeContext (ctx);
return 0;
}
......
......@@ -194,7 +194,7 @@ main (int argc, char const *argv [])
if (ssindex_show_version) {
printf (_("ssindex version '%s'\ndatadir := '%s'\nlibdir := '%s'\n"),
GNUMERIC_VERSION, gnumeric_data_dir, gnumeric_lib_dir);
GNUMERIC_VERSION, gnm_sys_data_dir (), gnm_sys_lib_dir ());
poptFreeContext (ctx);
return 0;
} else if (!ssindex_run_indexer && !ssindex_list_mime_types) {
......
......@@ -1413,8 +1413,7 @@ wbc_gtk_init (GObject *obj)
gtk_window_add_accel_group (wbcg->toplevel,
gtk_ui_manager_get_accel_group (gtk->ui));
uifile = g_build_filename (gnm_sys_data_dir (NULL),
"GNOME_Gnumeric-gtk.xml", NULL);
uifile = g_build_filename (gnm_sys_data_dir (), "GNOME_Gnumeric-gtk.xml", NULL);
if (!gtk_ui_manager_add_ui_from_file (gtk->ui, uifile, &error)) {
g_message ("building menus failed: %s", error->message);
g_error_free (error);
......
......@@ -856,10 +856,12 @@ static GNM_ACTION_DEF (cb_help_docs)
#warning "handle translations when we generate them"
#ifndef G_OS_WIN32
argv[0] = (char *)"yelp";
argv[1] = gnm_sys_data_dir ("doc/C/gnumeric.xml");
argv[1] = g_build_filename (gnm_sys_data_dir (), "doc", "C",
"gnumeric.xml", NULL);
#else
argv[0] = (char *)"hh";
argv[1] = gnm_sys_data_dir ("doc/C/gnumeric.chm");
argv[1] = g_build_filename (gnm_sys_data_dir (), "doc", "C",
"gnumeric.chm", NULL);
#endif
g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
NULL, NULL, NULL, &error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment