From 0046dbc336923aec0dbb1177385f5c48760aa38f Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 25 Sep 2009 11:54:43 +0300 Subject: [PATCH] Renamed global variable use_subshell into mc_args__use_subshell. Signed-off-by: Slava Zanko --- src/args.c | 15 +++++++++++---- src/args.h | 6 ++++++ src/cmd.c | 4 ++-- src/command.c | 5 +++-- src/execute.c | 15 ++++++++------- src/layout.c | 2 +- src/main.c | 20 ++++++++++---------- src/subshell.c | 37 +++++++++++++++---------------------- src/subshell.h | 5 ----- 9 files changed, 56 insertions(+), 53 deletions(-) diff --git a/src/args.c b/src/args.c index 02607a69a..9a547d08e 100644 --- a/src/args.c +++ b/src/args.c @@ -37,7 +37,6 @@ /*** external variables **************************************************************************/ extern int reset_hp_softkeys; -extern int use_subshell; extern char *mc_home; extern char *mc_home_alt; @@ -49,6 +48,14 @@ extern const char *edit_one_file; extern const char *view_one_file; /*** global variables ****************************************************************************/ +/* If using a subshell for evaluating commands this is true */ +gboolean mc_args__use_subshell = +#ifdef SUBSHELL_OPTIONAL +FALSE; +#else +TRUE; +#endif + /* If true, show version info and exit */ gboolean mc_args__version = FALSE; @@ -124,7 +131,7 @@ static const GOptionEntry argument_main_table[] = { #ifdef HAVE_SUBSHELL_SUPPORT { "subshell", 'U', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, - &use_subshell, + &mc_args__use_subshell, N_("Enables subshell support (default)"), NULL }, @@ -382,10 +389,10 @@ mc_args_process(void) #ifdef HAVE_SUBSHELL_SUPPORT if (mc_args__nouse_subshell) - use_subshell = 0; + mc_args__use_subshell = 0; if (mc_args__nouse_subshell) - use_subshell = 0; + mc_args__use_subshell = 0; #endif /* HAVE_SUBSHELL_SUPPORT */ return TRUE; diff --git a/src/args.h b/src/args.h index 4faaef860..269061d78 100644 --- a/src/args.h +++ b/src/args.h @@ -9,6 +9,12 @@ /*** global variables defined in .c file *********************************************************/ +#ifdef HAVE_SUBSHELL_SUPPORT +extern gboolean mc_args__use_subshell; +#else +#define mc_args__use_subshell FALSE +#endif /* not HAVE_SUBSHELL_SUPPORT */ + extern gboolean mc_args__force_xterm; extern gboolean mc_args__nomouse; extern gboolean mc_args__slow_terminal; diff --git a/src/cmd.c b/src/cmd.c index 58a22dfaa..5ea04f53d 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -62,7 +62,7 @@ #include "find.h" /* do_find() */ #include "hotlist.h" /* hotlist_cmd() */ #include "tree.h" /* tree_chdir() */ -#include "subshell.h" /* use_subshell */ +#include "args.h" /* mc_args__use_subshell */ #include "cons.saver.h" /* console_flag */ #include "dialog.h" /* Widget */ #include "wtools.h" /* message() */ @@ -903,7 +903,7 @@ view_other_cmd (void) { static int message_flag = TRUE; - if (!xterm_flag && !console_flag && !use_subshell && !output_starts_shell) { + if (!xterm_flag && !console_flag && !mc_args__use_subshell && !output_starts_shell) { if (message_flag) message (D_ERROR, MSG_ERROR, _(" Not an xterm or Linux console; \n" diff --git a/src/command.c b/src/command.c index b418ba424..827524ff7 100644 --- a/src/command.c +++ b/src/command.c @@ -33,6 +33,7 @@ #include #include "global.h" /* home_dir */ +#include "args.h" /* mc_args__use_subshell */ #include "../src/tty/tty.h" #include "widget.h" /* WInput */ #include "command.h" @@ -233,7 +234,7 @@ enter (WInput *cmdline) #ifdef HAVE_SUBSHELL_SUPPORT /* Check this early before we clean command line * (will be checked again by shell_execute) */ - if (use_subshell && subshell_state != INACTIVE) { + if (mc_args__use_subshell && subshell_state != INACTIVE) { message (D_ERROR, MSG_ERROR, _(" The shell is already running a command ")); return MSG_NOT_HANDLED; @@ -265,7 +266,7 @@ enter (WInput *cmdline) quiet_quit_cmd (); return MSG_HANDLED; } - if (use_subshell) + if (mc_args__use_subshell) load_prompt (0, 0); #endif } diff --git a/src/execute.c b/src/execute.c index 2dc41116e..61b978306 100644 --- a/src/execute.c +++ b/src/execute.c @@ -34,6 +34,7 @@ #include "main.h" #include "cons.saver.h" #include "subshell.h" +#include "args.h" #include "layout.h" #include "dialog.h" #include "wtools.h" @@ -130,12 +131,12 @@ do_execute (const char *shell, const char *command, int flags) if (console_flag) handle_console (CONSOLE_RESTORE); - if (!use_subshell && command && !(flags & EXECUTE_INTERNAL)) { + if (!mc_args__use_subshell && command && !(flags & EXECUTE_INTERNAL)) { printf ("%s%s\n", prompt, command); fflush (stdout); } #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell && !(flags & EXECUTE_INTERNAL)) { + if (mc_args__use_subshell && !(flags & EXECUTE_INTERNAL)) { do_update_prompt (); /* We don't care if it died, higher level takes care of this */ @@ -208,7 +209,7 @@ shell_execute (const char *command, int flags) } #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) + if (mc_args__use_subshell) if (subshell_state == INACTIVE) do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL); else @@ -258,7 +259,7 @@ toggle_panels (void) handle_console (CONSOLE_RESTORE); #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) { + if (mc_args__use_subshell) { new_dir_p = vfs_current_is_local ()? &new_dir : NULL; if (invoke_subshell (NULL, VISIBLY, new_dir_p)) quiet_quit_cmd (); /* User did `exit' or `logout': quit MC quietly */ @@ -293,7 +294,7 @@ toggle_panels (void) application_keypad_mode (); #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) { + if (mc_args__use_subshell) { load_prompt (0, 0); if (new_dir) do_possible_cd (new_dir); @@ -315,7 +316,7 @@ do_suspend_cmd (void) { pre_exec (); - if (console_flag && !use_subshell) + if (console_flag && !mc_args__use_subshell) handle_console (CONSOLE_RESTORE); #ifdef SIGTSTP @@ -334,7 +335,7 @@ do_suspend_cmd (void) } #endif /* SIGTSTP */ - if (console_flag && !use_subshell) + if (console_flag && !mc_args__use_subshell) handle_console (CONSOLE_SAVE); edition_post_exec (); diff --git a/src/layout.c b/src/layout.c index aa3f37eca..f73f822e1 100644 --- a/src/layout.c +++ b/src/layout.c @@ -61,7 +61,7 @@ #include "command.h" #include "main-widgets.h" #include "main.h" -#include "subshell.h" /* For use_subshell and resize_subshell() */ +#include "subshell.h" /* For resize_subshell() */ #include "tree.h" #include "menu.h" #include "strutil.h" diff --git a/src/main.c b/src/main.c index 69403de02..d1ebae75d 100644 --- a/src/main.c +++ b/src/main.c @@ -456,7 +456,7 @@ quit_cmd_internal (int quiet) } if (q) { #ifdef HAVE_SUBSHELL_SUPPORT - if (!use_subshell) + if (!mc_args__use_subshell) stop_dialogs (); else if ((q = exit_subshell ())) #endif @@ -485,7 +485,7 @@ void subshell_chdir (const char *directory) { #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) { + if (mc_args__use_subshell) { if (vfs_current_is_local ()) do_subshell_chdir (directory, 0, 1); } @@ -1382,7 +1382,7 @@ setup_mc (void) setup_panels (); #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) + if (mc_args__use_subshell) add_select_channel (subshell_pty, load_prompt, 0); #endif /* !HAVE_SUBSHELL_SUPPORT */ @@ -1906,7 +1906,7 @@ sigchld_handler_no_subshell (int sig) /* 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). */ + this handler at all if (!console_flag && !mc_args__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). */ @@ -1937,7 +1937,7 @@ init_sigchld (void) sigchld_action.sa_handler = #ifdef HAVE_SUBSHELL_SUPPORT - use_subshell ? sigchld_handler : + mc_args__use_subshell ? sigchld_handler : #endif /* HAVE_SUBSHELL_SUPPORT */ sigchld_handler_no_subshell; @@ -1955,7 +1955,7 @@ init_sigchld (void) * This may happen on QNX Neutrino 6, where SA_RESTART * is defined but not implemented. Fallback to no subshell. */ - use_subshell = 0; + mc_args__use_subshell = 0; #endif /* HAVE_SUBSHELL_SUPPORT */ } } @@ -2099,9 +2099,9 @@ main (int argc, char *argv[]) #ifdef HAVE_SUBSHELL_SUPPORT /* Don't use subshell when invoked as viewer or editor */ if (edit_one_file || view_one_file) - use_subshell = 0; + mc_args__use_subshell = 0; - if (use_subshell) + if (mc_args__use_subshell) subshell_get_console_attributes (); #endif /* HAVE_SUBSHELL_SUPPORT */ @@ -2144,7 +2144,7 @@ main (int argc, char *argv[]) #ifdef HAVE_SUBSHELL_SUPPORT /* Done here to ensure that the subshell doesn't */ /* inherit the file descriptors opened below, etc */ - if (use_subshell) + if (mc_args__use_subshell) init_subshell (); #endif /* HAVE_SUBSHELL_SUPPORT */ @@ -2162,7 +2162,7 @@ main (int argc, char *argv[]) application_keypad_mode (); #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) { + if (mc_args__use_subshell) { prompt = strip_ctrl_codes (subshell_prompt); if (!prompt) prompt = ""; diff --git a/src/subshell.c b/src/subshell.c index 120bd99a1..d4b3f4568 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -50,6 +50,7 @@ #endif /* HAVE_STROPTS_H */ #include "global.h" +#include "args.h" #include "../src/tty/tty.h" /* LINES */ #include "panel.h" /* current_panel */ #include "wtools.h" /* query_dialog() */ @@ -90,14 +91,6 @@ static int resize_tty (int fd); # define STDERR_FILENO 2 #endif -/* If using a subshell for evaluating commands this is true */ -int use_subshell = -#ifdef SUBSHELL_OPTIONAL -FALSE; -#else -TRUE; -#endif - /* File descriptors of the pseudoterminal used by the subshell */ int subshell_pty = 0; static int subshell_pty_slave = -1; @@ -369,7 +362,7 @@ check_sid (void) * * Possibly modifies the global variables: * subshell_type, subshell_alive, subshell_stopped, subshell_pid - * use_subshell - Is set to FALSE if we can't run the subshell + * mc_args__use_subshell - Is set to FALSE if we can't run the subshell * quit - Can be set to SUBSHELL_EXIT by the SIGCHLD handler */ @@ -383,10 +376,10 @@ init_subshell (void) #ifdef HAVE_GETSID switch (check_sid ()) { case 1: - use_subshell = FALSE; + mc_args__use_subshell = FALSE; return; case 2: - use_subshell = FALSE; + mc_args__use_subshell = FALSE; midnight_shutdown = 1; return; } @@ -410,7 +403,7 @@ init_subshell (void) else if (strstr (shell, "/fish")) subshell_type = FISH; else { - use_subshell = FALSE; + mc_args__use_subshell = FALSE; return; } @@ -422,14 +415,14 @@ init_subshell (void) if (subshell_pty == -1) { fprintf (stderr, "Cannot open master side of pty: %s\r\n", unix_error_string (errno)); - use_subshell = FALSE; + mc_args__use_subshell = FALSE; return; } subshell_pty_slave = pty_open_slave (pty_name); if (subshell_pty_slave == -1) { fprintf (stderr, "Cannot open slave side of pty %s: %s\r\n", pty_name, unix_error_string (errno)); - use_subshell = FALSE; + mc_args__use_subshell = FALSE; return; } @@ -446,7 +439,7 @@ init_subshell (void) if (mkfifo (tcsh_fifo, 0600) == -1) { fprintf (stderr, "mkfifo(%s) failed: %s\r\n", tcsh_fifo, unix_error_string (errno)); - use_subshell = FALSE; + mc_args__use_subshell = FALSE; return; } @@ -457,12 +450,12 @@ init_subshell (void) open (tcsh_fifo, O_RDWR)) == -1) { fprintf (stderr, _("Cannot open named pipe %s\n"), tcsh_fifo); perror (__FILE__": open"); - use_subshell = FALSE; + mc_args__use_subshell = FALSE; return; } } else /* subshell_type is BASH or ZSH */ if (pipe (subshell_pipe)) { perror (__FILE__": couldn't create pipe"); - use_subshell = FALSE; + mc_args__use_subshell = FALSE; return; } } @@ -520,11 +513,11 @@ init_subshell (void) subshell_state = RUNNING_COMMAND; tty_enable_interrupt_key (); if (!feed_subshell (QUIETLY, TRUE)) { - use_subshell = FALSE; + mc_args__use_subshell = FALSE; } tty_disable_interrupt_key (); if (!subshell_alive) - use_subshell = FALSE; /* Subshell died instantly, so don't use it */ + mc_args__use_subshell = FALSE; /* Subshell died instantly, so don't use it */ } @@ -594,7 +587,7 @@ int invoke_subshell (const char *command, int how, char **new_dir) g_free (pcwd); /* Restart the subshell if it has died by SIGHUP, SIGQUIT, etc. */ - while (!subshell_alive && !quit && use_subshell) + while (!subshell_alive && !quit && mc_args__use_subshell) init_subshell (); prompt_pos = 0; @@ -677,7 +670,7 @@ static int resize_tty (int fd) /* Resize subshell_pty */ void resize_subshell (void) { - if (use_subshell == 0) + if (! mc_args__use_subshell) return; resize_tty (subshell_pty); @@ -879,7 +872,7 @@ subshell_get_console_attributes (void) if (tcgetattr (STDOUT_FILENO, &shell_mode)) { fprintf (stderr, "Cannot get terminal settings: %s\r\n", unix_error_string (errno)); - use_subshell = FALSE; + mc_args__use_subshell = FALSE; return; } } diff --git a/src/subshell.h b/src/subshell.h index 6bb003a4a..d14a9b270 100644 --- a/src/subshell.h +++ b/src/subshell.h @@ -12,9 +12,6 @@ #ifdef HAVE_SUBSHELL_SUPPORT -/* If using a subshell for evaluating commands this is true */ -extern int use_subshell; - /* File descriptor of the pseudoterminal used by the subshell */ extern int subshell_pty; @@ -38,8 +35,6 @@ void do_subshell_chdir (const char *directory, int update_prompt, int reset_prom void subshell_get_console_attributes (void); void sigchld_handler (int sig); -#else -#define use_subshell 0 #endif /* not HAVE_SUBSHELL_SUPPORT */ #endif