diff --git a/src/ChangeLog b/src/ChangeLog index ea83cbfda..0d09363ce 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-03-22 Adam Byrtek + + * subshell.c: Remove dead code (SYNC_PTY_SIDES). + (init_subshell_child): Remove dead code (initfile for TCSH). + (init_subshell): Use ZSH_VERSION environment variable to detect + ZSH. Use -g option to zsh to hide entries beginning with space + from history. Add space before ZSH precmd to hide it. + 2003-03-21 Andrew V. Samoilov * view.c (get_line_at): Return unreversed line for backward @@ -24,7 +32,7 @@ * key.c: Use fputs() instead of fprintf(). (func_XOpenDisplay) [HAVE_GMODULE]: Move to init_key_x11(). (get_modifier) [__QNXNTO__]: Use g_snprintf() instead of unsafe - sprintf(). + sprintf(). 2003-03-10 Pavel Roskin diff --git a/src/subshell.c b/src/subshell.c index 084143bda..07b5c8562 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -1,5 +1,3 @@ -/* {{{ Copyright notice */ - /* Concurrent shell support for the Midnight Commander Copyright (C) 1994, 1995 Dugan Porter @@ -17,13 +15,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* }}} */ - #include #ifdef HAVE_SUBSHELL_SUPPORT -/* {{{ Declarations */ - #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif @@ -53,7 +47,7 @@ #include "tty.h" /* LINES */ #include "panel.h" /* cpanel */ #include "wtools.h" /* query_dialog() */ -#include "main.h" /* update_prompt() */ +#include "main.h" /* do_update_prompt() */ #include "cons.saver.h" /* handle_console() */ #include "key.h" /* XCTRL */ #include "subshell.h" @@ -77,9 +71,6 @@ static int pty_open_master (char *pty_name); static int pty_open_slave (const char *pty_name); static int resize_tty (int fd); -/* }}} */ -/* {{{ Definitions */ - #ifndef STDIN_FILENO # define STDIN_FILENO 0 #endif @@ -127,9 +118,6 @@ char *subshell_prompt = NULL; /* For pipes */ enum {READ=0, WRITE=1}; - -/* Local variables */ - static char *pty_buffer; /* For reading/writing on the subshell's pty */ static int pty_buffer_size; /* The buffer grows as needed */ static int subshell_pipe[2]; /* To pass CWD info from the subshell to MC */ @@ -160,22 +148,6 @@ static struct termios raw_mode; /* FIXME: try to figure out why this had to become global */ static int prompt_pos; -/* }}} */ - -#ifdef HAVE_GRANTPT -# define SYNC_PTY_SIDES -#else -# define SYNC_PTY_SIDES -#endif - -#undef SYNC_PTY_SIDES - -#ifdef SYNC_PTY_SIDES -/* Handler for SIGUSR1 (used below), does nothing but accept the signal */ -static void sigusr1_handler (int sig) -{ -} -#endif /* * Prepare child process to running the shell and run it. @@ -195,7 +167,7 @@ static void init_subshell_child (const char *pty_name) setsid (); /* Get a fresh terminal session */ - /* {{{ Open the slave side of the pty: again */ + /* Open the slave side of the pty: again */ pty_slave = pty_open_slave (pty_name); /* This must be done before closing the master side of the pty, */ @@ -209,13 +181,7 @@ static void init_subshell_child (const char *pty_name) close (subshell_pty); -#ifdef SYNC_PTY_SIDES - /* Give our parent process (MC) the go-ahead */ - kill (getppid (), SIGUSR1); -#endif - - /* }}} */ - /* {{{ Make sure that it has become our controlling terminal */ + /* Make sure that it has become our controlling terminal */ /* Redundant on Linux and probably most systems, but just in case: */ @@ -223,8 +189,7 @@ static void init_subshell_child (const char *pty_name) ioctl (pty_slave, TIOCSCTTY, 0); #endif - /* }}} */ - /* {{{ Configure its terminal modes and window size */ + /* Configure its terminal modes and window size */ /* Set up the pty with the same termios flags as our own tty, plus */ /* TOSTOP, which keeps background processes from writing to the pty */ @@ -240,8 +205,7 @@ static void init_subshell_child (const char *pty_name) /* size of the real terminal as calculated by ncurses, if possible */ resize_tty (pty_slave); - /* }}} */ - /* {{{ Set up the subshell's environment and init file name */ + /* Set up the subshell's environment and init file name */ /* It simplifies things to change to our home directory here, */ /* and the user's startup file may do a `cd' command anyway */ @@ -273,14 +237,9 @@ static void init_subshell_child (const char *pty_name) break; - case TCSH: - init_file = ".mc/tcshrc"; - if (access (init_file, R_OK) == -1) - init_file += 3; - break; - - case ZSH: - break; + /* TODO: Find a way to pass initfile to TCSH and ZSH */ + case TCSH: case ZSH: + break; default: fprintf (stderr, __FILE__": unimplemented subshell type %d\n", @@ -288,8 +247,7 @@ static void init_subshell_child (const char *pty_name) _exit (FORK_FAILURE); } - /* }}} */ - /* {{{ Attach all our standard file descriptors to the pty */ + /* Attach all our standard file descriptors to the pty */ /* This is done just before the fork, because stderr must still */ /* be connected to the real tty during the above error messages; */ @@ -299,8 +257,7 @@ static void init_subshell_child (const char *pty_name) dup2 (pty_slave, STDOUT_FILENO); dup2 (pty_slave, STDERR_FILENO); - /* }}} */ - /* {{{ Execute the subshell at last */ + /* Execute the subshell at last */ close (subshell_pipe[READ]); close (pty_slave); /* These may be FD_CLOEXEC, but just in case... */ @@ -312,23 +269,19 @@ static void init_subshell_child (const char *pty_name) break; case TCSH: - execl (shell, "tcsh", NULL); /* What's the -rcfile equivalent? */ + execl (shell, "tcsh", NULL); break; case ZSH: - /* change from "+Z" to "-Z" by Michael Bramer - * (Debian-mc-maintainer) from a patch from - * Radovan Garabik - */ - execl (shell, "zsh", "-Z", NULL); + /* Use -g to exclude cmds beginning with space from history + * and -Z to use the line editor on non-interactive term */ + execl (shell, "zsh", "-Z", "-g", NULL); break; } /* If we get this far, everything failed miserably */ _exit (FORK_FAILURE); - - /* }}} */ } @@ -377,8 +330,6 @@ check_sid () #endif /* HAVE_GETSID */ -/* {{{ init_subshell */ - /* * Fork the subshell, and set up many, many things. * @@ -390,10 +341,9 @@ check_sid () void init_subshell (void) { - /* {{{ Local variables */ - /* This must be remembered across calls to init_subshell() */ static char pty_name[BUF_SMALL]; + char precmd[BUF_SMALL]; int pty_slave = -1; #ifdef HAVE_GETSID @@ -408,22 +358,15 @@ void init_subshell (void) } #endif /* HAVE_GETSID */ -#ifdef SYNC_PTY_SIDES - /* Used to wait for a SIGUSR1 signal from the subprocess */ - sigset_t sigusr1_mask, old_mask; -#endif - - /* }}} */ - /* Take the current (hopefully pristine) tty mode and make */ /* a raw mode based on it now, before we do anything else with it */ init_raw_mode (); if (subshell_pty == 0) /* First time through */ { - /* {{{ Find out what type of shell we have */ + /* Find out what type of shell we have */ - if (strstr (shell, "/zsh")) + if (strstr (shell, "/zsh") || getenv("ZSH_VERSION")) subshell_type = ZSH; else if (strstr (shell, "/tcsh")) subshell_type = TCSH; @@ -435,8 +378,7 @@ void init_subshell (void) return; } - /* }}} */ - /* {{{ Open a pty for talking to the subshell */ + /* Open a pty for talking to the subshell */ /* FIXME: We may need to open a fresh pty each time on SVR4 */ @@ -457,15 +399,12 @@ void init_subshell (void) return; } - - /* }}} */ - /* {{{ Initialise the pty's I/O buffer */ + /* Initialise the pty's I/O buffer */ pty_buffer_size = INITIAL_PTY_BUFFER_SIZE; pty_buffer = (char *) g_malloc (pty_buffer_size); - /* }}} */ - /* {{{ Create a pipe for receiving the subshell's CWD */ + /* Create a pipe for receiving the subshell's CWD */ if (subshell_type == TCSH) { @@ -496,21 +435,9 @@ void init_subshell (void) use_subshell = FALSE; return; } - - /* }}} */ } - /* {{{ Define a handler for the sigusr1 signal */ - -#ifdef SYNC_PTY_SIDES - sigemptyset (&sigusr1_mask); - sigaddset (&sigusr1_mask, SIGUSR1); - sigprocmask (SIG_BLOCK, &sigusr1_mask, &old_mask); - signal (SIGUSR1, sigusr1_handler); -#endif - - /* }}} */ - /* {{{ Fork the subshell */ + /* Fork the subshell */ subshell_alive = TRUE; subshell_stopped = FALSE; @@ -524,8 +451,6 @@ void init_subshell (void) exit (1); } - /* }}} */ - if (subshell_pid == 0) /* We are in the child process */ { init_subshell_child (pty_name); @@ -536,57 +461,30 @@ void init_subshell (void) close(pty_slave); } -#ifdef SYNC_PTY_SIDES - sigsuspend (&old_mask); - signal (SIGUSR1, SIG_DFL); - sigprocmask (SIG_SETMASK, &old_mask, NULL); - /* ...before installing our handler for SIGCHLD. */ -#endif - -#if 0 - /* {{{ Install our handler for SIGCHLD */ - - init_sigchld (); - - /* We could have received the SIGCHLD signal for the subshell - * before installing the init_sigchld */ - pid = waitpid (subshell_pid, &status, WUNTRACED | WNOHANG); - if (pid == subshell_pid){ - use_subshell = FALSE; - return; - } - - /* }}} */ -#endif - - /* {{{ Set up `precmd' or equivalent for reading the subshell's CWD */ + /* Set up `precmd' or equivalent for reading the subshell's CWD */ switch (subshell_type) { - char precmd[BUF_SMALL]; - - case BASH: + case BASH: g_snprintf (precmd, sizeof (precmd), " PROMPT_COMMAND='pwd>&%d;kill -STOP $$'\n", - subshell_pipe[WRITE]); - goto write_it; - - case ZSH: - g_snprintf (precmd, sizeof (precmd), "precmd(){ pwd>&%d;kill -STOP $$ }\n", - subshell_pipe[WRITE]); - goto write_it; - - case TCSH: + subshell_pipe[WRITE]); + break; + + case ZSH: + g_snprintf (precmd, sizeof (precmd), " precmd(){ pwd>&%d;kill -STOP $$ }\n", + subshell_pipe[WRITE]); + break; + + case TCSH: g_snprintf (precmd, sizeof (precmd), "set echo_style=both;" "alias precmd 'echo $cwd:q >>%s;kill -STOP $$'\n", tcsh_fifo); - - write_it: - write (subshell_pty, precmd, strlen (precmd)); + break; } + write (subshell_pty, precmd, strlen (precmd)); - /* }}} */ - /* {{{ Wait until the subshell has started up and processed the command */ + /* Wait until the subshell has started up and processed the command */ subshell_state = RUNNING_COMMAND; enable_interrupt_key (); @@ -596,11 +494,8 @@ void init_subshell (void) disable_interrupt_key (); if (!subshell_alive) use_subshell = FALSE; /* Subshell died instantly, so don't use it */ - - /* }}} */ } -/* }}} */ static void init_raw_mode () { @@ -627,15 +522,11 @@ static void init_raw_mode () } } -/* {{{ invoke_subshell */ int invoke_subshell (const char *command, int how, char **new_dir) { - /* {{{ Make the MC terminal transparent */ - + /* Make the MC terminal transparent */ tcsetattr (STDOUT_FILENO, TCSANOW, &raw_mode); - - /* }}} */ /* Make the subshell change to MC's working directory */ if (new_dir) @@ -676,13 +567,9 @@ int invoke_subshell (const char *command, int how, char **new_dir) return quit; } -/* }}} */ -/* {{{ read_subshell_prompt */ int read_subshell_prompt (void) { - /* {{{ Local variables */ - static int prompt_size = INITIAL_PROMPT_SIZE; int bytes = 0, i, rc = 0; struct timeval timeleft = {0, 0}; @@ -691,8 +578,6 @@ int read_subshell_prompt (void) FD_ZERO (&tmp); FD_SET (subshell_pty, &tmp); - /* }}} */ - if (subshell_prompt == NULL) /* First time through */ { subshell_prompt = (char *) g_malloc (prompt_size); @@ -703,8 +588,7 @@ int read_subshell_prompt (void) while (subshell_alive && (rc = select (subshell_pty + 1, &tmp, NULL, NULL, &timeleft))) { - /* {{{ Check for `select' errors */ - + /* Check for `select' errors */ if (rc == -1) { if (errno == EINTR) continue; @@ -715,11 +599,9 @@ int read_subshell_prompt (void) } } - /* }}} */ - bytes = read (subshell_pty, pty_buffer, pty_buffer_size); - /* {{{ Extract the prompt from the shell output */ + /* Extract the prompt from the shell output */ for (i=0; i