Ticket #1851: Home config directory [xdg-user-dirs]

Instead of hardcoded (via MC_USERCONF_DIR) path mc mc now used
dynamic directories specified by environment variables:
 * XDG_CONFIG_HOME - dir for config files . By default is ~/.config/mc
 * XDG_DATA_HOME - dir for some data, such as user defuned Syntax file, menu etc By default is ~/.local/share/mc
 * XDG_CACHE_HOME - dir for temp files, such as cooledit.clip etc. By default is ~/.cache/mc

This is mainstream standard already adopted by many projects.

Old settings will be migrated at first time from ~/.mc to these dirs.

See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html for more info.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Slava Zanko 2010-12-29 17:12:59 +02:00
parent d21eb43152
commit acbe048486
30 changed files with 560 additions and 131 deletions

View File

@ -202,7 +202,7 @@ mc_fhl_init_from_standard_files (mc_fhl_t * fhl)
gboolean ok;
/* ~/.mc/filehighlight.ini */
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FHL_INI_FILE, (char *) NULL);
name = g_build_filename (mc_config_get_data_path (), MC_FHL_INI_FILE, (char *) NULL);
ok = mc_fhl_read_ini_file (fhl, name);
g_free (name);
if (ok)

View File

@ -16,7 +16,7 @@
/*** typedefs(not structures) and defined constants **********************************************/
#ifndef MC_USERCONF_DIR
#define MC_USERCONF_DIR ".mc"
#define MC_USERCONF_DIR "mc"
#endif
#define TAGS_NAME "TAGS"
@ -62,14 +62,14 @@
#define MC_SKINS_SUBDIR "skins"
/* editor home directory */
#define EDIT_DIR MC_USERCONF_DIR PATH_SEP_STR "cedit"
#define EDIT_DIR "mcedit"
/* file names */
#define EDIT_SYNTAX_FILE EDIT_DIR PATH_SEP_STR "Syntax"
#define EDIT_CLIP_FILE EDIT_DIR PATH_SEP_STR "cooledit.clip"
#define EDIT_MACRO_FILE EDIT_DIR PATH_SEP_STR "cooledit.macros"
#define EDIT_BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block"
#define EDIT_TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp"
#define EDIT_CLIP_FILE EDIT_DIR PATH_SEP_STR "mcedit.clip"
#define EDIT_MACRO_FILE EDIT_DIR PATH_SEP_STR "mcedit.macros"
#define EDIT_BLOCK_FILE EDIT_DIR PATH_SEP_STR "mcedit.block"
#define EDIT_TEMP_FILE EDIT_DIR PATH_SEP_STR "mcedit.temp"
#define EDIT_GLOBAL_MENU "cedit.menu"
#define EDIT_LOCAL_MENU ".cedit.menu"

View File

