Allow setup mc home directory using MC_HOME environment variable.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2012-03-16 13:53:34 +03:00
parent cce7ccf48a
commit 13a660d2e0
13 changed files with 114 additions and 65 deletions

View File

@ -3664,8 +3664,9 @@ o infrautilizadas).
.SH "ARCHIVOS AUXILIARES"
Los directorios indicados a continuación pueden variar de una
instalación a otra. También se pueden modificar con la variable de
entorno MC_DATADIR, que de estar definida se emplearía en vez de
@prefix@/share/mc.
entorno
.BR MC_DATADIR ,
que de estar definida se emplearía en vez de @prefix@/share/mc.
.PP
.I @prefix@/share/mc.hlp
.IP
@ -3722,6 +3723,12 @@ La lista de directorios para el árbol de directorios y la vista en árbol.
Menú local definido por el usuario. Si este archivo
está presente será usado en lugar del menú de aplicaciones
personal o de sistema.
.PP
To change default home directory of MC, you can use
.BR MC_HOME
environment variable. The value of MC_HOME must be an absolute path. If MC_HOME
variable is unset or empty, HOME variable is used. If HOME variable is unset
or empty, MC home directory is get from GLib library.
.\"SKIP_SECTION"
.SH "LICENCIA"
Este programa se distribuye en los términos que recoge la Licencia Pública

View File

@ -3172,9 +3172,10 @@ valamelyik gomb nem használható).
.SH ""
.\"NODE "FILES"
.SH "Fájlok"
A progam minden ezzel kapcsolatos infomációt az MCHOME környezeti
változóban tárol. Ha ezt a változót nem állítottuk be, akkor ez vissza
fog állítódni a /usr könyvtárra.
A progam minden ezzel kapcsolatos infomációt az
.BR MC_DATADIR
környezeti változóban tárol. Ha ezt a változót nem állítottuk be, akkor
ez vissza fog állítódni a /usr könyvtárra.
.PP
.I @prefix@/share/mc/mc.hlp
.IP
@ -3237,6 +3238,12 @@ frissíti ezt.
.IP
Helyi felhasználó által definiált menü. Ha ez a fájl létezik, ezt
használja a home, vagy rendszerszintű alkalmazás menü helyett.
.PP
To change default home directory of MC, you can use
.BR MC_HOME
environment variable. The value of MC_HOME must be an absolute path. If MC_HOME
variable is unset or empty, HOME variable is used. If HOME variable is unset
or empty, MC home directory is get from GLib library.
.\"NODE "AVAILABILITY"
.SH "A Midnight Commander frissítése"
A program legutolsó verzióját az ftp.nuclecu.unam.mx címen a

View File

@ -3168,8 +3168,9 @@ simpatici tasti dappertutto).
.\"NODE "FILES"
.SH "FILE"
Il programma recupera tutte le informazioni relative al proprio funzionamento
dalla variabile ambiente MC_DATADIR, e se la variabile non è impostata,
passerà alla directory @prefix@/share/mc .
dalla variabile ambiente
.BR MC_DATADIR ,
e se la variabile non è impostata, passerà alla directory @prefix@/share/mc .
.PP
.I @prefix@/share/mc/mc.hlp
.IP
@ -3226,6 +3227,12 @@ L'elenco di directory per l'albero directory e per la vista ad albero.
.IP
Menu locale definito dall'utente. Se questo file è presente viene usato
al posto del menu delle applicazioni utente o di sistema.
.PP
To change default home directory of MC, you can use
.BR MC_HOME
environment variable. The value of MC_HOME must be an absolute path. If MC_HOME
variable is unset or empty, HOME variable is used. If HOME variable is unset
or empty, MC home directory is get from GLib library.
.\"SKIP_SECTION"
.SH "LICENZA"
Questo programma è distribuito sotto i termini della Licenza Generale

View File

@ -4098,8 +4098,10 @@ everywhere).
.\"NODE "FILES"
.SH "FILES"
Full paths below may vary between installations. They are also affected
by the MC_DATADIR environment variable. If it's set, its value is used
instead of @prefix@/share/mc in the paths below.
by the
.BR MC_DATADIR
environment variable. If it's set, its value is used instead of
@prefix@/share/mc in the paths below.
.PP
.I @prefix@/share/mc/mc.hlp
.IP
@ -4154,6 +4156,12 @@ The directory list for the directory tree and tree view features.
.IP
Local user\-defined menu. If this file is present, it is used instead of
the home or system\-wide applications menu.
.PP
To change default home directory of MC, you can use
.BR MC_HOME
environment variable. The value of MC_HOME must be an absolute path. If MC_HOME
variable is unset or empty, HOME variable is used. If HOME variable is unset
or empty, MC home directory is get from GLib library.
.\"SKIP_SECTION"
.SH "LICENSE"
This program is distributed under the terms of the GNU General Public

