mirror of
https://github.com/MidnightCommander/mc
synced 2025-03-13 03:13:08 +03:00
Merge branch '2738_handle_startup_errors'
* 2738_handle_startup_errors: Allow setup mc home directory using MC_HOME environment variable. Tweak arguments parsing Handle error of mc main loop. Ticket #2738: handle errors at mc sturtup stage.
This commit is contained in:
commit
903e184fff
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -4546,6 +4546,13 @@ Commander; используется только в тех случаях, ко
|
||||
локальное меню, задаваемое пользователем. Если этот файл существует, он
|
||||
используется вместо файла меню из домашнего каталога пользователя и
|
||||
общесистемного меню.
|
||||
.PP
|
||||
Для того, чтобы изменить домашний каталог MC, установленный по умолчанию,
|
||||
можно использовать переменную окружения
|
||||
.BR MC_HOME .
|
||||
Значением этой переменный должен быть абсолютный путь. Если переменная MC_HOME
|
||||
не определена или пуста, используется переменная окружения HOME. Если и HOME
|
||||
не определена или пуста, домашний каталог MC определяется средствами библиотеки GLib.
|
||||
.\"SKIP_SECTION"
|
||||
.\" "LICENSE"
|
||||
.SH Лицензия
|
||||
|
@ -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
|
||||
|
@ -9,6 +9,4 @@ libmcconfig_la_SOURCES = \
|
||||
|
||||
libmcconfig_la_CFLAGS = -I$(top_srcdir) \
|
||||
$(GLIB_CFLAGS) \
|
||||
-DDATADIR=\""$(pkgdatadir)/"\" \
|
||||
-DLOCALEDIR=\""$(localedir)"\" \
|
||||
-DSYSCONFDIR=\""$(sysconfdir)/@PACKAGE@/"\"
|
||||
-DLOCALEDIR=\""$(localedir)"\"
|
||||
|
@ -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 ("HOME");
|
||||
if (homedir == NULL)
|
||||
homedir = g_getenv ("MC_HOME");
|
||||
if (homedir == NULL || *homedir == '\0')
|
||||
homedir = g_getenv ("HOME");
|
||||
if (homedir == NULL || *homedir == '\0')
|
||||
homedir = g_get_home_dir ();
|
||||
}
|
||||
return homedir;
|
||||
|
@ -72,7 +72,7 @@ static struct str_class used_class;
|
||||
|
||||
GIConv str_cnv_to_term;
|
||||
GIConv str_cnv_from_term;
|
||||
GIConv str_cnv_not_convert;
|
||||
GIConv str_cnv_not_convert = INVALID_CONV;
|
||||
|
||||
/* if enc is same encoding like on terminal */
|
||||
static int
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
366
src/args.c
366
src/args.c
@ -416,12 +416,194 @@ mc_args_add_extended_info_to_help (void)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
mc_setup_by_args (int argc, char *argv[])
|
||||
static gchar *
|
||||
mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_message,
|
||||
const gchar * help_str)
|
||||
{
|
||||
GString *buffer;
|
||||
GIConv conv;
|
||||
gchar *full_help_str;
|
||||
|
||||
buffer = g_string_new ("");
|
||||
conv = g_iconv_open (charset, "UTF-8");
|
||||
full_help_str = g_strdup_printf ("%s\n\n%s\n", error_message, help_str);
|
||||
|
||||
str_convert (conv, full_help_str, buffer);
|
||||
|
||||
g_free (full_help_str);
|
||||
g_iconv_close (conv);
|
||||
|
||||
return g_string_free (buffer, FALSE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
parse_mc_e_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error)
|
||||
{
|
||||
(void) option_name;
|
||||
(void) data;
|
||||
(void) error;
|
||||
|
||||
mc_global.mc_run_mode = MC_RUN_EDITOR;
|
||||
mc_run_param0 = g_strdup (value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
parse_mc_v_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error)
|
||||
{
|
||||
(void) option_name;
|
||||
(void) data;
|
||||
(void) error;
|
||||
|
||||
mc_global.mc_run_mode = MC_RUN_VIEWER;
|
||||
mc_run_param0 = g_strdup (value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** error)
|
||||
{
|
||||
const gchar *_system_codepage;
|
||||
gboolean ok = TRUE;
|
||||
|
||||
_system_codepage = str_detect_termencoding ();
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
if (!str_isutf8 (_system_codepage))
|
||||
bind_textdomain_codeset ("mc", "UTF-8");
|
||||
#endif
|
||||
|
||||
context = g_option_context_new (mc_args_add_usage_info ());
|
||||
|
||||
g_option_context_set_ignore_unknown_options (context, FALSE);
|
||||
|
||||
mc_args_add_extended_info_to_help ();
|
||||
|
||||
main_group = g_option_group_new ("main", _("Main options"), _("Main options"), NULL, NULL);
|
||||
|
||||
g_option_group_add_entries (main_group, argument_main_table);
|
||||
g_option_context_set_main_group (context, main_group);
|
||||
g_option_group_set_translation_domain (main_group, translation_domain);
|
||||
|
||||
terminal_group = g_option_group_new ("terminal", _("Terminal options"),
|
||||
_("Terminal options"), NULL, NULL);
|
||||
|
||||
g_option_group_add_entries (terminal_group, argument_terminal_table);
|
||||
g_option_context_add_group (context, terminal_group);
|
||||
g_option_group_set_translation_domain (terminal_group, translation_domain);
|
||||
|
||||
color_group = mc_args_new_color_group ();
|
||||
|
||||
g_option_group_add_entries (color_group, argument_color_table);
|
||||
g_option_context_add_group (context, color_group);
|
||||
g_option_group_set_translation_domain (color_group, translation_domain);
|
||||
|
||||
if (!g_option_context_parse (context, argc, argv, error))
|
||||
{
|
||||
GError *error2 = NULL;
|
||||
|
||||
if (*error == NULL)
|
||||
*error = g_error_new (MC_ERROR, 0, "%s\n", _("Arguments parse error!"));
|
||||
else
|
||||
{
|
||||
gchar *help_str;
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,14,0)
|
||||
help_str = g_option_context_get_help (context, TRUE, NULL);
|
||||
#else
|
||||
help_str = g_strdup ("");
|
||||
#endif
|
||||
if (str_isutf8 (_system_codepage))
|
||||
error2 = g_error_new ((*error)->domain, (*error)->code, "%s\n\n%s\n",
|
||||
(*error)->message, help_str);
|
||||
else
|
||||
{
|
||||
gchar *full_help_str;
|
||||
|
||||
full_help_str =
|
||||
mc_args__convert_help_to_syscharset (_system_codepage, (*error)->message,
|
||||
help_str);
|
||||
error2 = g_error_new ((*error)->domain, (*error)->code, "%s", full_help_str);
|
||||
g_free (full_help_str);
|
||||
}
|
||||
|
||||
g_free (help_str);
|
||||
g_error_free (*error);
|
||||
*error = error2;
|
||||
}
|
||||
|
||||
ok = FALSE;
|
||||
}
|
||||
|
||||
g_option_context_free (context);
|
||||
mc_args_clean_temp_help_strings ();
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
if (!str_isutf8 (_system_codepage))
|
||||
bind_textdomain_codeset ("mc", _system_codepage);
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
mc_args_show_info (void)
|
||||
{
|
||||
if (mc_args__show_version)
|
||||
{
|
||||
show_version ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mc_args__show_datadirs)
|
||||
{
|
||||
printf ("%s (%s)\n", mc_global.sysconfig_dir, mc_global.share_data_dir);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mc_args__show_datadirs_extended)
|
||||
{
|
||||
show_datadirs_extended ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mc_args__show_configure_opts)
|
||||
{
|
||||
show_configure_options ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
mc_setup_by_args (int argc, char **argv, GError ** error)
|
||||
{
|
||||
const char *base;
|
||||
char *tmp;
|
||||
|
||||
if (mc_args__force_colors)
|
||||
mc_global.tty.disable_colors = FALSE;
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
if (mc_args__nouse_subshell)
|
||||
mc_global.tty.use_subshell = FALSE;
|
||||
#endif /* HAVE_SUBSHELL_SUPPORT */
|
||||
|
||||
#ifdef ENABLE_VFS_SMB
|
||||
if (mc_args__debug_level != 0)
|
||||
smbfs_set_debug (mc_args__debug_level);
|
||||
@ -440,6 +622,7 @@ mc_setup_by_args (int argc, char *argv[])
|
||||
mc_setctl (vpath, VFS_SETCTL_LOGFILE, (void *) mc_args__netfs_logfile);
|
||||
vfs_path_free (vpath);
|
||||
#endif /* ENABLE_VFS_SMB */
|
||||
(void) vpath;
|
||||
}
|
||||
|
||||
base = x_basename (argv[0]);
|
||||
@ -534,8 +717,8 @@ mc_setup_by_args (int argc, char *argv[])
|
||||
mc_run_param0 = g_strdup (tmp);
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "%s\n", _("No arguments given to the viewer."));
|
||||
exit (EXIT_FAILURE);
|
||||
*error = g_error_new (MC_ERROR, 0, "%s\n", _("No arguments given to the viewer."));
|
||||
return FALSE;
|
||||
}
|
||||
mc_global.mc_run_mode = MC_RUN_VIEWER;
|
||||
}
|
||||
@ -546,8 +729,9 @@ mc_setup_by_args (int argc, char *argv[])
|
||||
|
||||
if (argc < 3)
|
||||
{
|
||||
fprintf (stderr, "%s\n", _("Two files are required to evoke the diffviewer."));
|
||||
exit (EXIT_FAILURE);
|
||||
*error = g_error_new (MC_ERROR, 0, "%s\n",
|
||||
_("Two files are required to evoke the diffviewer."));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (tmp != NULL)
|
||||
@ -589,178 +773,8 @@ mc_setup_by_args (int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
mc_args_process (int argc, char *argv[])
|
||||
{
|
||||
if (mc_args__show_version)
|
||||
{
|
||||
show_version ();
|
||||
return FALSE;
|
||||
}
|
||||
if (mc_args__show_datadirs)
|
||||
{
|
||||
printf ("%s (%s)\n", mc_global.sysconfig_dir, mc_global.share_data_dir);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mc_args__show_datadirs_extended)
|
||||
{
|
||||
show_datadirs_extended ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mc_args__show_configure_opts)
|
||||
{
|
||||
show_configure_options ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mc_args__force_colors)
|
||||
mc_global.tty.disable_colors = FALSE;
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
if (mc_args__nouse_subshell)
|
||||
mc_global.tty.use_subshell = FALSE;
|
||||
#endif /* HAVE_SUBSHELL_SUPPORT */
|
||||
|
||||
mc_setup_by_args (argc, argv);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gchar *
|
||||
mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_message,
|
||||
const gchar * help_str)
|
||||
{
|
||||
GString *buffer = g_string_new ("");
|
||||
GIConv conv = g_iconv_open (charset, "UTF-8");
|
||||
gchar *full_help_str = g_strdup_printf ("%s\n\n%s\n", error_message, help_str);
|
||||
|
||||
str_convert (conv, full_help_str, buffer);
|
||||
|
||||
g_free (full_help_str);
|
||||
g_iconv_close (conv);
|
||||
|
||||
return g_string_free (buffer, FALSE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
parse_mc_e_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error)
|
||||
{
|
||||
(void) option_name;
|
||||
(void) data;
|
||||
(void) error;
|
||||
|
||||
mc_global.mc_run_mode = MC_RUN_EDITOR;
|
||||
mc_run_param0 = g_strdup (value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
parse_mc_v_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error)
|
||||
{
|
||||
(void) option_name;
|
||||
(void) data;
|
||||
(void) error;
|
||||
|
||||
mc_global.mc_run_mode = MC_RUN_VIEWER;
|
||||
mc_run_param0 = g_strdup (value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/*** public functions ****************************************************************************/
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
mc_args_handle (int argc, char **argv, const char *translation_domain)
|
||||
{
|
||||
GError *error = NULL;
|
||||
const gchar *_system_codepage = str_detect_termencoding ();
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
if (!str_isutf8 (_system_codepage))
|
||||
bind_textdomain_codeset ("mc", "UTF-8");
|
||||
#endif
|
||||
|
||||
context = g_option_context_new (mc_args_add_usage_info ());
|
||||
|
||||
g_option_context_set_ignore_unknown_options (context, FALSE);
|
||||
|
||||
mc_args_add_extended_info_to_help ();
|
||||
|
||||
main_group = g_option_group_new ("main", _("Main options"), _("Main options"), NULL, NULL);
|
||||
|
||||
g_option_group_add_entries (main_group, argument_main_table);
|
||||
g_option_context_set_main_group (context, main_group);
|
||||
g_option_group_set_translation_domain (main_group, translation_domain);
|
||||
|
||||
terminal_group = g_option_group_new ("terminal", _("Terminal options"),
|
||||
_("Terminal options"), NULL, NULL);
|
||||
|
||||
g_option_group_add_entries (terminal_group, argument_terminal_table);
|
||||
g_option_context_add_group (context, terminal_group);
|
||||
g_option_group_set_translation_domain (terminal_group, translation_domain);
|
||||
|
||||
color_group = mc_args_new_color_group ();
|
||||
|
||||
g_option_group_add_entries (color_group, argument_color_table);
|
||||
g_option_context_add_group (context, color_group);
|
||||
g_option_group_set_translation_domain (color_group, translation_domain);
|
||||
|
||||
if (!g_option_context_parse (context, &argc, &argv, &error))
|
||||
{
|
||||
if (error != NULL)
|
||||
{
|
||||
gchar *full_help_str;
|
||||
gchar *help_str;
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,14,0)
|
||||
help_str = g_option_context_get_help (context, TRUE, NULL);
|
||||
#else
|
||||
help_str = g_strdup ("");
|
||||
#endif
|
||||
if (!str_isutf8 (_system_codepage))
|
||||
full_help_str =
|
||||
mc_args__convert_help_to_syscharset (_system_codepage, error->message,
|
||||
help_str);
|
||||
else
|
||||
full_help_str = g_strdup_printf ("%s\n\n%s\n", error->message, help_str);
|
||||
|
||||
fprintf (stderr, "%s", full_help_str);
|
||||
|
||||
g_free (help_str);
|
||||
g_free (full_help_str);
|
||||
g_error_free (error);
|
||||
}
|
||||
g_option_context_free (context);
|
||||
mc_args_clean_temp_help_strings ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_option_context_free (context);
|
||||
mc_args_clean_temp_help_strings ();
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
if (!str_isutf8 (_system_codepage))
|
||||
bind_textdomain_codeset ("mc", _system_codepage);
|
||||
#endif
|
||||
|
||||
return mc_args_process (argc, argv);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -15,7 +15,6 @@ extern gboolean mc_args__force_xterm;
|
||||
extern gboolean mc_args__nomouse;
|
||||
extern gboolean mc_args__force_colors;
|
||||
extern gboolean mc_args__nokeymap;
|
||||
extern gboolean mc_args__version;
|
||||
extern int mc_args__edit_start_line;
|
||||
extern char *mc_args__last_wd_file;
|
||||
extern char *mc_args__netfs_logfile;
|
||||
@ -24,7 +23,9 @@ extern int mc_args__debug_level;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
gboolean mc_args_handle (int argc, char **argv, const char *translation_domain);
|
||||
gboolean mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** error);
|
||||
gboolean mc_args_show_info (void);
|
||||
gboolean mc_setup_by_args (int argc, char **argv, GError ** error);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__ARGS_H */
|
||||
|
@ -3335,7 +3335,7 @@ diff_view (const char *file1, const char *file2, const char *label1, const char
|
||||
if ((error != 0) || (dview_dlg->state == DLG_CLOSED))
|
||||
destroy_dlg (dview_dlg);
|
||||
|
||||
return error;
|
||||
return error == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -3438,8 +3438,8 @@ dview_diff_cmd (void)
|
||||
vfs_path_free (file1);
|
||||
vfs_path_free (file0);
|
||||
|
||||
if (rv != 0)
|
||||
message (1, MSG_ERROR, _("Two files are needed to compare"));
|
||||
if (rv == 0)
|
||||
message (D_ERROR, MSG_ERROR, _("Two files are needed to compare"));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -942,9 +942,11 @@ prepend_cwd_on_local (const char *filename)
|
||||
/** Invoke the internal view/edit routine with:
|
||||
* the default processing and forcing the internal viewer/editor
|
||||
*/
|
||||
static void
|
||||
static gboolean
|
||||
mc_maybe_editor_or_viewer (void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
switch (mc_global.mc_run_mode)
|
||||
{
|
||||
#ifdef USE_INTERNAL_EDIT
|
||||
@ -953,7 +955,7 @@ mc_maybe_editor_or_viewer (void)
|
||||
vfs_path_t *param_vpath;
|
||||
|
||||
param_vpath = vfs_path_from_str (mc_run_param0);
|
||||
edit_file (param_vpath, mc_args__edit_start_line);
|
||||
ret = edit_file (param_vpath, mc_args__edit_start_line);
|
||||
vfs_path_free (param_vpath);
|
||||
}
|
||||
break;
|
||||
@ -965,16 +967,19 @@ mc_maybe_editor_or_viewer (void)
|
||||
vpath = prepend_cwd_on_local (mc_run_param0);
|
||||
view_file (vpath, 0, 1);
|
||||
vfs_path_free (vpath);
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
#ifdef USE_DIFF_VIEW
|
||||
case MC_RUN_DIFFVIEWER:
|
||||
diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
|
||||
ret = diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
|
||||
break;
|
||||
#endif /* USE_DIFF_VIEW */
|
||||
default:
|
||||
break;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return (ret != 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -1651,9 +1656,11 @@ quiet_quit_cmd (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** Run the main dialog that occupies the whole screen */
|
||||
void
|
||||
gboolean
|
||||
do_nc (void)
|
||||
{
|
||||
gboolean ret;
|
||||
|
||||
dlg_colors_t midnight_colors;
|
||||
|
||||
midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
|
||||
@ -1676,10 +1683,11 @@ do_nc (void)
|
||||
|
||||
/* Check if we were invoked as an editor or file viewer */
|
||||
if (mc_global.mc_run_mode != MC_RUN_FULL)
|
||||
mc_maybe_editor_or_viewer ();
|
||||
ret = mc_maybe_editor_or_viewer ();
|
||||
else
|
||||
{
|
||||
create_panels_and_run_mc ();
|
||||
ret = TRUE;
|
||||
|
||||
/* destroy_dlg destroys even current_panel->cwd_vpath, so we have to save a copy :) */
|
||||
if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
|
||||
@ -1704,6 +1712,8 @@ do_nc (void)
|
||||
|
||||
if ((quit & SUBSHELL_EXIT) == 0)
|
||||
clr_scr ();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -45,7 +45,7 @@ void load_hint (gboolean force);
|
||||
void change_panel (void);
|
||||
void save_cwds_stat (void);
|
||||
gboolean quiet_quit_cmd (void);
|
||||
void do_nc (void);
|
||||
gboolean do_nc (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
111
src/main.c
111
src/main.c
@ -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 ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -398,41 +413,67 @@ int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GError *error = NULL;
|
||||
gboolean isInitialized;
|
||||
int exit_code = EXIT_FAILURE;
|
||||
|
||||
/* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
|
||||
(void) setlocale (LC_ALL, "");
|
||||
(void) bindtextdomain ("mc", LOCALEDIR);
|
||||
(void) textdomain ("mc");
|
||||
|
||||
if (!events_init (&error))
|
||||
{
|
||||
fprintf (stderr, _("Failed to run:\n%s\n"), error->message);
|
||||
g_error_free (error);
|
||||
(void) mc_event_deinit (NULL);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Set up temporary directory */
|
||||
(void) mc_tmpdir ();
|
||||
|
||||
OS_Setup ();
|
||||
|
||||
/* do this before args parsing */
|
||||
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 (!mc_args_parse (&argc, &argv, "mc", &error))
|
||||
{
|
||||
startup_exit_falure:
|
||||
fprintf (stderr, _("Failed to run:\n%s\n"), error->message);
|
||||
g_error_free (error);
|
||||
g_free (shell);
|
||||
startup_exit_ok:
|
||||
str_uninit_strings ();
|
||||
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;
|
||||
goto startup_exit_ok;
|
||||
}
|
||||
|
||||
if (!events_init (&error))
|
||||
goto startup_exit_falure;
|
||||
|
||||
mc_config_init_config_paths (&error);
|
||||
if (error == NULL && mc_config_deprecated_dir_present ())
|
||||
mc_config_migrate_from_old_place (&error);
|
||||
if (error != NULL)
|
||||
{
|
||||
mc_event_deinit (NULL);
|
||||
goto startup_exit_falure;
|
||||
}
|
||||
|
||||
vfs_init ();
|
||||
vfs_plugins_init ();
|
||||
vfs_setup_work_dir ();
|
||||
|
||||
if (!mc_args_handle (argc, argv, "mc"))
|
||||
exit (EXIT_FAILURE);
|
||||
/* do this after vfs initialization due to mc_setctl() call in mc_setup_by_args() */
|
||||
if (!mc_setup_by_args (argc, argv, &error))
|
||||
{
|
||||
vfs_shut ();
|
||||
mc_event_deinit (NULL);
|
||||
goto startup_exit_falure;
|
||||
}
|
||||
|
||||
/* check terminal type
|
||||
* $TEMR must be set and not empty
|
||||
@ -481,20 +522,7 @@ main (int argc, char *argv[])
|
||||
|
||||
tty_init_colors (mc_global.tty.disable_colors, mc_args__force_colors);
|
||||
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
mc_skin_init (&error);
|
||||
if (error != NULL)
|
||||
{
|
||||
message (D_ERROR, _("Warning"), "%s", error->message);
|
||||
@ -502,6 +530,8 @@ main (int argc, char *argv[])
|
||||
error = NULL;
|
||||
}
|
||||
|
||||
mc_filehighlight = mc_fhl_new (TRUE);
|
||||
dlg_set_default_colors ();
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
/* Done here to ensure that the subshell doesn't */
|
||||
@ -530,8 +560,10 @@ main (int argc, char *argv[])
|
||||
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
|
||||
|
||||
/* Program main loop */
|
||||
if (!mc_global.widget.midnight_shutdown)
|
||||
do_nc ();
|
||||
if (mc_global.widget.midnight_shutdown)
|
||||
exit_code = EXIT_SUCCESS;
|
||||
else
|
||||
exit_code = do_nc () ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
|
||||
/* Save the tree store */
|
||||
(void) tree_store_save ();
|
||||
@ -600,20 +632,19 @@ main (int argc, char *argv[])
|
||||
g_free (mc_run_param0);
|
||||
g_free (mc_run_param1);
|
||||
|
||||
(void) mc_event_deinit (&error);
|
||||
|
||||
mc_config_deinit_config_paths ();
|
||||
|
||||
(void) mc_event_deinit (&error);
|
||||
if (error != NULL)
|
||||
{
|
||||
fprintf (stderr, _("\nFailed while close:\n%s\n"), error->message);
|
||||
g_error_free (error);
|
||||
exit (EXIT_FAILURE);
|
||||
exit_code = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
(void) putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
|
||||
|
||||
return 0;
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user