Browse Source

Moved initialization of mc_global.share_data_dir and mc_global.sysconf_dir to library

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Slava Zanko 14 years ago
parent
commit
7dad2df6a8
5 changed files with 28 additions and 36 deletions
  1. 3 2
      lib/mcconfig/Makefile.am
  2. 16 0
      lib/mcconfig/paths.c
  3. 1 4
      src/Makefile.am
  4. 7 29
      src/main.c
  5. 1 1
      src/vfs/sfs/sfs.c

+ 3 - 2
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@/"\"

+ 16 - 0
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;
 }
 

+ 1 - 4
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

+ 7 - 29
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 ();

+ 1 - 1
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;
     }