2003-06-22 13:17:46 +04:00
|
|
|
/* Execution routines for GNU Midnight Commander
|
2007-09-25 19:33:35 +04:00
|
|
|
Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
|
2010-05-11 16:16:58 +04:00
|
|
|
|
2003-06-22 13:17:46 +04: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.
|
2010-05-11 16:16:58 +04:00
|
|
|
|
2003-06-22 13:17:46 +04: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. */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file execute.c
|
|
|
|
* \brief Source: execution routines
|
|
|
|
*/
|
|
|
|
|
2003-06-22 13:17:46 +04:00
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
2009-08-12 15:37:22 +04:00
|
|
|
#include <signal.h>
|
2009-03-07 15:23:15 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
2005-02-08 12:04:03 +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"
|
|
|
|
#include "lib/tty/key.h"
|
|
|
|
#include "lib/tty/win.h"
|
2011-02-15 16:44:17 +03:00
|
|
|
#include "lib/vfs/vfs.h"
|
2010-11-11 16:58:29 +03:00
|
|
|
#include "lib/util.h"
|
2010-11-12 11:03:57 +03:00
|
|
|
#include "lib/widget.h"
|
2009-05-09 19:17:57 +04:00
|
|
|
|
2010-11-22 17:15:28 +03:00
|
|
|
#include "filemanager/midnight.h"
|
|
|
|
#include "filemanager/layout.h" /* use_dash() */
|
2010-01-21 17:20:11 +03:00
|
|
|
#include "consaver/cons.saver.h"
|
2003-06-22 13:17:46 +04:00
|
|
|
#include "subshell.h"
|
2010-11-22 14:45:18 +03:00
|
|
|
#include "setup.h" /* clear_before_exec */
|
|
|
|
|
2003-06-22 13:17:46 +04:00
|
|
|
#include "execute.h"
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
int pause_after_run = pause_on_dumb_terminals;
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
edition_post_exec (void)
|
|
|
|
{
|
|
|
|
do_enter_ca_mode ();
|
|
|
|
|
|
|
|
/* FIXME: Missing on slang endwin? */
|
2009-05-31 16:23:10 +04:00
|
|
|
tty_reset_prog_mode ();
|
2009-06-02 21:40:37 +04:00
|
|
|
tty_flush_input ();
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
tty_keypad (TRUE);
|
2009-05-19 20:12:29 +04:00
|
|
|
tty_raw_mode ();
|
2003-06-22 13:17:46 +04:00
|
|
|
channels_up ();
|
|
|
|
enable_mouse ();
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.alternate_plus_minus)
|
2010-05-11 16:16:58 +04:00
|
|
|
application_keypad_mode ();
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
edition_pre_exec (void)
|
|
|
|
{
|
|
|
|
if (clear_before_exec)
|
2010-05-11 16:16:58 +04:00
|
|
|
clr_scr ();
|
|
|
|
else
|
|
|
|
{
|
2011-09-14 02:07:31 +04:00
|
|
|
if (!(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag))
|
2010-05-11 16:16:58 +04:00
|
|
|
printf ("\n\n");
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
channels_down ();
|
|
|
|
disable_mouse ();
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
tty_reset_shell_mode ();
|
|
|
|
tty_keypad (FALSE);
|
2009-06-02 21:40:37 +04:00
|
|
|
tty_reset_screen ();
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
numeric_keypad_mode ();
|
|
|
|
|
|
|
|
/* on xterms: maybe endwin did not leave the terminal on the shell
|
|
|
|
* screen page: do it now.
|
|
|
|
*
|
|
|
|
* Do not move this before endwin: in some systems rmcup includes
|
|
|
|
* a call to clear screen, so it will end up clearing the shell screen.
|
|
|
|
*/
|
|
|
|
do_exit_ca_mode ();
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2009-08-05 13:28:59 +04:00
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
|
|
|
static void
|
|
|
|
do_possible_cd (const char *new_dir)
|
|
|
|
{
|
|
|
|
if (!do_cd (new_dir, cd_exact))
|
2010-05-11 16:16:58 +04:00
|
|
|
message (D_ERROR, _("Warning"),
|
2010-05-15 18:45:13 +04:00
|
|
|
_("The Commander can't change to the directory that\n"
|
|
|
|
"the subshell claims you are in. Perhaps you have\n"
|
|
|
|
"deleted your working directory, or given yourself\n"
|
|
|
|
"extra access permissions with the \"su\" command?"));
|
2009-08-05 13:28:59 +04:00
|
|
|
}
|
2010-05-11 16:16:58 +04:00
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
2009-08-05 13:28:59 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-06-22 14:15:04 +04:00
|
|
|
static void
|
2009-10-30 04:12:04 +03:00
|
|
|
do_execute (const char *lc_shell, const char *command, int flags)
|
2003-06-22 13:17:46 +04:00
|
|
|
{
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
|
|
|
char *new_dir = NULL;
|
2010-05-11 16:16:58 +04:00
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
char *old_vfs_dir = 0;
|
|
|
|
|
|
|
|
if (!vfs_current_is_local ())
|
2011-04-29 15:13:29 +04:00
|
|
|
old_vfs_dir = vfs_get_current_dir ();
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.mc_run_mode == MC_RUN_FULL)
|
2010-05-11 16:16:58 +04:00
|
|
|
save_cwds_stat ();
|
2003-06-22 13:17:46 +04:00
|
|
|
pre_exec ();
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag != '\0')
|
2010-05-11 16:16:58 +04:00
|
|
|
handle_console (CONSOLE_RESTORE);
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
if (!mc_global.tty.use_subshell && command && !(flags & EXECUTE_INTERNAL))
|
2010-05-11 16:16:58 +04:00
|
|
|
{
|
|
|
|
printf ("%s%s\n", mc_prompt, command);
|
|
|
|
fflush (stdout);
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.tty.use_subshell && !(flags & EXECUTE_INTERNAL))
|
2010-05-11 16:16:58 +04:00
|
|
|
{
|
|
|
|
do_update_prompt ();
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2010-05-11 16:16:58 +04:00
|
|
|
/* We don't care if it died, higher level takes care of this */
|
|
|
|
invoke_subshell (command, VISIBLY, old_vfs_dir ? NULL : &new_dir);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
|
|
|
my_system (flags, lc_shell, command);
|
|
|
|
|
|
|
|
if (!(flags & EXECUTE_INTERNAL))
|
|
|
|
{
|
|
|
|
if ((pause_after_run == pause_always
|
2011-09-06 14:35:42 +04:00
|
|
|
|| (pause_after_run == pause_on_dumb_terminals && !mc_global.tty.xterm_flag
|
2011-09-14 02:07:31 +04:00
|
|
|
&& mc_global.tty.console_flag == '\0')) && quit == 0
|
2003-06-22 13:17:46 +04:00
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
2010-05-11 16:16:58 +04:00
|
|
|
&& subshell_state != RUNNING_COMMAND
|
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
printf (_("Press any key to continue..."));
|
|
|
|
fflush (stdout);
|
|
|
|
tty_raw_mode ();
|
|
|
|
get_key_code (0);
|
|
|
|
printf ("\r\n");
|
|
|
|
fflush (stdout);
|
|
|
|
}
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag != '\0')
|
2010-05-11 16:16:58 +04:00
|
|
|
{
|
2011-02-10 18:02:54 +03:00
|
|
|
if (output_lines && mc_global.keybar_visible)
|
2010-05-11 16:16:58 +04:00
|
|
|
{
|
|
|
|
putchar ('\n');
|
|
|
|
fflush (stdout);
|
|
|
|
}
|
|
|
|
}
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
|
|
|
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag != '\0')
|
2010-05-11 16:16:58 +04:00
|
|
|
handle_console (CONSOLE_SAVE);
|
2003-06-22 13:17:46 +04:00
|
|
|
edition_post_exec ();
|
|
|
|
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
|
|
|
if (new_dir)
|
2010-05-11 16:16:58 +04:00
|
|
|
do_possible_cd (new_dir);
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2010-05-11 16:16:58 +04:00
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2010-05-11 16:16:58 +04:00
|
|
|
if (old_vfs_dir)
|
|
|
|
{
|
|
|
|
mc_chdir (old_vfs_dir);
|
|
|
|
g_free (old_vfs_dir);
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.mc_run_mode == MC_RUN_FULL)
|
2010-05-11 16:16:58 +04:00
|
|
|
{
|
|
|
|
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
|
|
|
update_xterm_title_path ();
|
2010-05-07 20:54:15 +04:00
|
|
|
}
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
do_refresh ();
|
|
|
|
use_dash (TRUE);
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_suspend_cmd (void)
|
|
|
|
{
|
|
|
|
pre_exec ();
|
|
|
|
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag != '\0' && !mc_global.tty.use_subshell)
|
2010-11-10 14:09:42 +03:00
|
|
|
handle_console (CONSOLE_RESTORE);
|
|
|
|
|
|
|
|
#ifdef SIGTSTP
|
|
|
|
{
|
|
|
|
struct sigaction sigtstp_action;
|
|
|
|
|
|
|
|
/* Make sure that the SIGTSTP below will suspend us directly,
|
|
|
|
without calling ncurses' SIGTSTP handler; we *don't* want
|
|
|
|
ncurses to redraw the screen immediately after the SIGCONT */
|
|
|
|
sigaction (SIGTSTP, &startup_handler, &sigtstp_action);
|
|
|
|
|
|
|
|
kill (getpid (), SIGTSTP);
|
|
|
|
|
|
|
|
/* Restore previous SIGTSTP action */
|
|
|
|
sigaction (SIGTSTP, &sigtstp_action, NULL);
|
|
|
|
}
|
|
|
|
#endif /* SIGTSTP */
|
|
|
|
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag != '\0' && !mc_global.tty.use_subshell)
|
2010-11-10 14:09:42 +03:00
|
|
|
handle_console (CONSOLE_SAVE);
|
|
|
|
|
|
|
|
edition_post_exec ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/** Set up the terminal before executing a program */
|
|
|
|
|
|
|
|
void
|
|
|
|
pre_exec (void)
|
|
|
|
{
|
|
|
|
use_dash (FALSE);
|
|
|
|
edition_pre_exec ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Hide the terminal after executing a program */
|
|
|
|
void
|
|
|
|
post_exec (void)
|
|
|
|
{
|
|
|
|
edition_post_exec ();
|
|
|
|
use_dash (TRUE);
|
2011-09-19 13:53:54 +04:00
|
|
|
repaint_screen ();
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-06-22 13:17:46 +04:00
|
|
|
/* Executes a command */
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2003-06-22 13:17:46 +04:00
|
|
|
void
|
|
|
|
shell_execute (const char *command, int flags)
|
|
|
|
{
|
2004-11-26 14:14:07 +03:00
|
|
|
char *cmd = NULL;
|
2004-11-18 20:47:55 +03:00
|
|
|
|
2010-05-11 16:16:58 +04:00
|
|
|
if (flags & EXECUTE_HIDE)
|
|
|
|
{
|
|
|
|
cmd = g_strconcat (" ", command, (char *) NULL);
|
|
|
|
flags ^= EXECUTE_HIDE;
|
2004-11-26 14:14:07 +03:00
|
|
|
}
|
2004-11-18 20:47:55 +03:00
|
|
|
|
2003-06-22 13:17:46 +04:00
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.tty.use_subshell)
|
2010-05-11 16:16:58 +04:00
|
|
|
if (subshell_state == INACTIVE)
|
|
|
|
do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL);
|
|
|
|
else
|
2010-05-15 18:45:13 +04:00
|
|
|
message (D_ERROR, MSG_ERROR, _("The shell is already running a command"));
|
2003-06-22 13:17:46 +04:00
|
|
|
else
|
2010-05-11 16:16:58 +04:00
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
|
|
|
do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL);
|
2004-11-18 20:47:55 +03:00
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (cmd);
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
exec_shell (void)
|
|
|
|
{
|
|
|
|
do_execute (shell, 0, 0);
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
toggle_panels (void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
|
|
|
char *new_dir = NULL;
|
|
|
|
char **new_dir_p;
|
2010-05-11 16:16:58 +04:00
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
channels_down ();
|
|
|
|
disable_mouse ();
|
|
|
|
if (clear_before_exec)
|
2010-05-11 16:16:58 +04:00
|
|
|
clr_scr ();
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.alternate_plus_minus)
|
2010-05-11 16:16:58 +04:00
|
|
|
numeric_keypad_mode ();
|
2003-06-22 13:17:46 +04:00
|
|
|
#ifndef HAVE_SLANG
|
|
|
|
/* With slang we don't want any of this, since there
|
2009-06-07 10:48:51 +04:00
|
|
|
* is no raw_mode supported
|
2003-06-22 13:17:46 +04:00
|
|
|
*/
|
2009-05-31 16:23:10 +04:00
|
|
|
tty_reset_shell_mode ();
|
2010-05-11 16:16:58 +04:00
|
|
|
#endif /* !HAVE_SLANG */
|
2009-06-02 21:40:37 +04:00
|
|
|
tty_noecho ();
|
2009-05-31 16:23:10 +04:00
|
|
|
tty_keypad (FALSE);
|
2009-06-02 21:40:37 +04:00
|
|
|
tty_reset_screen ();
|
2003-06-22 13:17:46 +04:00
|
|
|
do_exit_ca_mode ();
|
2009-05-19 20:12:29 +04:00
|
|
|
tty_raw_mode ();
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag != '\0')
|
2010-05-11 16:16:58 +04:00
|
|
|
handle_console (CONSOLE_RESTORE);
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.tty.use_subshell)
|
2010-05-11 16:16:58 +04:00
|
|
|
{
|
2010-10-14 12:31:19 +04:00
|
|
|
new_dir_p = vfs_current_is_local ()? &new_dir : NULL;
|
2010-06-23 13:54:36 +04:00
|
|
|
invoke_subshell (NULL, VISIBLY, new_dir_p);
|
2010-05-11 16:16:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
2003-06-22 13:17:46 +04:00
|
|
|
{
|
2010-05-11 16:16:58 +04:00
|
|
|
if (output_starts_shell)
|
|
|
|
{
|
|
|
|
fprintf (stderr, _("Type `exit' to return to the Midnight Commander"));
|
|
|
|
fprintf (stderr, "\n\r\n\r");
|
|
|
|
|
|
|
|
my_system (EXECUTE_INTERNAL, shell, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
get_key_code (0);
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
2010-06-23 13:54:36 +04:00
|
|
|
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag != '\0')
|
2010-05-11 16:16:58 +04:00
|
|
|
handle_console (CONSOLE_SAVE);
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
do_enter_ca_mode ();
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
tty_reset_prog_mode ();
|
|
|
|
tty_keypad (TRUE);
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
/* Prevent screen flash when user did 'exit' or 'logout' within
|
|
|
|
subshell */
|
2010-06-23 13:54:36 +04:00
|
|
|
if ((quit & SUBSHELL_EXIT) != 0)
|
|
|
|
{
|
|
|
|
/* User did `exit' or `logout': quit MC */
|
|
|
|
if (quiet_quit_cmd ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
quit = 0;
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
|
|
|
/* restart subshell */
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.tty.use_subshell)
|
2010-06-23 13:54:36 +04:00
|
|
|
init_subshell ();
|
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
|
|
|
}
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
enable_mouse ();
|
|
|
|
channels_up ();
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.alternate_plus_minus)
|
2010-05-11 16:16:58 +04:00
|
|
|
application_keypad_mode ();
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.tty.use_subshell)
|
2010-05-11 16:16:58 +04:00
|
|
|
{
|
2010-11-22 14:45:18 +03:00
|
|
|
load_prompt (0, NULL);
|
2010-05-11 16:16:58 +04:00
|
|
|
if (new_dir)
|
|
|
|
do_possible_cd (new_dir);
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag != '\0' && output_lines)
|
2010-05-11 16:16:58 +04:00
|
|
|
show_console_contents (output_start_y,
|
2011-02-10 18:02:54 +03:00
|
|
|
LINES - mc_global.keybar_visible - output_lines -
|
|
|
|
1, LINES - mc_global.keybar_visible - 1);
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
2010-05-11 16:16:58 +04:00
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.mc_run_mode == MC_RUN_FULL)
|
2010-05-11 16:16:58 +04:00
|
|
|
{
|
|
|
|
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
|
|
|
update_xterm_title_path ();
|
2010-03-06 11:08:18 +03:00
|
|
|
}
|
2009-06-07 10:48:51 +04:00
|
|
|
repaint_screen ();
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-06-22 13:17:46 +04:00
|
|
|
|
2011-02-18 15:13:44 +03:00
|
|
|
/* event callback */
|
|
|
|
gboolean
|
|
|
|
execute_suspend (const gchar * event_group_name, const gchar * event_name,
|
|
|
|
gpointer init_data, gpointer data)
|
2003-06-22 13:17:46 +04:00
|
|
|
{
|
2011-02-18 15:13:44 +03:00
|
|
|
(void) event_group_name;
|
|
|
|
(void) event_name;
|
|
|
|
(void) init_data;
|
|
|
|
(void) data;
|
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.mc_run_mode == MC_RUN_FULL)
|
2010-05-11 16:16:58 +04:00
|
|
|
save_cwds_stat ();
|
2003-06-22 13:17:46 +04:00
|
|
|
do_suspend_cmd ();
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.mc_run_mode == MC_RUN_FULL)
|
2010-05-11 16:16:58 +04:00
|
|
|
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
2003-06-22 13:17:46 +04:00
|
|
|
do_refresh ();
|
2011-02-18 15:13:44 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
2003-06-22 13:17:46 +04:00
|
|
|
* Execute command on a filename that can be on VFS.
|
|
|
|
* Errors are reported to the user.
|
|
|
|
*/
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2003-06-22 13:17:46 +04:00
|
|
|
void
|
|
|
|
execute_with_vfs_arg (const char *command, const char *filename)
|
|
|
|
{
|
|
|
|
char *localcopy;
|
|
|
|
char *fn;
|
|
|
|
struct stat st;
|
|
|
|
time_t mtime;
|
2011-05-01 13:16:46 +04:00
|
|
|
vfs_path_t *vpath = vfs_path_from_str (filename);
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
/* Simplest case, this file is local */
|
2011-05-01 13:16:46 +04:00
|
|
|
if (!filename || vfs_file_is_local (vpath))
|
2010-05-11 16:16:58 +04:00
|
|
|
{
|
2011-05-01 14:30:58 +04:00
|
|
|
fn = vfs_path_to_str (vpath);
|
2010-05-11 16:16:58 +04:00
|
|
|
do_execute (command, fn, EXECUTE_INTERNAL);
|
2008-12-29 02:54:37 +03:00
|
|
|
g_free (fn);
|
2011-05-01 13:16:46 +04:00
|
|
|
vfs_path_free (vpath);
|
2010-05-11 16:16:58 +04:00
|
|
|
return;
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
2011-05-01 13:16:46 +04:00
|
|
|
vfs_path_free (vpath);
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
/* FIXME: Creation of new files on VFS is not supported */
|
|
|
|
if (!*filename)
|
2010-05-11 16:16:58 +04:00
|
|
|
return;
|
2003-06-22 13:17:46 +04:00
|
|
|
|
|
|
|
localcopy = mc_getlocalcopy (filename);
|
2010-05-11 16:16:58 +04:00
|
|
|
if (localcopy == NULL)
|
|
|
|
{
|
2010-05-15 18:45:13 +04:00
|
|
|
message (D_ERROR, MSG_ERROR, _("Cannot fetch a local copy of %s"), filename);
|
2010-05-11 16:16:58 +04:00
|
|
|
return;
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* filename can be an entry on panel, it can be changed by executing
|
|
|
|
* the command, so make a copy. Smarter VFS code would make the code
|
|
|
|
* below unnecessary.
|
|
|
|
*/
|
2009-02-06 01:40:32 +03:00
|
|
|
fn = g_strdup (filename);
|
2003-06-22 13:17:46 +04:00
|
|
|
mc_stat (localcopy, &st);
|
|
|
|
mtime = st.st_mtime;
|
|
|
|
do_execute (command, localcopy, EXECUTE_INTERNAL);
|
|
|
|
mc_stat (localcopy, &st);
|
|
|
|
mc_ungetlocalcopy (fn, localcopy, mtime != st.st_mtime);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (localcopy);
|
|
|
|
g_free (fn);
|
2003-06-22 13:17:46 +04:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|