View File

@ -2874,7 +2874,8 @@ zupełnie bezużytecznych klawiszy).
.\"NODE "FILES"
.SH PLIKI
.PP
Program będzie pobierał wszystkie swoje informacje ze zmiennej MCHOME,
Program będzie pobierał wszystkie swoje informacje ze zmiennej
.BR MC_DATADIR ,
jeśli jest ona nie ustawiona to znowu przetwarzany jest katalog /usr.
.PP
@prefix@/share/mc.hlp
@ -2933,6 +2934,11 @@ Midnight Commander robi to sam za ciebie.
Lokalny plik zdefiniowany przez użytkownika. Jeśli ten plik jest dostępny,
jest używany zamiast pliku w katalogu domowym i ogólnosystemowego.
.PP
To change default home directory of MC, you can use
.BR MC_HOME
environment variable. The value of MC_HOME must be an absolute path. If MC_HOME
variable is unset or empty, HOME variable is used. If HOME variable is unset
or empty, MC home directory is get from GLib library.
.\"SKIP_SECTION"
.SH LICENCJA
Program jest dystrybuowany na zasadach licencji GNU General Public License

View File

@ -4546,6 +4546,13 @@ Commander; используется только в тех случаях, ко
локальное меню, задаваемое пользователем. Если этот файл существует, он
используется вместо файла меню из домашнего каталога пользователя и
общесистемного меню.
.PP
Для того, чтобы изменить домашний каталог MC, установленный по умолчанию,
можно использовать переменную окружения
.BR MC_HOME .
Значением этой переменный должен быть абсолютный путь. Если переменная MC_HOME
не определена или пуста, используется переменная окружения HOME. Если и HOME
не определена или пуста, домашний каталог MC определяется средствами библиотеки GLib.
.\"SKIP_SECTION"
.\" "LICENSE"
.SH Лицензия

View File

