From 7dad2df6a845f32cc526c3afa4d55557e9d25d9c Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 16 Feb 2011 14:23:29 +0200 Subject: [PATCH] Moved initialization of mc_global.share_data_dir and mc_global.sysconf_dir to library Signed-off-by: Slava Zanko --- lib/mcconfig/Makefile.am | 5 +++-- lib/mcconfig/paths.c | 16 ++++++++++++++++ src/Makefile.am | 5 +---- src/main.c | 36 +++++++----------------------------- src/vfs/sfs/sfs.c | 2 +- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/lib/mcconfig/Makefile.am b/lib/mcconfig/Makefile.am index 5605a076f..296047fd2 100644 --- a/lib/mcconfig/Makefile.am +++ b/lib/mcconfig/Makefile.am @@ -9,5 +9,6 @@ libmcconfig_la_SOURCES = \ libmcconfig_la_CFLAGS = -I$(top_srcdir) \ $(GLIB_CFLAGS) \ - -DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\" - + -DDATADIR=\""$(pkgdatadir)/"\" \ + -DLOCALEDIR=\""$(localedir)"\" \ + -DSYSCONFDIR=\""$(sysconfdir)/@PACKAGE@/"\" diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c index abcf9decc..3fdd3c57e 100644 --- a/lib/mcconfig/paths.c +++ b/lib/mcconfig/paths.c @@ -206,6 +206,8 @@ mc_config_copy (const char *old_name, const char *new_name, GError ** error) void mc_config_init_config_paths (GError ** error) { + const char *mc_datadir; + char *u_config_dir = (char *) g_get_user_config_dir (); char *u_data_dir = (char *) g_get_user_data_dir (); char *u_cache_dir = (char *) g_get_user_cache_dir (); @@ -230,6 +232,17 @@ mc_config_init_config_paths (GError ** error) g_free (u_data_dir); g_free (u_cache_dir); g_free (u_config_dir); + + /* This is the directory, where MC was installed, on Unix this is DATADIR */ + /* and can be overriden by the MC_DATADIR environment variable */ + mc_datadir = g_getenv ("MC_DATADIR"); + if (mc_datadir != NULL) + mc_global.sysconfig_dir = g_strdup (mc_datadir); + else + mc_global.sysconfig_dir = g_strdup (SYSCONFDIR); + + mc_global.share_data_dir = g_strdup (DATADIR); + xdg_vars_initialized = TRUE; } @@ -245,6 +258,9 @@ mc_config_deinit_config_paths (void) g_free (xdg_cache); g_free (xdg_data); + g_free (mc_global.share_data_dir); + g_free (mc_global.sysconfig_dir); + xdg_vars_initialized = FALSE; } diff --git a/src/Makefile.am b/src/Makefile.am index 2e36f2eac..bf36f7d14 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,10 +8,7 @@ if USE_DIFF SUBDIRS += diffviewer endif -AM_CPPFLAGS = -DDATADIR=\""$(pkgdatadir)/"\" \ - -DLOCALEDIR=\""$(localedir)"\" \ - -DSYSCONFDIR=\""$(sysconfdir)/@PACKAGE@/"\" - +AM_CPPFLAGS = -DLOCALEDIR=\""$(localedir)"\" if CONS_SAVER SUBDIRS += consaver diff --git a/src/main.c b/src/main.c index a69607e28..ae53f5e78 100644 --- a/src/main.c +++ b/src/main.c @@ -156,7 +156,6 @@ static void OS_Setup (void) { const char *shell_env = getenv ("SHELL"); - const char *mc_libdir; if ((shell_env == NULL) || (shell_env[0] == '\0')) { @@ -173,21 +172,6 @@ OS_Setup (void) g_free (shell); shell = g_strdup ("/bin/sh"); } - - /* This is the directory, where MC was installed, on Unix this is DATADIR */ - /* and can be overriden by the MC_DATADIR environment variable */ - mc_libdir = getenv ("MC_DATADIR"); - if (mc_libdir != NULL) - { - mc_global.sysconfig_dir = g_strdup (mc_libdir); - mc_global.share_data_dir = g_strdup (SYSCONFDIR); - } - else - { - mc_global.sysconfig_dir = g_strdup (SYSCONFDIR); - mc_global.share_data_dir = g_strdup (DATADIR); - } - } /* --------------------------------------------------------------------------------------------- */ @@ -408,6 +392,13 @@ main (int argc, char *argv[]) str_init_strings (NULL); + /* Initialize and create home directories */ + /* do it after the screen library initialization to show the error message */ + mc_config_init_config_paths (&error); + + if (error == NULL && mc_config_deprecated_dir_present ()) + mc_config_migrate_from_old_place (&error); + vfs_init (); vfs_plugins_init (); vfs_setup_work_dir (); @@ -437,17 +428,6 @@ main (int argc, char *argv[]) /* We need this, since ncurses endwin () doesn't restore the signals */ save_stop_handler (); - /* Initialize and create home directories */ - /* do it after the screen library initialization to show the error message */ - mc_config_init_config_paths (&error); - if (error == NULL) - { - if (mc_config_deprecated_dir_present ()) - { - mc_config_migrate_from_old_place (&error); - } - } - /* Must be done before init_subshell, to set up the terminal size: */ /* FIXME: Should be removed and LINES and COLS computed on subshell */ tty_init (mc_global.args.slow_terminal, mc_global.args.ugly_line_drawing); @@ -563,8 +543,6 @@ main (int argc, char *argv[]) } g_free (last_wd_string); - g_free (mc_global.share_data_dir); - g_free (mc_global.sysconfig_dir); g_free (shell); done_key (); diff --git a/src/vfs/sfs/sfs.c b/src/vfs/sfs/sfs.c index c32a22812..401fbfef9 100644 --- a/src/vfs/sfs/sfs.c +++ b/src/vfs/sfs/sfs.c @@ -421,7 +421,7 @@ sfs_init (struct vfs_class *me) if (cfg == NULL) { - fprintf (stderr, _("Warning: file %s not found\n"), mc_sfsini); + fprintf (stderr, _("%s: Warning: file %s not found\n"), "sfs_init()", mc_sfsini); g_free (mc_sfsini); return 0; }