@ -81,7 +81,7 @@ mc_log (const char *fmt, ...)
if (is_logging_enabled ())
{
va_start (args, fmt);
logfilename = g_strdup_printf ("%s/%s/log", home_dir, MC_USERCONF_DIR);
logfilename = g_build_filename (mc_config_get_cache_path (), "mc.log", NULL);
if (logfilename != NULL)
{
f = fopen (logfilename, "a");

View File

@ -1,14 +1,14 @@
#ifndef MC_CONFIG_H
#define MC_CONFIG_H
/*** typedefs(not structures) and defined constants ********************/
/*** typedefs(not structures) and defined constants **********************************************/
#define CONFIG_APP_SECTION "Midnight-Commander"
#define CONFIG_PANELS_SECTION "Panels"
/*** enums *************************************************************/
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)***************/
/*** structures declarations (and typedefs of structures)*****************************************/
typedef struct mc_config_struct
{
@ -16,12 +16,12 @@ typedef struct mc_config_struct
gchar *ini_path;
} mc_config_t;
/*** global variables defined in .c file *******************************/
/*** global variables defined in .c file *********************************************************/
extern mc_config_t *mc_main_config;
extern mc_config_t *mc_panels_config;
/*** declarations of public functions **********************************/
/*** declarations of public functions ************************************************************/
/* mcconfig/common.c: */
@ -86,4 +86,26 @@ void mc_config_set_int_list (mc_config_t *, const gchar *, const gchar *, int[],
void mc_config_show_dialog (void);
/* mcconfig/paths.c: */
void mc_config_init_config_paths (GError ** error);
void mc_config_deinit_config_paths (void);
gboolean mc_config_deprecated_dir_present (void);
void mc_config_migrate_from_old_place (GError ** error);
const char *mc_config_get_data_path (void);
const char *mc_config_get_cache_path (void);
const char *mc_config_get_path (void);
const char *mc_config_get_home_dir (void);
/*** inline functions ****************************************************************************/
#endif

View File

@ -4,7 +4,8 @@ noinst_LTLIBRARIES = libmcconfig.la
libmcconfig_la_SOURCES = \
common.c \
get.c \
set.c
set.c \
paths.c
libmcconfig_la_CFLAGS = -I$(top_srcdir) \
$(GLIB_CFLAGS) \

369
lib/mcconfig/paths.c Normal file
View File

@ -0,0 +1,369 @@
/*
paths to configuration files
Copyright (C) 2010 The Free Software Foundation, Inc.
Written by:
Slava Zanko <slavazanko@gmail.com>, 2010.
This file is part of the Midnight Commander.
The Midnight Commander 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.
The Midnight Commander 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.
*/
#include <config.h>
#include <stdio.h>
#include <errno.h>
#include "lib/global.h"
#include "lib/mcconfig.h"
#include "lib/fileloc.h"
#include "lib/vfs/mc-vfs/vfs.h"
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
static gboolean xdg_vars_initialized = FALSE;
static char *xdg_config = NULL;
static char *xdg_cache = NULL;
static char *xdg_data = NULL;
static const char *homedir = NULL;
static gboolean config_dir_present = FALSE;
static const struct
{
const char *old_filename;
char **new_basedir;
const char *new_filename;
} mc_config_migrate_rules[] =
{
/* *INDENT-OFF* */
/* config */
{ "ini", &xdg_config, MC_CONFIG_FILE},
{ "filehighlight.ini", &xdg_config, MC_FHL_INI_FILE},
{ "hotlist", &xdg_config, MC_HOTLIST_FILE},
{ "mc.keymap", &xdg_config, GLOBAL_KEYMAP_FILE},
/* data */
{ "skins", &xdg_data, MC_SKINS_SUBDIR},
{ "fish", &xdg_data, FISH_PREFIX},
{ "bindings", &xdg_data, MC_FILEBIND_FILE},
{ "menu", &xdg_data, MC_USERMENU_FILE},
{ "bashrc", &xdg_data, "bashrc"},
{ "inputrc", &xdg_data, "inputrc"},
{ "extfs.d", &xdg_data, MC_EXTFS_DIR},
{ "cedit" PATH_SEP_STR "cooledit.macros", &xdg_data, EDIT_MACRO_FILE},
{ "cedit" PATH_SEP_STR "Syntax", &xdg_data, EDIT_SYNTAX_FILE},
{ "cedit" PATH_SEP_STR "menu", &xdg_data, EDIT_HOME_MENU},
{ "cedit" PATH_SEP_STR "edit.indent.rc", &xdg_data, EDIT_DIR PATH_SEP_STR "edit.indent.rc"},
{ "cedit" PATH_SEP_STR "edit.spell.rc", &xdg_data, EDIT_DIR PATH_SEP_STR "edit.spell.rc"},
/* cache */
{ "history", &xdg_cache, MC_HISTORY_FILE},
{ "panels.ini", &xdg_cache, MC_PANELS_FILE},
{ "log", &xdg_cache, "mc.log"},
{ "filepos", &xdg_cache, MC_FILEPOS_FILE},
{ "Tree", &xdg_cache, MC_TREESTORE_FILE},
{ "cedit" PATH_SEP_STR "cooledit.clip", &xdg_cache, EDIT_CLIP_FILE},
{ "cedit" PATH_SEP_STR "cooledit.temp", &xdg_cache, EDIT_TEMP_FILE},
{ "cedit" PATH_SEP_STR "cooledit.block", &xdg_cache, EDIT_BLOCK_FILE},
{NULL, NULL, NULL}
/* *INDENT-ON* */
};
/*** file scope functions *********************************************************************** */
/* --------------------------------------------------------------------------------------------- */
static void
mc_config_mkdir (const char *directory_name, GError ** error)
{
if ((!g_file_test (directory_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) &&
(g_mkdir_with_parents (directory_name, 0700) != 0))
{
g_propagate_error (error,
g_error_new (MC_ERROR, 0, _("Cannot create %s directory"),
directory_name));
}
}
/* --------------------------------------------------------------------------------------------- */
static char *
mc_config_init_one_config_path (const char *path_base, const char *subdir, GError ** error)
{
char *full_path;
full_path = g_build_filename (path_base, subdir, NULL);
if (g_file_test (full_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
config_dir_present = TRUE;
mc_config_mkdir (full_path, error);
if (error != NULL && *error != NULL)
{
g_free (full_path);
full_path = NULL;
}
return full_path;
}
/* --------------------------------------------------------------------------------------------- */
static char *
mc_config_get_deprecated_path (void)
{
return g_build_filename (mc_config_get_home_dir (), "." MC_USERCONF_DIR, NULL);
}
/* --------------------------------------------------------------------------------------------- */
static void
mc_config_copy (const char *old_name, const char *new_name, GError ** error)
{
if (error != NULL && *error != NULL)
return;
if (g_file_test (old_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
{
char *contents = NULL;
size_t length;
if (g_file_get_contents (old_name, &contents, &length, error))
g_file_set_contents (new_name, contents, length, error);
g_free (contents);
return;
}
if (g_file_test (old_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
{
GDir *dir;
const char *dir_name;
dir = g_dir_open (old_name, 0, error);
if (dir == NULL)
return;
if (!g_mkdir_with_parents (new_name, 0700))
{
g_dir_close (dir);
g_propagate_error (error,
g_error_new (MC_ERROR, 0,
_
("An error occured while migrating user settings: %s"),
g_strerror (errno)));
return;
}
while ((dir_name = g_dir_read_name (dir)) != NULL)
{
char *old_name2, *new_name2;
old_name2 = g_build_filename (old_name, dir_name, NULL);
new_name2 = g_build_filename (new_name, dir_name, NULL);
mc_config_copy (old_name2, new_name2, error);
g_free (new_name2);
g_free (old_name2);
}
}
if (rename (old_name, new_name) != 0)
{
g_propagate_error (error,
g_error_new (MC_ERROR, 0,
_
("An error occured while migrating user settings: %s"),
g_strerror (errno)));
}
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
mc_config_init_config_paths (GError ** error)
{
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 ();
if (xdg_vars_initialized)
return;
u_config_dir = (u_config_dir == NULL)
? g_build_filename (mc_config_get_home_dir (), ".config", NULL) : g_strdup (u_config_dir);
u_cache_dir = (u_cache_dir == NULL)
? g_build_filename (mc_config_get_home_dir (), ".cache", NULL) : g_strdup (u_cache_dir);
u_data_dir = (u_data_dir == NULL)
? g_build_filename (mc_config_get_home_dir (), ".local", "share", NULL)
: g_strdup (u_data_dir);
xdg_config = mc_config_init_one_config_path (u_config_dir, MC_USERCONF_DIR, error);
xdg_cache = mc_config_init_one_config_path (u_cache_dir, MC_USERCONF_DIR, error);
xdg_data = mc_config_init_one_config_path (u_data_dir, MC_USERCONF_DIR, error);
g_free (u_data_dir);
g_free (u_cache_dir);
g_free (u_config_dir);
xdg_vars_initialized = TRUE;
}
/* --------------------------------------------------------------------------------------------- */
void
mc_config_deinit_config_paths (void)
{
if (!xdg_vars_initialized)
return;
g_free (xdg_config);
g_free (xdg_cache);
g_free (xdg_data);
xdg_vars_initialized = FALSE;
}
/* --------------------------------------------------------------------------------------------- */
const char *
mc_config_get_data_path (void)
{
if (!xdg_vars_initialized)
mc_config_init_config_paths (NULL);
return (const char *) xdg_data;
}
/* --------------------------------------------------------------------------------------------- */
const char *
mc_config_get_cache_path (void)
{
if (!xdg_vars_initialized)
mc_config_init_config_paths (NULL);
return (const char *) xdg_cache;
}
/* --------------------------------------------------------------------------------------------- */
const char *
mc_config_get_home_dir (void)
{
if (homedir == NULL)
{
homedir = g_getenv ("HOME");
if (homedir == NULL)
homedir = g_get_home_dir ();
}
return homedir;
}
/* --------------------------------------------------------------------------------------------- */
const char *
mc_config_get_path (void)
{
if (!xdg_vars_initialized)
mc_config_init_config_paths (NULL);
return (const char *) xdg_config;
}
/* --------------------------------------------------------------------------------------------- */
void
mc_config_migrate_from_old_place (GError ** error)
{
char *old_dir, *tmp_dir_name;
size_t rule_index;
old_dir = mc_config_get_deprecated_path ();
tmp_dir_name = mc_config_init_one_config_path (xdg_config, EDIT_DIR, error);
g_free (tmp_dir_name);
tmp_dir_name = mc_config_init_one_config_path (xdg_cache, EDIT_DIR, error);
g_free (tmp_dir_name);
tmp_dir_name = mc_config_init_one_config_path (xdg_data, EDIT_DIR, error);
g_free (tmp_dir_name);
for (rule_index = 0; mc_config_migrate_rules[rule_index].old_filename != NULL; rule_index++)
{
char *old_name, *new_name;
old_name =
g_build_filename (old_dir, mc_config_migrate_rules[rule_index].old_filename, NULL);
if (!g_file_test (old_name, G_FILE_TEST_EXISTS))
{
g_free (old_name);
continue;
}
new_name = g_build_filename (*mc_config_migrate_rules[rule_index].new_basedir,
mc_config_migrate_rules[rule_index].new_filename, NULL);
mc_config_copy (old_name, new_name, error);
g_free (new_name);
g_free (old_name);
}
/*
{
char *old_dir2;
old_dir2 = g_strconcat (old_dir, "~", NULL);
rename (old_dir, old_dir2);
g_free (old_dir2);
}
*/
g_propagate_error (error,
g_error_new (MC_ERROR, 0,
_
("Your old settings were migrated from %s\n"
"to Freedesktop recommended dirs.\n"
"To get more info, please visit\n"
"http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html"),
old_dir));
g_free (old_dir);
}
/* --------------------------------------------------------------------------------------------- */
gboolean
mc_config_deprecated_dir_present (void)
{
char *old_dir = mc_config_get_deprecated_path ();
gboolean is_present = g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR);
g_free (old_dir);
return is_present && !config_dir_present;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -81,8 +81,7 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
gboolean
mc_skin_ini_file_load (mc_skin_t * mc_skin)
{
char *file_name, *user_home_dir;
gboolean ok;
char *file_name;
file_name = g_path_get_basename (mc_skin->name);
if (file_name == NULL)
@ -99,10 +98,7 @@ mc_skin_ini_file_load (mc_skin_t * mc_skin)
g_free (file_name);
/* ~/.mc/skins/ */
user_home_dir = g_build_filename (home_dir, MC_USERCONF_DIR, (char *) NULL);
ok = mc_skin_ini_file_load_search_in_dir (mc_skin, user_home_dir);
g_free (user_home_dir);
if (ok)
if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_config_get_data_path ()))
return TRUE;
/* /etc/mc/skins/ */

View File

@ -50,7 +50,7 @@
#include "src/filemanager/filegui.h"
#include "src/filemanager/file.h" /* copy_file_file() */
#include "src/main.h" /* home_dir, eight_bit_clean */
#include "src/main.h" /* eight_bit_clean */
/*** global variables ****************************************************************************/
@ -392,8 +392,7 @@ void
size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gboolean use_si)
{
/* Avoid taking power for every file. */
static const uintmax_t power10[] =
{
static const uintmax_t power10[] = {
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
};
static const char *const suffix[] = { "", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL };
@ -585,8 +584,8 @@ strip_home_and_password (const char *dir)
size_t len;
static char newdir[MC_MAXPATHLEN];
len = strlen (home_dir);
if (home_dir != NULL && strncmp (dir, home_dir, len) == 0 &&
len = strlen (mc_config_get_home_dir ());
if (mc_config_get_home_dir () != NULL && strncmp (dir, mc_config_get_home_dir (), len) == 0 &&
(dir[len] == PATH_SEP || dir[len] == '\0'))
{
newdir[0] = '~';
@ -1229,7 +1228,7 @@ load_file_position (const char *filename, long *line, long *column, off_t * offs
*offset = 0;
/* open file with positions */
fn = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FILEPOS_FILE, NULL);
fn = g_build_filename (mc_config_get_cache_path (), MC_FILEPOS_FILE, NULL);
f = fopen (fn, "r");
g_free (fn);
if (f == NULL)
@ -1319,7 +1318,7 @@ save_file_position (const char *filename, long line, long column, off_t offset,
filepos_max_saved_entries = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
"filepos_max_saved_entries", 1024);
fn = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FILEPOS_FILE, NULL);
fn = g_build_filename (mc_config_get_cache_path (), MC_FILEPOS_FILE, NULL);
if (fn == NULL)
goto early_error;

View File

@ -48,6 +48,7 @@
#include "lib/global.h"
#include "lib/fileloc.h"
#include "lib/mcconfig.h"
#include "lib/util.h"
#include "lib/widget.h" /* message() */
@ -1630,14 +1631,11 @@ static int
extfs_init (struct vfs_class *me)
{
gboolean d1, d2;
char *dirname;
(void) me;
/* 1st: scan user directory */
dirname = g_build_path (PATH_SEP_STR, home_dir, MC_USERCONF_DIR, (char *) NULL);
d1 = extfs_get_plugins (dirname, TRUE); /* silent about user dir */
g_free (dirname);
d1 = extfs_get_plugins (mc_config_get_data_path (), TRUE); /* silent about user dir */
/* 2nd: scan system dir */
d2 = extfs_get_plugins (LIBEXECDIR, d1);

View File

@ -61,6 +61,7 @@
#include "lib/strescape.h"
#include "lib/unixcompat.h"
#include "lib/fileloc.h"
#include "lib/mcconfig.h"
#include "src/filemanager/layout.h" /* print_vfs_message */
#include "src/execute.h" /* pre_exec, post_exec */
@ -149,7 +150,7 @@ fish_load_script_from_file (const char *hostname, const char *script_name, const
gsize scr_len = 0;
/* 1st: scan user directory */
scr_filename = g_build_path (PATH_SEP_STR, home_dir, MC_USERCONF_DIR, FISH_PREFIX, hostname,
scr_filename = g_build_path (PATH_SEP_STR, mc_config_get_data_path (), FISH_PREFIX, hostname,
script_name, (char *) NULL);
/* silent about user dir */
g_file_get_contents (scr_filename, &scr_content, &scr_len, NULL);

View File

@ -88,6 +88,7 @@ What to do with this?
#include "lib/global.h"
#include "lib/util.h"
#include "lib/mcconfig.h"
#include "lib/tty/tty.h" /* enable/disable interrupt key */
#include "lib/widget.h" /* message() */
@ -1827,7 +1828,7 @@ ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *l
w_buf += n_written;
n_read -= n_written;
}
print_vfs_message ("%s: %" PRIuMAX "/%" PRIuMAX,
print_vfs_message ("%s: %" PRIuMAX "/%" PRIuMAX,
_("ftpfs: storing file"), (uintmax_t) n_stored, (uintmax_t) s.st_size);
}
tty_disable_interrupt_key ();
@ -2388,7 +2389,7 @@ ftpfs_netrc_lookup (const char *host, char **login, char **pass)
}
/* Load current .netrc */
netrcname = g_build_filename (home_dir, ".netrc", (char *) NULL);
netrcname = g_build_filename (mc_config_get_home_dir (), ".netrc", (char *) NULL);
if (!g_file_get_contents (netrcname, &netrc, NULL, NULL))
{
g_free (netrcname);

View File

@ -154,7 +154,7 @@ history_get (const char *input_name)
if ((input_name == NULL) || (*input_name == '\0'))
return NULL;
profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_HISTORY_FILE, NULL);
profile = g_build_filename (mc_config_get_cache_path (), MC_HISTORY_FILE, NULL);
cfg = mc_config_init (profile);
/* get number of keys */
@ -227,7 +227,7 @@ history_put (const char *input_name, GList * h)
if (h == NULL)
return;
profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_HISTORY_FILE, NULL);
profile = g_build_filename (mc_config_get_cache_path (), MC_HISTORY_FILE, NULL);
i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
if (i != -1)

View File

@ -53,7 +53,7 @@
#include "src/main.h" /* home_dir */
#include "src/filemanager/midnight.h" /* current_panel */
#include "src/clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */
#include "src/keybind-defaults.h" /* input_map */
#include "src/keybind-defaults.h" /* input_map */
/*** global variables ****************************************************************************/
@ -91,7 +91,7 @@ save_text_to_clip_file (const char *text)
ssize_t ret;
size_t str_len;
fname = g_build_filename (home_dir, EDIT_CLIP_FILE, NULL);
fname = g_build_filename (mc_config_get_cache_path (), EDIT_CLIP_FILE, NULL);
file = mc_open (fname, O_CREAT | O_WRONLY | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY);
g_free (fname);
@ -115,7 +115,7 @@ load_text_from_clip_file (char **text)
char *fname = NULL;
gboolean first = TRUE;
fname = g_build_filename (home_dir, EDIT_CLIP_FILE, NULL);
fname = g_build_filename (mc_config_get_cache_path (), EDIT_CLIP_FILE, NULL);
f = fopen (fname, "r");
g_free (fname);

View File

@ -31,6 +31,7 @@
#include "lib/global.h"
#include "lib/fileloc.h"
#include "lib/mcconfig.h"
#include "lib/util.h"
#include "main.h"
@ -67,7 +68,7 @@ copy_file_to_ext_clip (void)
if (d == NULL || clipboard_store_path == NULL || clipboard_store_path[0] == '\0')
return FALSE;
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
cmd = g_strconcat (clipboard_store_path, " ", tmp, " 2>/dev/null", (char *) NULL);
if (cmd != NULL)
@ -90,7 +91,7 @@ paste_to_file_from_ext_clip (void)
if (d == NULL || clipboard_paste_path == NULL || clipboard_paste_path[0] == '\0')
return FALSE;
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
cmd = g_strconcat (clipboard_paste_path, " > ", tmp, " 2>/dev/null", (char *) NULL);
if (cmd != NULL)

View File

@ -57,7 +57,7 @@
#endif
#include "src/filemanager/cmd.h" /* view_other_cmd() */
#include "src/filemanager/usermenu.h" /* user_menu_cmd() */
#include "src/filemanager/usermenu.h" /* user_menu_cmd() */
#include "src/main.h" /* source_codepage */
#include "src/setup.h" /* option_tab_spacing */
@ -1678,7 +1678,7 @@ user_menu (WEdit * edit)
long start_mark, end_mark;
struct stat status;
block_file = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE);
block_file = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE);
nomark = eval_marks (edit, &start_mark, &end_mark);
if (nomark == 0)

View File

@ -456,7 +456,7 @@ edit_open_macro_file (const char *r)
gchar *filename;
FILE *fd;
int file;
filename = concat_dir_and_file (home_dir, EDIT_MACRO_FILE);
filename = concat_dir_and_file (mc_config_get_data_path (), EDIT_MACRO_FILE);
file = open (filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (file == -1)
{
@ -508,7 +508,7 @@ edit_delete_macro (WEdit * edit, int k)
if (j < 0)
return 0;
}
tmp = concat_dir_and_file (home_dir, EDIT_TEMP_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_TEMP_FILE);
g = fopen (tmp, "w");
g_free (tmp);
if (!g)
@ -545,8 +545,8 @@ edit_delete_macro (WEdit * edit, int k)
}
fclose (f);
fclose (g);
tmp = concat_dir_and_file (home_dir, EDIT_TEMP_FILE);
tmp2 = concat_dir_and_file (home_dir, EDIT_MACRO_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_TEMP_FILE);
tmp2 = concat_dir_and_file (mc_config_get_data_path (), EDIT_MACRO_FILE);
if (rename (tmp, tmp2) == -1)
{
edit_error_dialog (_("Delete macro"), get_sys_error (_("Cannot overwrite macro file")));
@ -646,7 +646,7 @@ edit_load_syntax_file (WEdit * edit)
{
char *buffer;
buffer = concat_dir_and_file (home_dir, EDIT_SYNTAX_FILE);
buffer = concat_dir_and_file (mc_config_get_data_path (), EDIT_SYNTAX_FILE);
check_for_default (extdir, buffer);
edit_load_file_from_filename (edit, buffer);
g_free (buffer);
@ -687,7 +687,7 @@ edit_load_menu_file (WEdit * edit)
break;
case 1:
buffer = concat_dir_and_file (home_dir, EDIT_HOME_MENU);
buffer = concat_dir_and_file (mc_config_get_data_path (), EDIT_HOME_MENU);
check_for_default (menufile, buffer);
break;
@ -1007,7 +1007,7 @@ edit_do_search (WEdit * edit)
/* --------------------------------------------------------------------------------------------- */
static void
edit_search (WEdit *edit)
edit_search (WEdit * edit)
{
if (editcmd_dialog_search_show (edit))
edit_do_search (edit);
@ -1058,7 +1058,7 @@ edit_save_block_to_clip_file (WEdit * edit, long start, long finish)
{
int ret;
gchar *tmp;
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
ret = edit_save_block (edit, tmp, start, finish);
g_free (tmp);
return ret;
@ -1741,7 +1741,7 @@ eval_marks (WEdit * edit, long *start_mark, long *end_mark)
}
if (edit->column_highlight
&& (((edit->mark1 > end_mark_curs) && (edit->column1 < edit->column2))
&& (((edit->mark1 > end_mark_curs) && (edit->column1 < edit->column2))
|| ((edit->mark1 < end_mark_curs) && (edit->column1 > edit->column2))))
{
start_bol = edit_bol (edit, *start_mark);
@ -2500,7 +2500,7 @@ edit_paste_from_X_buf_cmd (WEdit * edit)
gchar *tmp;
/* try use external clipboard utility */
paste_to_file_from_ext_clip ();
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
edit_insert_file (edit, tmp);
g_free (tmp);
}
@ -2561,7 +2561,7 @@ edit_save_block_cmd (WEdit * edit)
if (eval_marks (edit, &start_mark, &end_mark))
return 1;
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
exp =
input_expand_dialog (_("Save block"), _("Enter file name:"),
MC_HISTORY_EDIT_SAVE_BLOCK, tmp);
@ -2603,7 +2603,7 @@ edit_insert_file_cmd (WEdit * edit)
gchar *tmp;
char *exp;
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
exp = input_expand_dialog (_("Insert file"), _("Enter file name:"),
MC_HISTORY_EDIT_INSERT_FILE, tmp);
g_free (tmp);
@ -2651,7 +2651,7 @@ edit_sort_cmd (WEdit * edit)
return 0;
}
tmp = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE);
edit_save_block (edit, tmp, start_mark, end_mark);
g_free (tmp);
@ -2663,8 +2663,10 @@ edit_sort_cmd (WEdit * edit)
return 1;
g_free (old);
old = exp;
tmp = g_strconcat (" sort ", exp, " ", home_dir, PATH_SEP_STR EDIT_BLOCK_FILE, " > ",
home_dir, PATH_SEP_STR EDIT_TEMP_FILE, (char *) NULL);
tmp =
g_strconcat (" sort ", exp, " ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_BLOCK_FILE,
" > ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_TEMP_FILE,
(char *) NULL);
e = system (tmp);
g_free (tmp);
if (e)
@ -2688,7 +2690,7 @@ edit_sort_cmd (WEdit * edit)
if (edit_block_delete_cmd (edit))
return 1;
tmp = concat_dir_and_file (home_dir, EDIT_TEMP_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_TEMP_FILE);
edit_insert_file (edit, tmp);
g_free (tmp);
return 0;
@ -2713,7 +2715,9 @@ edit_ext_cmd (WEdit * edit)
if (!exp)
return 1;
tmp = g_strconcat (exp, " > ", home_dir, PATH_SEP_STR EDIT_TEMP_FILE, (char *) NULL);
tmp =
g_strconcat (exp, " > ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_TEMP_FILE,
(char *) NULL);
e = system (tmp);
g_free (tmp);
g_free (exp);
@ -2725,7 +2729,7 @@ edit_ext_cmd (WEdit * edit)
}
edit->force |= REDRAW_COMPLETELY;
tmp = concat_dir_and_file (home_dir, EDIT_TEMP_FILE);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_TEMP_FILE);
edit_insert_file (edit, tmp);
g_free (tmp);
return 0;
@ -2747,8 +2751,8 @@ edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
char *quoted_name = NULL;
o = g_strconcat (mc_home, shell_cmd, (char *) NULL); /* original source script */
h = g_strconcat (home_dir, PATH_SEP_STR EDIT_DIR, shell_cmd, (char *) NULL); /* home script */
b = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE); /* block file */
h = g_strconcat (mc_config_get_data_path (), PATH_SEP_STR EDIT_DIR, shell_cmd, (char *) NULL); /* home script */
b = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE); /* block file */
script_home = fopen (h, "r");
if (script_home == NULL)
@ -2816,8 +2820,10 @@ edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
* $3 - file where error messages should be put
* (for compatibility with old scripts).
*/
tmp = g_strconcat (" ", home_dir, PATH_SEP_STR EDIT_DIR, shell_cmd, " ", quoted_name,
" ", home_dir, PATH_SEP_STR EDIT_BLOCK_FILE " /dev/null", (char *) NULL);
tmp =
g_strconcat (" ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_DIR, shell_cmd, " ",
quoted_name, " ", mc_config_get_cache_path (),
PATH_SEP_STR EDIT_BLOCK_FILE " /dev/null", (char *) NULL);
}
else
{
@ -2826,7 +2832,7 @@ edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
* Arguments:
* $1 - name of the edited file.
*/
tmp = g_strconcat (" ", home_dir, PATH_SEP_STR EDIT_DIR, shell_cmd, " ",
tmp = g_strconcat (" ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_DIR, shell_cmd, " ",
quoted_name, (char *) NULL);
}

View File

@ -46,6 +46,7 @@
#include "lib/strutil.h" /* str_term_trim() */
#include "lib/util.h" /* concat_dir_and_file() */
#include "lib/widget.h"
#include "lib/mcconfig.h"
#include "src/keybind-defaults.h"
#include "src/main.h" /* home_dir */
@ -265,7 +266,7 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo
return MSG_HANDLED;
case DLG_VALIDATE:
h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */
h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */
if (edit_ok_to_exit (edit))
h->state = DLG_CLOSED;
return MSG_HANDLED;
@ -345,7 +346,15 @@ edit_file (const char *_file, int line)
if (!made_directory)
{
char *dir = concat_dir_and_file (home_dir, EDIT_DIR);
char *dir = concat_dir_and_file (mc_config_get_cache_path (), EDIT_DIR);
made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
g_free (dir);
dir = concat_dir_and_file (mc_config_get_path (), EDIT_DIR);
made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
g_free (dir);
dir = concat_dir_and_file (mc_config_get_data_path (), EDIT_DIR);
made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
g_free (dir);
}

View File

@ -852,7 +852,8 @@ open_include_file (const char *filename)
return fopen (filename, "r");
g_free (error_file_name);
error_file_name = g_build_filename (home_dir, EDIT_DIR, filename, (char *) NULL);
error_file_name =
g_build_filename (mc_config_get_data_path (), EDIT_DIR, filename, (char *) NULL);
f = fopen (error_file_name, "r");
if (f != NULL)
return f;
@ -1510,7 +1511,7 @@ edit_load_syntax (WEdit * edit, char ***pnames, const char *type)
if (!*edit->filename && !type)
return;
}
f = g_build_filename (home_dir, EDIT_SYNTAX_FILE, (char *) NULL);
f = g_build_filename (mc_config_get_data_path (), EDIT_SYNTAX_FILE, (char *) NULL);
if (edit != NULL)
r = edit_read_syntax_file (edit, pnames, f, edit->filename,
get_first_editor_line (edit),

View File

@ -1024,7 +1024,7 @@ ext_cmd (void)
if (dir == 0)
{
buffer = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FILEBIND_FILE, NULL);
buffer = g_build_filename (mc_config_get_data_path (), MC_FILEBIND_FILE, NULL);
check_for_default (extdir, buffer);
do_edit (buffer);
g_free (buffer);
@ -1073,7 +1073,7 @@ edit_mc_menu_cmd (void)
break;
case 1:
buffer = g_build_filename (home_dir, MC_USERCONF_DIR, MC_USERMENU_FILE, NULL);
buffer = g_build_filename (mc_config_get_data_path (), MC_USERMENU_FILE, NULL);
check_for_default (menufile, buffer);
break;
@ -1118,7 +1118,7 @@ edit_fhl_cmd (void)
if (dir == 0)
{
buffer = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FHL_INI_FILE, NULL);
buffer = g_build_filename (mc_config_get_path (), MC_FHL_INI_FILE, NULL);
check_for_default (fhlfile, buffer);
do_edit (buffer);
g_free (buffer);
@ -1572,8 +1572,8 @@ void
save_setup_cmd (void)
{
if (save_setup (TRUE, TRUE))
message (D_NORMAL, _("Setup"), _("Setup saved to ~/%s"),
MC_USERCONF_DIR PATH_SEP_STR MC_CONFIG_FILE);
message (D_NORMAL, _("Setup"), _("Setup saved to %s%s%s"),
mc_config_get_path (), PATH_SEP_STR, MC_CONFIG_FILE);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -325,7 +325,7 @@ do_cd_command (char *orig_cmd)
{
if (cmd[0] == 0)
{
sync_tree (home_dir);
sync_tree (mc_config_get_home_dir ());
}
else if (strcmp (cmd + 3, "..") == 0)
{

View File

@ -36,6 +36,7 @@
#include "lib/tty/tty.h"
#include "lib/search.h"
#include "lib/fileloc.h"
#include "lib/mcconfig.h"
#include "lib/util.h"
#include "lib/vfs/mc-vfs/vfs.h"
#include "lib/widget.h"
@ -629,7 +630,7 @@ regex_command (const char *filename, const char *action, int *move_dir)
int mc_user_ext = 1;
int home_error = 0;
extension_file = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FILEBIND_FILE, NULL);
extension_file = g_build_filename (mc_config_get_data_path (), MC_FILEBIND_FILE, NULL);
if (!exist_file (extension_file))
{
g_free (extension_file);
@ -675,13 +676,14 @@ regex_command (const char *filename, const char *action, int *move_dir)
}
if (home_error)
{
char *title = g_strdup_printf (_("~/%s file error"),
MC_USERCONF_DIR PATH_SEP_STR MC_FILEBIND_FILE);
char *title = g_strdup_printf (_("%s%s%s file error"),
mc_config_get_data_path (), PATH_SEP_STR,
MC_FILEBIND_FILE);
message (D_ERROR, title,
_("The format of the ~/%s file has "
_("The format of the %s%s%s file has "
"changed with version 3.0. You may either want to copy "
"it from %smc.ext or use that file as an example of how to write it."),
MC_USERCONF_DIR PATH_SEP_STR MC_FILEBIND_FILE, mc_home);
mc_config_get_data_path (), PATH_SEP_STR, MC_FILEBIND_FILE, mc_home);
g_free (title);
}
}

View File

@ -506,7 +506,7 @@ hotlist_button_callback (WButton * button, int action)
case B_REFRESH_VFS:
listbox_remove_list (l_hotlist);
listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, home_dir, 0);
listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, mc_config_get_home_dir (), 0);
vfs_fill_names (add_name_to_list);
return MSG_NOT_HANDLED;
#endif /* ENABLE_VFS */
@ -814,7 +814,7 @@ init_hotlist (int list_type)
#ifdef ENABLE_VFS
if (list_type == LIST_VFSLIST)
{
listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, home_dir, 0);
listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, mc_config_get_home_dir (), 0);
vfs_fill_names (add_name_to_list);
}
else
@ -1551,7 +1551,7 @@ load_hotlist (void)
}
if (!hotlist_file_name)
hotlist_file_name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_HOTLIST_FILE, NULL);
hotlist_file_name = g_build_filename (mc_config_get_path (), MC_HOTLIST_FILE, NULL);
hotlist = new_hotlist ();
hotlist->type = HL_TYPE_GROUP;

View File

@ -2632,7 +2632,7 @@ _do_panel_cd (WPanel * panel, const char *new_dir, enum cd_enum cd_type)
new_dir = temp;
}
}
directory = *new_dir ? new_dir : home_dir;
directory = *new_dir ? new_dir : mc_config_get_home_dir ();
if (mc_chdir (directory) == -1)
{

View File

@ -174,7 +174,8 @@ save_tree (WTree * tree)
if (error)
{
tree_name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, (char *) NULL);
tree_name =
g_build_filename (mc_config_get_cache_path (), MC_TREESTORE_FILE, (char *) NULL);
fprintf (stderr, _("Cannot open the %s file for writing:\n%s\n"), tree_name,
unix_error_string (error));
g_free (tree_name);
@ -212,7 +213,7 @@ load_tree (WTree * tree)
tree_store_load ();
tree->selected_ptr = tree->store->tree_first;
tree_chdir (tree, home_dir);
tree_chdir (tree, mc_config_get_home_dir ());
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -640,7 +640,7 @@ tree_store_load (void)
char *name;
int retval;
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
name = g_build_filename (mc_config_get_cache_path (), MC_TREESTORE_FILE, NULL);
retval = tree_store_load_from (name);
g_free (name);
@ -660,7 +660,7 @@ tree_store_save (void)
char *name;
int retval;
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
name = g_build_filename (mc_config_get_cache_path (), MC_TREESTORE_FILE, NULL);
mc_util_make_backup_if_possible (name, ".tmp");
retval = tree_store_save_to (name);

View File

@ -785,7 +785,7 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
#ifdef USE_INTERNAL_EDIT
if (edit_widget)
{
char *file = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE);
char *file = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE);
fname = (*quote_func) (file, 0);
g_free (file);
return fname;
@ -872,15 +872,17 @@ user_menu_cmd (struct WEdit *edit_widget)
{
g_free (menu);
if (edit_widget)
menu = concat_dir_and_file (home_dir, EDIT_HOME_MENU);
menu = concat_dir_and_file (mc_config_get_data_path (), EDIT_HOME_MENU);
else
menu = g_build_filename (home_dir, MC_USERCONF_DIR, MC_USERMENU_FILE, NULL);
menu = g_build_filename (mc_config_get_data_path (), MC_USERMENU_FILE, NULL);
if (!exist_file (menu))
{
g_free (menu);
menu = concat_dir_and_file (mc_home, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
menu =
concat_dir_and_file (mc_config_get_home_dir (),
edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
if (!exist_file (menu))
{
g_free (menu);

View File

@ -123,8 +123,6 @@ const char *mc_prompt = NULL;
char *mc_home = NULL;
/* mc_home_alt: Alternative home of MC - deprecated /usr/share/mc */
char *mc_home_alt = NULL;
/* The home directory */
const char *home_dir = NULL;
/* Set to TRUE to suppress printing the last directory */
int print_last_revert = FALSE;
@ -207,11 +205,6 @@ OS_Setup (void)
mc_home_alt = g_strdup (DATADIR);
}
/* This variable is used by the subshell */
home_dir = getenv ("HOME");
if (home_dir == NULL)
home_dir = mc_home;
}
/* --------------------------------------------------------------------------------------------- */
@ -418,8 +411,6 @@ update_xterm_title_path (void)
int
main (int argc, char *argv[])
{
struct stat s;
char *mc_dir;
GError *error = NULL;
gboolean isInitialized;
@ -428,6 +419,7 @@ main (int argc, char *argv[])
bindtextdomain ("mc", LOCALEDIR);
textdomain ("mc");
/* Set up temporary directory */
mc_tmpdir ();
@ -462,6 +454,17 @@ 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 ((gboolean) mc_args__slow_terminal, (gboolean) mc_args__ugly_line_drawing);
@ -477,24 +480,28 @@ main (int argc, char *argv[])
load_keymap_defs ();
tty_init_colors (mc_args__disable_colors, mc_args__force_colors);
isInitialized = mc_skin_init (&error);
mc_filehighlight = mc_fhl_new (TRUE);
dlg_set_default_colors ();
if (!isInitialized)
{
GError *error2 = NULL;
isInitialized = mc_skin_init (&error2);
mc_filehighlight = mc_fhl_new (TRUE);
dlg_set_default_colors ();
if (!isInitialized)
{
message (D_ERROR, _("Warning"), "%s", error2->message);
g_error_free (error2);
error2 = NULL;
}
}
if (error != NULL)
{
message (D_ERROR, _("Warning"), "%s", error->message);
g_error_free (error);
error = NULL;
}
/* create home directory */
/* do it after the screen library initialization to show the error message */
mc_dir = g_build_filename (home_dir, MC_USERCONF_DIR, (char *) NULL);
canonicalize_pathname (mc_dir);
if ((stat (mc_dir, &s) != 0) && (errno == ENOENT) && mkdir (mc_dir, 0700) != 0)
message (D_ERROR, _("Warning"), _("Cannot create %s directory"), mc_dir);
g_free (mc_dir);
#ifdef HAVE_SUBSHELL_SUPPORT
/* Done here to ensure that the subshell doesn't */
@ -582,6 +589,8 @@ main (int argc, char *argv[])
g_free (mc_run_param0);
g_free (mc_run_param1);
mc_config_deinit_config_paths ();
putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
return 0;

View File

@ -81,8 +81,6 @@ extern const char *mc_prompt;
extern char *mc_home;
extern char *mc_home_alt;
extern const char *home_dir;
/*** declarations of public functions ************************************************************/
#ifdef HAVE_SUBSHELL_SUPPORT

View File

@ -383,7 +383,7 @@ static const struct
\return
Newly allocated path to config name or NULL if file not found.
If config_file_name is a relative path, then search config in stantart pathes.
If config_file_name is a relative path, then search config in stantart paths.
*/
static char *
load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
@ -407,9 +407,9 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam
return NULL;
if (subdir != NULL)
ret = g_build_filename (home_dir, MC_USERCONF_DIR, subdir, lc_basename, NULL);
ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
else
ret = g_build_filename (home_dir, MC_USERCONF_DIR, lc_basename, NULL);
ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);
if (exist_file (ret))
{
@ -689,7 +689,7 @@ load_setup_get_keymap_profile_config (void)
g_free (fname);
/* 3) ~/.mc (home_dir?) */
fname = g_build_filename (home_dir, MC_USERCONF_DIR, GLOBAL_KEYMAP_FILE, NULL);
fname = g_build_filename (mc_config_get_path (), GLOBAL_KEYMAP_FILE, NULL);
load_setup_init_config_from_file (&keymap_config, fname);
g_free (fname);
@ -811,7 +811,7 @@ setup_init (void)
if (profile_name != NULL)
return profile_name;
profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL);
if (!exist_file (profile))
{
inifile = concat_dir_and_file (mc_home, "mc.ini");
@ -864,7 +864,7 @@ load_setup (void)
global_profile_name = g_build_filename (mc_home_alt, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
}
panels_profile_name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_PANELS_FILE, NULL);
panels_profile_name = g_build_filename (mc_config_get_cache_path (), MC_PANELS_FILE, NULL);
mc_main_config = mc_config_init (profile);
@ -1015,7 +1015,7 @@ save_setup (gboolean save_options, gboolean save_panel_options)
mc_config_set_string (mc_main_config, "Misc", "clipboard_store", clipboard_store_path);
mc_config_set_string (mc_main_config, "Misc", "clipboard_paste", clipboard_paste_path);
tmp_profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
tmp_profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL);
ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
g_free (tmp_profile);
@ -1069,7 +1069,7 @@ save_config (void)
GError *error = NULL;
size_t i;
profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL);
/* Save integer options */
for (i = 0; int_options[i].opt_name != NULL; i++)
@ -1108,7 +1108,7 @@ save_layout (void)
char *profile;
size_t i;
profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL);
/* Save integer options */
for (i = 0; layout[i].opt_name != NULL; i++)
mc_config_set_int (mc_main_config, "Layout", layout[i].opt_name, *layout[i].opt_addr);