@ -3180,8 +3180,9 @@ insert=\\e[Op
.\"NODE "FILES"
.SH "ДАТОТЕКЕ"
Програм ће добавити све своје податке у односу на променљиву окружења
MC_DATADIR. Ако ова променљива није постављена, биће употребљен
директоријум @prefix@/share/mc.
.BR MC_DATADIR .
Ако ова променљива није постављена, биће употребљен директоријум
@prefix@/share/mc.
.PP
.I @prefix@/share/mc/mc.hlp
.IP

View File

@ -9,6 +9,4 @@ libmcconfig_la_SOURCES = \
libmcconfig_la_CFLAGS = -I$(top_srcdir) \
$(GLIB_CFLAGS) \
-DDATADIR=\""$(pkgdatadir)/"\" \
-DLOCALEDIR=\""$(localedir)"\" \
-DSYSCONFDIR=\""$(sysconfdir)/@PACKAGE@/"\"
-DLOCALEDIR=\""$(localedir)"\"

View File

@ -271,64 +271,43 @@ mc_config_fix_migrated_rules (void)
void
mc_config_init_config_paths (GError ** error)
{
const char *mc_datadir;
#ifdef MC_HOMEDIR_XDG
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 ();
char *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);
#ifdef MC_HOMEDIR_XDG
dir = g_build_filename (mc_config_get_home_dir (), ".config", (char *) NULL);
mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error);
g_free (dir);
u_cache_dir = (u_cache_dir == NULL)
? g_build_filename (mc_config_get_home_dir (), ".cache", NULL) : g_strdup (u_cache_dir);
dir = g_build_filename (mc_config_get_home_dir (), ".cache", (char *) NULL);
mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error);
g_free (dir);
u_data_dir = (u_data_dir == NULL)
? g_build_filename (mc_config_get_home_dir (), ".local", "share", NULL)
: g_strdup (u_data_dir);
mc_config_str = mc_config_init_one_config_path (u_config_dir, MC_USERCONF_DIR, error);
mc_cache_str = mc_config_init_one_config_path (u_cache_dir, MC_USERCONF_DIR, error);
mc_data_str = 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);
dir = g_build_filename (mc_config_get_home_dir (), ".local", "share", (char *) NULL);
mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error);
g_free (dir);
mc_config_fix_migrated_rules ();
#else /* MC_HOMEDIR_XDG */
char *defined_userconf_dir;
char *u_config_dir;
defined_userconf_dir = tilde_expand (MC_USERCONF_DIR);
if (!g_path_is_absolute (defined_userconf_dir))
{
u_config_dir = g_build_filename (mc_config_get_home_dir (), MC_USERCONF_DIR, NULL);
g_free (defined_userconf_dir);
}
if (g_path_is_absolute (defined_userconf_dir))
dir = defined_userconf_dir;
else
u_config_dir = defined_userconf_dir;
{
g_free (defined_userconf_dir);
dir = g_build_filename (mc_config_get_home_dir (), MC_USERCONF_DIR, (char *) NULL);
}
mc_data_str = mc_cache_str = mc_config_str =
mc_config_init_one_config_path (u_config_dir, "", error);
mc_config_init_one_config_path (dir, "", error);
g_free (u_config_dir);
g_free (dir);
#endif /* MC_HOMEDIR_XDG */
/* 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;
}
@ -381,8 +360,10 @@ mc_config_get_home_dir (void)
{
if (homedir == NULL)
{
homedir = g_getenv ("MC_HOME");
if (homedir == NULL || *homedir == '\0')
homedir = g_getenv ("HOME");
if (homedir == NULL)
if (homedir == NULL || *homedir == '\0')
homedir = g_get_home_dir ();
}
return homedir;

View File

@ -823,7 +823,7 @@ const char *
mc_tmpdir (void)
{
static char buffer[64];
static const char *tmpdir;
static const char *tmpdir = NULL;
const char *sys_tmp;
struct passwd *pwd;
struct stat st;

View File

@ -9,8 +9,10 @@ SUBDIRS += diffviewer
endif
AM_CPPFLAGS = \
-DLOCALEDIR=\""$(localedir)"\" \
-DLIBEXECDIR=\""$(libexecdir)/@PACKAGE@/"\"
-DSYSCONFDIR=\""$(sysconfdir)/@PACKAGE@/"\" \
-DLIBEXECDIR=\""$(libexecdir)/@PACKAGE@/"\" \
-DDATADIR=\""$(pkgdatadir)/"\" \
-DLOCALEDIR=\""$(localedir)"\"
if CONS_SAVER
SUBDIRS += consaver

View File

@ -161,8 +161,10 @@ check_codeset (void)
static void
OS_Setup (void)
{
const char *shell_env = getenv ("SHELL");
const char *shell_env;
const char *datadir_env;
shell_env = getenv ("SHELL");
if ((shell_env == NULL) || (shell_env[0] == '\0'))
{
struct passwd *pwd;
@ -178,6 +180,19 @@ 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 */
datadir_env = g_getenv ("MC_DATADIR");
if (datadir_env != NULL)
mc_global.sysconfig_dir = g_strdup (datadir_env);
else
mc_global.sysconfig_dir = g_strdup (SYSCONFDIR);
mc_global.share_data_dir = g_strdup (DATADIR);
/* Set up temporary directory */
mc_tmpdir ();
}
/* --------------------------------------------------------------------------------------------- */
@ -419,6 +434,17 @@ main (int argc, char *argv[])
return exit_code;
}
/* do this before mc_args_show_info () to view paths in the --datadir-info output */
OS_Setup ();
if (!g_path_is_absolute (mc_config_get_home_dir ()))
{
error = g_error_new (MC_ERROR, 0, "%s: %s", _("Home directory path is not absolute"),
mc_config_get_home_dir ());
mc_event_deinit (NULL);
goto startup_exit_falure;
}
if (!mc_args_show_info ())
{
exit_code = EXIT_SUCCESS;
@ -428,10 +454,6 @@ main (int argc, char *argv[])
if (!events_init (&error))
goto startup_exit_falure;
/* Set up temporary directory */
(void) mc_tmpdir ();
OS_Setup ();
/* Initialize and create home directories */
mc_config_init_config_paths (&error);
if (error == NULL && mc_config_deprecated_dir_present ())
mc_config_migrate_from_old_place (&error);

View File

@ -177,6 +177,9 @@ show_version (void)
void
show_datadirs_extended (void)
{
(void) printf ("%s %s\n", _("Home directory:"), mc_config_get_home_dir ());
(void) puts ("");
PRINTF_GROUP (_("System data"));
PRINTF_SECTION (_("Config directory:"), mc_global.sysconfig_dir);