diff --git a/src/args.c b/src/args.c index 54a819a83..8044904e3 100644 --- a/src/args.c +++ b/src/args.c @@ -564,9 +564,6 @@ mc_args_process (int argc, char *argv[]) #ifdef HAVE_SUBSHELL_SUPPORT if (mc_args__nouse_subshell) use_subshell = 0; - - if (mc_args__nouse_subshell) - use_subshell = 0; #endif /* HAVE_SUBSHELL_SUPPORT */ mc_setup_by_args (argc, argv); diff --git a/src/boxes.c b/src/boxes.c index aee991cbf..884d4e57d 100644 --- a/src/boxes.c +++ b/src/boxes.c @@ -413,7 +413,7 @@ confirm_box (void) /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */ /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"), &confirm_history_cleanup), - /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|&Directory hotlist delete"), + /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|Di&rectory hotlist delete"), &confirm_directory_hotlist_delete), /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit), /* 5 */ QUICK_CHECKBOX (3, 46, 5, 13, N_("Confirmation|&Execute"), &confirm_execute), diff --git a/src/cmd.c b/src/cmd.c index dd58a9de3..52497e74d 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1245,7 +1245,7 @@ nice_cd (const char *text, const char *xtext, const char *help, else cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL); - if (do_panel_cd (MENU_PANEL, cd_path, 0)) + if (do_panel_cd (MENU_PANEL, cd_path, cd_parse_command)) directory_history_add (MENU_PANEL, (MENU_PANEL)->cwd); else message (D_ERROR, MSG_ERROR, _("Cannot chdir to %s"), cd_path); diff --git a/src/info.c b/src/info.c index 4d82a594c..bc1d3174c 100644 --- a/src/info.c +++ b/src/info.c @@ -127,7 +127,7 @@ info_show_info (struct WInfo *info) if (myfs_stats.nfree > 0 || myfs_stats.nodes > 0) tty_printf (_("Free nodes: %ld (%ld%%) of %ld"), (size_t) myfs_stats.nfree, - myfs_stats.total != 0 + myfs_stats.nodes != 0 ? 100 * (size_t) myfs_stats.nfree / (size_t) myfs_stats.nodes : 0, (size_t) myfs_stats.nodes); else diff --git a/src/main.c b/src/main.c index 88010820d..e3e4ffb0f 100644 --- a/src/main.c +++ b/src/main.c @@ -389,180 +389,12 @@ subshell_chdir (const char *directory) #endif /* HAVE_SUBSHELL_SUPPORT */ } -void -directory_history_add (struct WPanel *panel, const char *dir) -{ - char *tmp; - - tmp = g_strdup (dir); - strip_password (tmp, 1); - - panel->dir_history = list_append_unique (panel->dir_history, tmp); -} - -/* - * If we moved to the parent directory move the selection pointer to - * the old directory name; If we leave VFS dir, remove FS specificator. - * - * You do _NOT_ want to add any vfs aware code here. - */ -static const char * -get_parent_dir_name (const char *cwd, const char *lwd) -{ - size_t llen, clen; - - llen = strlen (lwd); - clen = strlen (cwd); - - if (llen > clen) - { - const char *p; - - p = strrchr (lwd, PATH_SEP); - - if ((p != NULL) - && (strncmp (cwd, lwd, (size_t) (p - lwd)) == 0) - && (clen == (size_t) (p - lwd) - || ((p == lwd) && (cwd[0] == PATH_SEP) && (cwd[1] == '\0')))) - return (p + 1); - } - - return NULL; -} - -/* - * Changes the current directory of the panel. - * Don't record change in the directory history. - */ -static int -_do_panel_cd (WPanel * panel, const char *new_dir, enum cd_enum cd_type) -{ - const char *directory; - char *olddir; - char temp[MC_MAXPATHLEN]; - char *translated_url; - - if (cd_type == cd_parse_command) - { - while (*new_dir == ' ') - new_dir++; - } - - olddir = g_strdup (panel->cwd); - new_dir = translated_url = vfs_translate_url (new_dir); - - /* Convert *new_path to a suitable pathname, handle ~user */ - - if (cd_type == cd_parse_command) - { - if (!strcmp (new_dir, "-")) - { - strcpy (temp, panel->lwd); - new_dir = temp; - } - } - directory = *new_dir ? new_dir : home_dir; - - if (mc_chdir (directory) == -1) - { - strcpy (panel->cwd, olddir); - g_free (olddir); - g_free (translated_url); - return 0; - } - g_free (translated_url); - - /* Success: save previous directory, shutdown status of previous dir */ - strcpy (panel->lwd, olddir); - free_completions (cmdline); - - mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2); - - vfs_release_path (olddir); - - subshell_chdir (panel->cwd); - - /* Reload current panel */ - panel_clean_dir (panel); - panel->count = - do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine, - panel->reverse, panel->case_sensitive, panel->exec_first, panel->filter); - try_to_select (panel, get_parent_dir_name (panel->cwd, olddir)); - load_hint (0); - panel->dirty = 1; - update_xterm_title_path (); - - g_free (olddir); - - return 1; -} - -/* - * Changes the current directory of the panel. - * Record change in the directory history. - */ -int -do_panel_cd (struct WPanel *panel, const char *new_dir, enum cd_enum cd_type) -{ - int r; - - r = _do_panel_cd (panel, new_dir, cd_type); - if (r) - directory_history_add (panel, panel->cwd); - return r; -} - int do_cd (const char *new_dir, enum cd_enum exact) { return (do_panel_cd (current_panel, new_dir, exact)); } -void -directory_history_next (WPanel * panel) -{ - GList *nextdir; - - nextdir = g_list_next (panel->dir_history); - - if (!nextdir) - return; - - if (_do_panel_cd (panel, (char *) nextdir->data, cd_exact)) - panel->dir_history = nextdir; -} - -void -directory_history_prev (WPanel * panel) -{ - GList *prevdir; - - prevdir = g_list_previous (panel->dir_history); - - if (!prevdir) - return; - - if (_do_panel_cd (panel, (char *) prevdir->data, cd_exact)) - panel->dir_history = prevdir; -} - -void -directory_history_list (WPanel * panel) -{ - char *s; - - s = show_hist (&panel->dir_history, &panel->widget); - - if (s != NULL) - { - if (_do_panel_cd (panel, s, cd_exact)) - directory_history_add (panel, panel->cwd); - else - message (D_ERROR, MSG_ERROR, _("Cannot change directory")); - g_free (s); - } -} - #ifdef HAVE_SUBSHELL_SUPPORT int load_prompt (int fd, void *unused) diff --git a/src/main.h b/src/main.h index 299625977..385b6d10e 100644 --- a/src/main.h +++ b/src/main.h @@ -110,7 +110,7 @@ enum cd_enum cd_exact }; -int do_cd (const char *new_dir, enum cd_enum cd_type); /* For find.c */ +int do_cd (const char *new_dir, enum cd_enum cd_type); void sort_cmd (void); void change_panel (void); void save_cwds_stat (void); @@ -136,9 +136,4 @@ void init_menu (void); char *remove_encoding_from_path (const char *); -struct WPanel; - -void directory_history_add (struct WPanel *panel, const char *dir); -int do_panel_cd (struct WPanel *panel, const char *new_dir, enum cd_enum cd_type); - #endif /* MC_MAIN_H */ diff --git a/src/panel.h b/src/panel.h index fc8daa97f..65bde5305 100644 --- a/src/panel.h +++ b/src/panel.h @@ -12,6 +12,7 @@ #include "dir.h" /* dir_list */ #include "dialog.h" /* Widget */ +#include "main.h" /* cd_enum */ #define selection(p) (&(p->dir.list[p->selected])) #define DEFAULT_USER_FORMAT "half type name | size | perm" @@ -140,9 +141,9 @@ void recalculate_panel_summary (WPanel *panel); void file_mark (WPanel *panel, int idx, int val); void do_file_mark (WPanel *panel, int idx, int val); -void directory_history_next (WPanel *panel); -void directory_history_prev (WPanel *panel); -void directory_history_list (WPanel *panel); +gboolean do_panel_cd (struct WPanel *panel, const char *new_dir, enum cd_enum cd_type); + +void directory_history_add (struct WPanel *panel, const char *dir); gsize panel_get_num_of_sortable_fields(void); const char **panel_get_sortable_fields(gsize *); diff --git a/src/screen.c b/src/screen.c index ae9f2476a..14257960d 100644 --- a/src/screen.c +++ b/src/screen.c @@ -34,10 +34,10 @@ #include "lib/global.h" #include "lib/tty/tty.h" -#include "lib/skin.h" -#include "lib/strescape.h" #include "lib/tty/mouse.h" /* For Gpm_Event */ #include "lib/tty/key.h" /* XCTRL and ALT macros */ +#include "lib/skin.h" +#include "lib/strescape.h" #include "lib/filehighlight.h" #include "lib/mcconfig.h" #include "lib/vfs/mc-vfs/vfs.h" @@ -2813,60 +2813,155 @@ panel_set_sort_type_by_id (WPanel * panel, const char *name) panel_set_sort_order (panel, panel->current_sort_field); } -typedef void (*panel_key_callback) (WPanel *); +/* + * If we moved to the parent directory move the selection pointer to + * the old directory name; If we leave VFS dir, remove FS specificator. + * + * You do _NOT_ want to add any vfs aware code here. + */ +static const char * +get_parent_dir_name (const char *cwd, const char *lwd) +{ + size_t llen, clen; + + llen = strlen (lwd); + clen = strlen (cwd); + + if (llen > clen) + { + const char *p; + + p = strrchr (lwd, PATH_SEP); + + if ((p != NULL) + && (strncmp (cwd, lwd, (size_t) (p - lwd)) == 0) + && (clen == (size_t) (p - lwd) + || ((p == lwd) && (cwd[0] == PATH_SEP) && (cwd[1] == '\0')))) + return (p + 1); + } + + return NULL; +} + +/* + * Changes the current directory of the panel. + * Don't record change in the directory history. + */ +static gboolean +_do_panel_cd (WPanel * panel, const char *new_dir, enum cd_enum cd_type) +{ + const char *directory; + char *olddir; + char temp[MC_MAXPATHLEN]; + char *translated_url; + + if (cd_type == cd_parse_command) + { + while (*new_dir == ' ') + new_dir++; + } + + olddir = g_strdup (panel->cwd); + new_dir = translated_url = vfs_translate_url (new_dir); + + /* Convert *new_path to a suitable pathname, handle ~user */ + + if (cd_type == cd_parse_command) + { + if (!strcmp (new_dir, "-")) + { + strcpy (temp, panel->lwd); + new_dir = temp; + } + } + directory = *new_dir ? new_dir : home_dir; + + if (mc_chdir (directory) == -1) + { + strcpy (panel->cwd, olddir); + g_free (olddir); + g_free (translated_url); + return FALSE; + } + g_free (translated_url); + + /* Success: save previous directory, shutdown status of previous dir */ + strcpy (panel->lwd, olddir); + free_completions (cmdline); + + mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2); + + vfs_release_path (olddir); + + subshell_chdir (panel->cwd); + + /* Reload current panel */ + panel_clean_dir (panel); + panel->count = + do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine, + panel->reverse, panel->case_sensitive, panel->exec_first, panel->filter); + try_to_select (panel, get_parent_dir_name (panel->cwd, olddir)); + load_hint (0); + panel->dirty = 1; + update_xterm_title_path (); + + g_free (olddir); + + return TRUE; +} + +/* + * Changes the current directory of the panel. + * Record change in the directory history. + */ +gboolean +do_panel_cd (struct WPanel *panel, const char *new_dir, enum cd_enum cd_type) +{ + gboolean r; + + r = _do_panel_cd (panel, new_dir, cd_type); + if (r) + directory_history_add (panel, panel->cwd); + return r; +} static void -cmd_do_enter (WPanel * wp) +directory_history_next (WPanel * panel) { - (void) do_enter (wp); + GList *nextdir; + + nextdir = g_list_next (panel->dir_history); + + if ((nextdir != NULL) && (_do_panel_cd (panel, (char *) nextdir->data, cd_exact))) + panel->dir_history = nextdir; } + static void -cmd_view_simple (WPanel * wp) +directory_history_prev (WPanel * panel) { - (void) wp; - view_simple_cmd (); + GList *prevdir; + + prevdir = g_list_previous (panel->dir_history); + + if ((prevdir != NULL) && (_do_panel_cd (panel, (char *) prevdir->data, cd_exact))) + panel->dir_history = prevdir; } + static void -cmd_edit_new (WPanel * wp) +directory_history_list (WPanel * panel) { - (void) wp; - edit_cmd_new (); -} -static void -cmd_copy_local (WPanel * wp) -{ - (void) wp; - copy_cmd_local (); -} -static void -cmd_rename_local (WPanel * wp) -{ - (void) wp; - rename_cmd_local (); -} -static void -cmd_delete_local (WPanel * wp) -{ - (void) wp; - delete_cmd_local (); -} -static void -cmd_select (WPanel * wp) -{ - (void) wp; - select_cmd (); -} -static void -cmd_unselect (WPanel * wp) -{ - (void) wp; - unselect_cmd (); -} -static void -cmd_reverse_selection (WPanel * wp) -{ - (void) wp; - reverse_selection_cmd (); + char *s; + + s = show_hist (&panel->dir_history, &panel->widget); + + if (s != NULL) + { + if (_do_panel_cd (panel, s, cd_exact)) + directory_history_add (panel, panel->cwd); + else + message (D_ERROR, MSG_ERROR, _("Cannot change directory")); + g_free (s); + } } static cb_ret_t @@ -2886,31 +2981,31 @@ panel_execute_cmd (WPanel * panel, unsigned long command) chdir_to_readlink (panel); break; case CK_PanelCmdCopyLocal: - cmd_copy_local (panel); + copy_cmd_local (); break; case CK_PanelCmdDeleteLocal: - cmd_delete_local (panel); + delete_cmd_local (); break; case CK_PanelCmdDoEnter: - cmd_do_enter (panel); + do_enter (panel); break; case CK_PanelCmdViewSimple: - cmd_view_simple (panel); + view_simple_cmd (); break; case CK_PanelCmdEditNew: - cmd_edit_new (panel); + edit_cmd_new (); break; case CK_PanelCmdRenameLocal: - cmd_rename_local (panel); + rename_cmd_local (); break; case CK_PanelCmdReverseSelection: - cmd_reverse_selection (panel); + reverse_selection_cmd (); break; case CK_PanelCmdSelect: - cmd_select (panel); + select_cmd (); break; case CK_PanelCmdUnselect: - cmd_unselect (panel); + unselect_cmd (); break; case CK_PanelNextPage: next_page (panel); @@ -3425,7 +3520,7 @@ set_panel_encoding (WPanel * panel) /* No translation */ g_free (init_translation_table (display_codepage, display_codepage)); cd_path = remove_encoding_from_path (panel->cwd); - do_panel_cd (panel, cd_path, 0); + do_panel_cd (panel, cd_path, cd_parse_command); g_free (cd_path); return; } @@ -3445,7 +3540,7 @@ set_panel_encoding (WPanel * panel) if (encoding != NULL) { cd_path = add_encoding_to_path (panel->cwd, encoding); - if (!do_panel_cd (panel, cd_path, 0)) + if (!do_panel_cd (panel, cd_path, cd_parse_command)) message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path); g_free (cd_path); } @@ -3571,6 +3666,17 @@ update_panels (int force_update, const char *current_file) ret = mc_chdir (panel->cwd); } +void +directory_history_add (struct WPanel *panel, const char *dir) +{ + char *tmp; + + tmp = g_strdup (dir); + strip_password (tmp, 1); + + panel->dir_history = list_append_unique (panel->dir_history, tmp); +} + gsize panel_get_num_of_sortable_fields (void) { @@ -3582,7 +3688,6 @@ panel_get_num_of_sortable_fields (void) return ret; } - const char ** panel_get_sortable_fields (gsize * array_size) { diff --git a/src/subshell.c b/src/subshell.c index 280cdae58..35fa942c6 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -110,12 +110,10 @@ static const char subshell_switch_key = XCTRL ('o') & 255; * INACTIVE: the default state; awaiting a command * ACTIVE: remain in the shell until the user hits `subshell_switch_key' * RUNNING_COMMAND: return to MC when the current command finishes */ - enum subshell_state_enum - subshell_state; +enum subshell_state_enum subshell_state; /* Holds the latest prompt captured from the subshell */ - char * - subshell_prompt = NULL; +char *subshell_prompt = NULL; /* Initial length of the buffer for the subshell's prompt */ #define INITIAL_PROMPT_SIZE 10 @@ -127,62 +125,53 @@ static const char subshell_switch_key = XCTRL ('o') & 255; #define PTY_BUFFER_SIZE BUF_SMALL /* Arbitrary; but keep it >= 80 */ /* For pipes */ - enum - { - READ = 0, WRITE = 1 }; +enum +{ + READ = 0, + WRITE = 1 +}; - static char - pty_buffer[PTY_BUFFER_SIZE] = "\0"; /* For reading/writing on the subshell's pty */ - static int - subshell_pipe[2]; /* To pass CWD info from the subshell to MC */ - static pid_t - subshell_pid = 1; /* The subshell's process ID */ - static char - subshell_cwd[MC_MAXPATHLEN + 1]; /* One extra char for final '\n' */ +static char pty_buffer[PTY_BUFFER_SIZE] = "\0"; /* For reading/writing on the subshell's pty */ +static int subshell_pipe[2]; /* To pass CWD info from the subshell to MC */ +static pid_t subshell_pid = 1; /* The subshell's process ID */ +static char subshell_cwd[MC_MAXPATHLEN + 1]; /* One extra char for final '\n' */ /* Subshell type (gleaned from the SHELL environment variable, if available) */ - static enum - { - BASH, - TCSH, - ZSH, - FISH - } subshell_type; +static enum +{ + BASH, + TCSH, + ZSH, + FISH +} subshell_type; /* Flag to indicate whether the subshell is ready for next command */ - static int - subshell_ready; +static int subshell_ready; /* The following two flags can be changed by the SIGCHLD handler. This is */ /* OK, because the `int' type is updated atomically on all known machines */ - static volatile int - subshell_alive, - subshell_stopped; +static volatile int subshell_alive, subshell_stopped; /* We store the terminal's initial mode here so that we can configure the pty similarly, and also so we can restore the real terminal to sanity if we have to exit abruptly */ - static struct termios - shell_mode; +static struct termios shell_mode; /* This is a transparent mode for the terminal where MC is running on */ /* It is used when the shell is active, so that the control signals */ /* are delivered to the shell pty */ - static struct termios - raw_mode; +static struct termios raw_mode; /* This counter indicates how many characters of prompt we have read */ /* FIXME: try to figure out why this had to become global */ - static int - prompt_pos; +static int prompt_pos; /* * Write all data, even if the write() call is interrupted. */ - static - ssize_t - write_all (int fd, const void *buf, size_t count) +static ssize_t +write_all (int fd, const void *buf, size_t count) { ssize_t ret; ssize_t written = 0;