1998-02-27 07:54:42 +03:00
|
|
|
/* Main program for the Midnight Commander
|
2007-09-25 19:33:35 +04:00
|
|
|
Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
2009-05-20 16:34:33 +04:00
|
|
|
2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
2009-08-03 13:50:36 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
Written by: 1994, 1995, 1996, 1997 Miguel de Icaza
|
2010-04-30 17:31:06 +04:00
|
|
|
1994, 1995 Janne Kukonlehto
|
|
|
|
1997 Norbert Warmuth
|
2009-08-03 13:50:36 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
This program 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.
|
2009-08-03 13:50:36 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
This program 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
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file main.c
|
|
|
|
* \brief Source: this is a main module
|
|
|
|
*/
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
|
|
|
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <locale.h>
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-02-06 02:30:45 +03:00
|
|
|
#include <fcntl.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <sys/types.h>
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <sys/stat.h>
|
2009-02-27 14:54:26 +03:00
|
|
|
#include <sys/wait.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <unistd.h>
|
2010-04-30 17:31:06 +04:00
|
|
|
#include <pwd.h> /* for username in xterm title */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2009-05-09 19:17:57 +04:00
|
|
|
|
2010-01-08 17:47:19 +03:00
|
|
|
#include "lib/tty/tty.h"
|
2010-04-30 17:31:06 +04:00
|
|
|
#include "lib/tty/key.h" /* For init_key() */
|
|
|
|
#include "lib/tty/win.h" /* xterm_flag */
|
2010-02-15 14:21:30 +03:00
|
|
|
#include "lib/skin.h"
|
2010-01-21 16:06:15 +03:00
|
|
|
#include "lib/filehighlight.h"
|
2010-11-22 15:02:59 +03:00
|
|
|
#include "lib/fileloc.h"
|
2010-07-08 11:32:37 +04:00
|
|
|
#include "lib/strutil.h"
|
2010-11-22 14:45:18 +03:00
|
|
|
#include "lib/util.h"
|
2010-11-22 15:02:59 +03:00
|
|
|
#include "lib/vfs/mc-vfs/vfs.h" /* vfs_init(), vfs_shut() */
|
2010-01-21 13:30:08 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
#include "args.h"
|
|
|
|
#include "midnight.h" /* current_panel */
|
|
|
|
#include "treestore.h" /* tree_store_save */
|
|
|
|
#include "subshell.h"
|
|
|
|
#include "setup.h" /* save_setup() */
|
|
|
|
#include "layout.h" /* command_prompt */
|
|
|
|
#include "ext.h" /* flush_extension_file() */
|
|
|
|
#include "command.h" /* cmdline */
|
2010-04-30 17:31:06 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
#include "lib/charsets.h"
|
|
|
|
#include "selcodepage.h"
|
|
|
|
#endif /* HAVE_CHARSET */
|
2010-04-30 17:31:06 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
#include "consaver/cons.saver.h" /* console_flag */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
#include "main.h"
|
2002-10-31 07:31:52 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
2010-04-30 17:31:06 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
mc_fhl_t *mc_filehighlight;
|
2010-04-30 17:31:06 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/* Set when main loop should be terminated */
|
|
|
|
int quit = 0;
|
2009-11-08 13:49:27 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
/* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
|
|
|
|
int source_codepage = -1;
|
|
|
|
int default_source_codepage = -1;
|
|
|
|
int display_codepage = -1;
|
|
|
|
char *autodetect_codeset = NULL;
|
|
|
|
gboolean is_autodetect_codeset_enabled = FALSE;
|
|
|
|
#else
|
|
|
|
/* If true, allow characters in the range 160-255 */
|
|
|
|
int eight_bit_clean = 1;
|
|
|
|
/*
|
|
|
|
* If true, also allow characters in the range 128-159.
|
|
|
|
* This is reported to break on many terminals (xterm, qansi-m).
|
|
|
|
*/
|
|
|
|
int full_eight_bits = 0;
|
|
|
|
#endif /* !HAVE_CHARSET */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/*
|
|
|
|
* If utf-8 terminal utf8_display = 1
|
|
|
|
* Display bits set UTF-8
|
|
|
|
*/
|
|
|
|
int utf8_display = 0;
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/* If true use the internal viewer */
|
|
|
|
int use_internal_view = 1;
|
|
|
|
/* If set, use the builtin editor */
|
|
|
|
int use_internal_edit = 1;
|
2010-04-18 14:23:06 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
mc_run_mode_t mc_run_mode = MC_RUN_FULL;
|
|
|
|
char *mc_run_param0 = NULL;
|
|
|
|
char *mc_run_param1 = NULL;
|
2010-02-15 14:14:01 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/* Used so that widgets know if they are being destroyed or
|
|
|
|
shut down */
|
|
|
|
int midnight_shutdown = 0;
|
2009-10-24 12:58:02 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/* The user's shell */
|
|
|
|
char *shell = NULL;
|
2010-02-15 14:14:01 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/* The prompt */
|
|
|
|
const char *mc_prompt = NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/* mc_home: The home of MC - /etc/mc or defined by MC_DATADIR */
|
|
|
|
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;
|
2009-10-01 22:23:50 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/* Set to TRUE to suppress printing the last directory */
|
|
|
|
int print_last_revert = FALSE;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/* If set, then print to the given file the last directory we were at */
|
|
|
|
char *last_wd_string = NULL;
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
static void
|
2010-11-22 14:45:18 +03:00
|
|
|
check_codeset (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2010-11-22 14:45:18 +03:00
|
|
|
const char *current_system_codepage = NULL;
|
2009-09-21 16:34:15 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
current_system_codepage = str_detect_termencoding ();
|
2009-10-24 12:58:02 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
#ifdef HAVE_CHARSET
|
2010-04-30 17:31:06 +04:00
|
|
|
{
|
2010-11-22 14:45:18 +03:00
|
|
|
const char *_display_codepage;
|
2002-10-31 07:31:52 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
_display_codepage = get_codepage_id (display_codepage);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
if (strcmp (_display_codepage, current_system_codepage) != 0)
|
|
|
|
{
|
|
|
|
display_codepage = get_codepage_index (current_system_codepage);
|
|
|
|
if (display_codepage == -1)
|
|
|
|
display_codepage = 0;
|
2009-11-06 14:41:54 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
mc_config_set_string (mc_main_config, "Misc", "display_codepage", cp_display);
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2010-11-22 14:45:18 +03:00
|
|
|
#endif
|
2009-11-06 14:41:54 +03:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
utf8_display = str_isutf8 (current_system_codepage);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/** POSIX version. The only version we support. */
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
2001-06-15 02:33:00 +04:00
|
|
|
OS_Setup (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-06-30 21:49:40 +04:00
|
|
|
const char *shell_env = getenv ("SHELL");
|
2004-09-25 17:46:23 +04:00
|
|
|
const char *mc_libdir;
|
2009-06-30 21:49:40 +04:00
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
if ((shell_env == NULL) || (shell_env[0] == '\0'))
|
|
|
|
{
|
2004-09-23 18:07:44 +04:00
|
|
|
struct passwd *pwd;
|
|
|
|
pwd = getpwuid (geteuid ());
|
|
|
|
if (pwd != NULL)
|
2010-04-30 17:31:06 +04:00
|
|
|
shell = g_strdup (pwd->pw_shell);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
shell = g_strdup (shell_env);
|
2009-06-30 21:49:40 +04:00
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
if ((shell == NULL) || (shell[0] == '\0'))
|
|
|
|
{
|
|
|
|
g_free (shell);
|
|
|
|
shell = g_strdup ("/bin/sh");
|
2004-09-23 18:07:44 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-22 04:13:32 +04:00
|
|
|
/* This is the directory, where MC was installed, on Unix this is DATADIR */
|
|
|
|
/* and can be overriden by the MC_DATADIR environment variable */
|
2009-06-30 21:49:40 +04:00
|
|
|
mc_libdir = getenv ("MC_DATADIR");
|
2010-04-30 17:31:06 +04:00
|
|
|
if (mc_libdir != NULL)
|
|
|
|
{
|
|
|
|
mc_home = g_strdup (mc_libdir);
|
|
|
|
mc_home_alt = g_strdup (SYSCONFDIR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mc_home = g_strdup (SYSCONFDIR);
|
|
|
|
mc_home_alt = g_strdup (DATADIR);
|
1998-08-27 00:23:10 +04:00
|
|
|
}
|
2009-06-30 21:49:40 +04:00
|
|
|
|
|
|
|
/* This variable is used by the subshell */
|
|
|
|
home_dir = getenv ("HOME");
|
|
|
|
|
2010-11-22 15:02:59 +03:00
|
|
|
if (home_dir == NULL)
|
2010-04-30 17:31:06 +04:00
|
|
|
home_dir = mc_home;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
static void
|
|
|
|
sigchld_handler_no_subshell (int sig)
|
|
|
|
{
|
2003-02-27 08:09:35 +03:00
|
|
|
#ifdef __linux__
|
1998-02-27 07:54:42 +03:00
|
|
|
int pid, status;
|
|
|
|
|
|
|
|
if (!console_flag)
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
2002-10-31 07:31:52 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* COMMENT: if it were true that after the call to handle_console(..INIT)
|
|
|
|
the value of console_flag never changed, we could simply not install
|
|
|
|
this handler at all if (!console_flag && !use_subshell). */
|
|
|
|
|
|
|
|
/* That comment is no longer true. We need to wait() on a sigchld
|
|
|
|
handler (that's at least what the tarfs code expects currently). */
|
|
|
|
|
|
|
|
pid = waitpid (cons_saver_pid, &status, WUNTRACED | WNOHANG);
|
2002-10-31 07:31:52 +03:00
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
if (pid == cons_saver_pid)
|
|
|
|
{
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
if (WIFSTOPPED (status))
|
|
|
|
{
|
|
|
|
/* Someone has stopped cons.saver - restart it */
|
|
|
|
kill (pid, SIGCONT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* cons.saver has died - disable console saving */
|
|
|
|
handle_console (CONSOLE_DONE);
|
|
|
|
console_flag = 0;
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2005-02-08 22:59:45 +03:00
|
|
|
/* If we got here, some other child exited; ignore it */
|
2010-04-30 17:31:06 +04:00
|
|
|
#endif /* __linux__ */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2005-02-08 22:59:45 +03:00
|
|
|
(void) sig;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-15 01:58:56 +04:00
|
|
|
static void
|
1998-02-27 07:54:42 +03:00
|
|
|
init_sigchld (void)
|
|
|
|
{
|
|
|
|
struct sigaction sigchld_action;
|
|
|
|
|
|
|
|
sigchld_action.sa_handler =
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
2010-04-30 17:31:06 +04:00
|
|
|
use_subshell ? sigchld_handler :
|
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
|
|
|
sigchld_handler_no_subshell;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
sigemptyset (&sigchld_action.sa_mask);
|
|
|
|
|
|
|
|
#ifdef SA_RESTART
|
2001-08-18 19:18:56 +04:00
|
|
|
sigchld_action.sa_flags = SA_RESTART;
|
1998-02-27 07:54:42 +03:00
|
|
|
#else
|
2001-08-18 19:18:56 +04:00
|
|
|
sigchld_action.sa_flags = 0;
|
2010-04-30 17:31:06 +04:00
|
|
|
#endif /* !SA_RESTART */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
if (sigaction (SIGCHLD, &sigchld_action, NULL) == -1)
|
|
|
|
{
|
2001-08-18 19:18:56 +04:00
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
2010-04-30 17:31:06 +04:00
|
|
|
/*
|
|
|
|
* This may happen on QNX Neutrino 6, where SA_RESTART
|
|
|
|
* is defined but not implemented. Fallback to no subshell.
|
|
|
|
*/
|
|
|
|
use_subshell = 0;
|
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
2001-08-18 19:18:56 +04:00
|
|
|
}
|
2002-10-31 07:31:52 +03:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** Define this function for glib-style error handling */
|
|
|
|
GQuark
|
|
|
|
mc_main_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string (PACKAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
do_cd (const char *new_dir, enum cd_enum exact)
|
|
|
|
{
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
res = do_panel_cd (current_panel, new_dir, exact);
|
|
|
|
|
|
|
|
#if HAVE_CHARSET
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
const char *enc_name;
|
|
|
|
|
|
|
|
enc_name = vfs_get_encoding (current_panel->cwd);
|
|
|
|
if (enc_name != NULL)
|
|
|
|
current_panel->codepage = get_codepage_index (enc_name);
|
|
|
|
else
|
|
|
|
current_panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_CHARSET */
|
|
|
|
|
|
|
|
return res ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
|
|
|
int
|
|
|
|
load_prompt (int fd, void *unused)
|
|
|
|
{
|
|
|
|
(void) fd;
|
|
|
|
(void) unused;
|
|
|
|
|
|
|
|
if (!read_subshell_prompt ())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Don't actually change the prompt if it's invisible */
|
|
|
|
if (((Dlg_head *) top_dlg->data == midnight_dlg) && command_prompt)
|
|
|
|
{
|
|
|
|
char *tmp_prompt;
|
|
|
|
int prompt_len;
|
|
|
|
|
|
|
|
tmp_prompt = strip_ctrl_codes (subshell_prompt);
|
|
|
|
prompt_len = str_term_width1 (tmp_prompt);
|
|
|
|
|
|
|
|
/* Check for prompts too big */
|
|
|
|
if (COLS > 8 && prompt_len > COLS - 8)
|
|
|
|
{
|
|
|
|
prompt_len = COLS - 8;
|
|
|
|
tmp_prompt[prompt_len] = '\0';
|
|
|
|
}
|
|
|
|
mc_prompt = tmp_prompt;
|
|
|
|
label_set_text (the_prompt, mc_prompt);
|
2010-11-12 11:03:57 +03:00
|
|
|
input_set_origin ((WInput *) cmdline, prompt_len, COLS - prompt_len);
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* since the prompt has changed, and we are called from one of the
|
|
|
|
* tty_get_event channels, the prompt updating does not take place
|
|
|
|
* automatically: force a cursor update and a screen refresh
|
|
|
|
*/
|
|
|
|
update_cursor (midnight_dlg);
|
|
|
|
mc_refresh ();
|
|
|
|
}
|
2010-11-22 14:45:18 +03:00
|
|
|
update_subshell_prompt = TRUE;
|
2010-11-10 14:09:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** Show current directory in the xterm title */
|
|
|
|
void
|
|
|
|
update_xterm_title_path (void)
|
|
|
|
{
|
|
|
|
/* TODO: share code with midnight_get_title () */
|
|
|
|
|
|
|
|
const char *path;
|
|
|
|
char host[BUF_TINY];
|
|
|
|
char *p;
|
|
|
|
struct passwd *pw = NULL;
|
|
|
|
char *login = NULL;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
if (xterm_flag && xterm_title)
|
|
|
|
{
|
|
|
|
path = strip_home_and_password (current_panel->cwd);
|
|
|
|
res = gethostname (host, sizeof (host));
|
|
|
|
if (res)
|
|
|
|
{ /* On success, res = 0 */
|
|
|
|
host[0] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
host[sizeof (host) - 1] = '\0';
|
|
|
|
}
|
|
|
|
pw = getpwuid (getuid ());
|
|
|
|
if (pw)
|
|
|
|
{
|
|
|
|
login = g_strdup_printf ("%s@%s", pw->pw_name, host);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
login = g_strdup (host);
|
|
|
|
}
|
|
|
|
p = g_strdup_printf ("mc [%s]:%s", login, path);
|
|
|
|
fprintf (stdout, "\33]0;%s\7", str_term_form (p));
|
|
|
|
g_free (login);
|
|
|
|
g_free (p);
|
|
|
|
if (!alternate_plus_minus)
|
|
|
|
numeric_keypad_mode ();
|
|
|
|
fflush (stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
1999-04-17 02:02:09 +04:00
|
|
|
int
|
2002-10-31 07:31:52 +03:00
|
|
|
main (int argc, char *argv[])
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-02 14:45:48 +04:00
|
|
|
struct stat s;
|
|
|
|
char *mc_dir;
|
2009-09-28 18:04:25 +04:00
|
|
|
GError *error = NULL;
|
|
|
|
gboolean isInitialized;
|
2009-05-02 14:45:48 +04:00
|
|
|
|
1998-03-25 08:16:00 +03:00
|
|
|
/* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain ("mc", LOCALEDIR);
|
|
|
|
textdomain ("mc");
|
1998-12-30 05:51:01 +03:00
|
|
|
|
2002-09-11 08:58:24 +04:00
|
|
|
/* Set up temporary directory */
|
|
|
|
mc_tmpdir ();
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
OS_Setup ();
|
|
|
|
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
str_init_strings (NULL);
|
|
|
|
|
1998-08-27 00:23:10 +04:00
|
|
|
vfs_init ();
|
1998-12-02 08:18:20 +03:00
|
|
|
|
2010-05-12 10:29:57 +04:00
|
|
|
if (!mc_args_handle (argc, argv, "mc"))
|
|
|
|
exit (EXIT_FAILURE);
|
2005-07-21 00:29:08 +04:00
|
|
|
|
2009-07-12 14:22:41 +04:00
|
|
|
/* NOTE: This has to be called before tty_init or whatever routine
|
1998-02-27 07:54:42 +03:00
|
|
|
calls any define_sequence */
|
|
|
|
init_key ();
|
|
|
|
|
|
|
|
/* Must be done before installing the SIGCHLD handler [[FIXME]] */
|
|
|
|
handle_console (CONSOLE_INIT);
|
2002-10-31 07:31:52 +03:00
|
|
|
|
2002-11-16 00:41:57 +03:00
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
|
|
|
/* Don't use subshell when invoked as viewer or editor */
|
2010-03-21 13:57:33 +03:00
|
|
|
if (mc_run_mode != MC_RUN_FULL)
|
2010-04-30 17:31:06 +04:00
|
|
|
use_subshell = 0;
|
2002-11-16 00:41:57 +03:00
|
|
|
|
|
|
|
if (use_subshell)
|
2010-04-30 17:31:06 +04:00
|
|
|
subshell_get_console_attributes ();
|
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
2002-10-31 07:31:52 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Install the SIGCHLD handler; must be done before init_subshell() */
|
|
|
|
init_sigchld ();
|
2002-10-31 07:31:52 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* We need this, since ncurses endwin () doesn't restore the signals */
|
|
|
|
save_stop_handler ();
|
|
|
|
|
|
|
|
/* Must be done before init_subshell, to set up the terminal size: */
|
|
|
|
/* FIXME: Should be removed and LINES and COLS computed on subshell */
|
2009-09-01 15:05:01 +04:00
|
|
|
tty_init ((gboolean) mc_args__slow_terminal, (gboolean) mc_args__ugly_line_drawing);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
load_setup ();
|
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/* start check display_codepage and source_codepage */
|
|
|
|
check_codeset ();
|
|
|
|
|
2010-05-06 23:19:02 +04:00
|
|
|
/* Removing this from the X code let's us type C-c */
|
|
|
|
load_key_defs ();
|
|
|
|
|
|
|
|
load_keymap_defs ();
|
|
|
|
|
2009-09-01 15:05:01 +04:00
|
|
|
tty_init_colors (mc_args__disable_colors, mc_args__force_colors);
|
2010-04-30 17:31:06 +04:00
|
|
|
isInitialized = mc_skin_init (&error);
|
2009-09-04 18:22:49 +04:00
|
|
|
mc_filehighlight = mc_fhl_new (TRUE);
|
2009-05-30 21:39:02 +04:00
|
|
|
dlg_set_default_colors ();
|
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
if (!isInitialized)
|
|
|
|
{
|
clang: fixed useful warnings (-Wformat related)
../../mc/edit/editcmd.c:2519:50: error: field precision should have type 'int', but argument has type 'gsize' (aka 'unsigned long') [-Wformat]
match_expr = g_strdup_printf ("(^|\\s+|\\b)%.*s[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+", word_len, bufpos);
^ ~~~~~~~~
../../mc/edit/editcmd.c:2700:38: error: field precision should have type 'int', but argument has type 'gsize' (aka 'unsigned long') [-Wformat]
match_expr = g_strdup_printf ("%.*s", word_len, bufpos);
^ ~~~~~~~~
2 diagnostics generated.
make[2]: *** [editcmd.o] Error 1
make[2]: Target `all' not remade because of errors.
../../../mc/src/mcconfig/common.c:71:74: error: format string is not a string literal (potentially insecure) [-Wformat-security]
g_propagate_error (error, g_error_new (mc_main_error_quark() ,0, strerror(errno)));
^~~~~~~~~~~~~~~
../../../mc/src/mcconfig/common.c:83:74: error: format string is not a string literal (potentially insecure) [-Wformat-security]
g_propagate_error (error, g_error_new (mc_main_error_quark() ,0, strerror(errno)));
^~~~~~~~~~~~~~~
2 diagnostics generated.
make[3]: *** [libmcconfig_la-common.lo] Error 1
make[3]: Target `all' not remade because of errors.
../../mc/src/main.c:2165:41: error: format string is not a string literal (potentially insecure) [-Wformat-security]
message (D_ERROR, _("Warning"), error->message);
^~~~~~~~~~~~~~
1 diagnostic generated.
Signed-off-by: Sergei Trofimovich <slyfox@inbox.ru>
2009-12-06 16:32:16 +03:00
|
|
|
message (D_ERROR, _("Warning"), "%s", error->message);
|
2010-04-30 17:31:06 +04:00
|
|
|
g_error_free (error);
|
2009-09-28 18:04:25 +04:00
|
|
|
error = NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-02 14:45:48 +04:00
|
|
|
/* create home directory */
|
|
|
|
/* do it after the screen library initialization to show the error message */
|
2010-11-22 15:02:59 +03:00
|
|
|
mc_dir = g_build_filename (home_dir, MC_USERCONF_DIR, (char *) NULL);
|
2009-05-02 14:45:48 +04:00
|
|
|
canonicalize_pathname (mc_dir);
|
2010-04-30 17:31:06 +04:00
|
|
|
if ((stat (mc_dir, &s) != 0) && (errno == ENOENT) && mkdir (mc_dir, 0700) != 0)
|
|
|
|
message (D_ERROR, _("Warning"), _("Cannot create %s directory"), mc_dir);
|
2009-05-02 14:45:48 +04:00
|
|
|
g_free (mc_dir);
|
|
|
|
|
2001-02-10 07:28:56 +03:00
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
|
|
|
/* Done here to ensure that the subshell doesn't */
|
|
|
|
/* inherit the file descriptors opened below, etc */
|
|
|
|
if (use_subshell)
|
2010-04-30 17:31:06 +04:00
|
|
|
init_subshell ();
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Also done after init_subshell, to save any shell init file messages */
|
|
|
|
if (console_flag)
|
2010-04-30 17:31:06 +04:00
|
|
|
handle_console (CONSOLE_SAVE);
|
2002-10-31 07:31:52 +03:00
|
|
|
|
1998-04-01 02:36:24 +04:00
|
|
|
if (alternate_plus_minus)
|
2010-04-30 17:31:06 +04:00
|
|
|
application_keypad_mode ();
|
1999-03-30 10:09:56 +04:00
|
|
|
|
2001-09-08 01:15:04 +04:00
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
2010-04-30 17:31:06 +04:00
|
|
|
if (use_subshell)
|
|
|
|
{
|
|
|
|
mc_prompt = strip_ctrl_codes (subshell_prompt);
|
|
|
|
if (mc_prompt == NULL)
|
|
|
|
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
|
|
|
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Program main loop */
|
2003-03-05 23:18:11 +03:00
|
|
|
if (!midnight_shutdown)
|
2010-04-30 17:31:06 +04:00
|
|
|
do_nc ();
|
1999-04-06 07:49:34 +04:00
|
|
|
|
|
|
|
/* Save the tree store */
|
1999-04-17 02:02:09 +04:00
|
|
|
tree_store_save ();
|
2002-10-31 07:31:52 +03:00
|
|
|
|
2009-10-29 22:04:44 +03:00
|
|
|
free_keymap_defs ();
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Virtual File System shutdown */
|
|
|
|
vfs_shut ();
|
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
flush_extension_file (); /* does only free memory */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
mc_fhl_free (&mc_filehighlight);
|
2009-10-24 12:58:02 +04:00
|
|
|
mc_skin_deinit ();
|
2010-11-22 15:02:59 +03:00
|
|
|
tty_colors_done ();
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
tty_shutdown ();
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-22 15:02:59 +03:00
|
|
|
done_setup ();
|
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
if (console_flag && (quit & SUBSHELL_EXIT) == 0)
|
2010-04-30 17:31:06 +04:00
|
|
|
handle_console (CONSOLE_RESTORE);
|
1998-04-01 02:36:24 +04:00
|
|
|
if (alternate_plus_minus)
|
2010-04-30 17:31:06 +04:00
|
|
|
numeric_keypad_mode ();
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
signal (SIGCHLD, SIG_DFL); /* Disable the SIGCHLD handler */
|
2002-10-31 07:31:52 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (console_flag)
|
2010-04-30 17:31:06 +04:00
|
|
|
handle_console (CONSOLE_DONE);
|
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
if (mc_run_mode == MC_RUN_FULL && mc_args__last_wd_file != NULL
|
|
|
|
&& last_wd_string != NULL && !print_last_revert)
|
2010-04-30 17:31:06 +04:00
|
|
|
{
|
2010-11-22 14:45:18 +03:00
|
|
|
int last_wd_fd;
|
2010-04-30 17:31:06 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
last_wd_fd = open (mc_args__last_wd_file, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL,
|
|
|
|
S_IRUSR | S_IWUSR);
|
|
|
|
if (last_wd_fd != -1)
|
2010-04-30 17:31:06 +04:00
|
|
|
{
|
|
|
|
ssize_t ret1;
|
|
|
|
int ret2;
|
|
|
|
ret1 = write (last_wd_fd, last_wd_string, strlen (last_wd_string));
|
|
|
|
ret2 = close (last_wd_fd);
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (last_wd_string);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-05-21 02:01:10 +04:00
|
|
|
g_free (mc_home_alt);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mc_home);
|
2009-06-30 21:49:40 +04:00
|
|
|
g_free (shell);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
done_key ();
|
2010-06-08 23:23:00 +04:00
|
|
|
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
str_uninit_strings ();
|
|
|
|
|
2010-03-21 13:57:33 +03:00
|
|
|
g_free (mc_run_param0);
|
|
|
|
g_free (mc_run_param1);
|
1999-04-21 23:18:31 +04:00
|
|
|
|
2010-11-22 15:02:59 +03:00
|
|
|
putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
|
2009-02-26 00:53:52 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|