View File

@ -53,7 +53,7 @@
#include "lib/tty/key.h" /* XCTRL */
#include "lib/vfs/mc-vfs/vfs.h"
#include "lib/strutil.h"
#include "lib/fileloc.h"
#include "lib/mcconfig.h"
#include "lib/util.h"
#include "lib/widget.h"
@ -237,7 +237,7 @@ write_all (int fd, const void *buf, size_t count)
static void
init_subshell_child (const char *pty_name)
{
const char *init_file = NULL;
char *init_file = NULL;
pid_t mc_sid;
(void) pty_name;
@ -270,7 +270,7 @@ init_subshell_child (const char *pty_name)
/* and the user's startup file may do a `cd' command anyway */
{
int ret;
ret = chdir (home_dir); /* FIXME? What about when we re-run the subshell? */
ret = chdir (mc_config_get_home_dir ()); /* FIXME? What about when we re-run the subshell? */
}
/* Set MC_SID to prevent running one mc from another */
@ -285,16 +285,28 @@ init_subshell_child (const char *pty_name)
switch (subshell_type)
{
case BASH:
init_file = MC_USERCONF_DIR PATH_SEP_STR "bashrc";
init_file = g_build_filename (mc_config_get_path (), "bashrc", NULL);
if (access (init_file, R_OK) == -1)
init_file = ".bashrc";
{
g_free (init_file);
init_file = g_strdup (".bashrc");
}
/* Make MC's special commands not show up in bash's history */
putenv ((char *) "HISTCONTROL=ignorespace");
/* Allow alternative readline settings for MC */
if (access (MC_USERCONF_DIR PATH_SEP_STR "inputrc", R_OK) == 0)
putenv ((char *) "INPUTRC=" MC_USERCONF_DIR PATH_SEP_STR "/inputrc");
{
char *input_file = g_build_filename (mc_config_get_path (), "inputrc", NULL);
if (access (input_file, R_OK) == 0)
{
char *putenv_str = g_strconcat ("INPUTRC=", input_file, NULL);
putenv (putenv_str);
g_free (putenv_str);
}
g_free (input_file);
}
break;
@ -353,6 +365,7 @@ init_subshell_child (const char *pty_name)
}
/* If we get this far, everything failed miserably */
g_free (init_file);
_exit (FORK_FAILURE);
}