From c68ce1efe4cb57cdd5114e2dc19bb4f7d7d9f4ce Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Sat, 26 Nov 2011 15:46:54 +0300 Subject: [PATCH] Use vfs_path_t in execute.c and subshell.c. Signed-off-by: Slava Zanko --- src/execute.c | 47 ++++++++++++++++++++--------------------------- src/subshell.c | 8 ++++---- src/subshell.h | 2 +- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/execute.c b/src/execute.c index 33392f747..4a0bf89cb 100644 --- a/src/execute.c +++ b/src/execute.c @@ -113,22 +113,14 @@ edition_pre_exec (void) #ifdef HAVE_SUBSHELL_SUPPORT static void -do_possible_cd (const char *new_dir) +do_possible_cd (const vfs_path_t * new_dir_vpath) { - vfs_path_t *new_dir_vpath; - - if (*new_dir == '\0') - new_dir_vpath = vfs_path_from_str (mc_config_get_home_dir()); - else - new_dir_vpath = vfs_path_from_str (new_dir); - if (!do_cd (new_dir_vpath, cd_exact)) message (D_ERROR, _("Warning"), _("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?")); - vfs_path_free (new_dir_vpath); } #endif /* HAVE_SUBSHELL_SUPPORT */ @@ -138,13 +130,13 @@ static void do_execute (const char *lc_shell, const char *command, int flags) { #ifdef HAVE_SUBSHELL_SUPPORT - char *new_dir = NULL; + vfs_path_t *new_dir_vpath = NULL; #endif /* HAVE_SUBSHELL_SUPPORT */ - char *old_vfs_dir = 0; + vfs_path_t *old_vfs_dir_vpath = NULL; if (!vfs_current_is_local ()) - old_vfs_dir = vfs_get_current_dir (); + old_vfs_dir_vpath = vfs_path_clone (vfs_get_raw_current_dir ()); if (mc_global.mc_run_mode == MC_RUN_FULL) save_cwds_stat (); @@ -163,7 +155,7 @@ do_execute (const char *lc_shell, const char *command, int flags) do_update_prompt (); /* We don't care if it died, higher level takes care of this */ - invoke_subshell (command, VISIBLY, old_vfs_dir ? NULL : &new_dir); + invoke_subshell (command, VISIBLY, old_vfs_dir_vpath != NULL ? NULL : &new_dir_vpath); } else #endif /* HAVE_SUBSHELL_SUPPORT */ @@ -201,19 +193,18 @@ do_execute (const char *lc_shell, const char *command, int flags) edition_post_exec (); #ifdef HAVE_SUBSHELL_SUPPORT - if (new_dir) - do_possible_cd (new_dir); + if (new_dir_vpath != NULL) + { + do_possible_cd (new_dir_vpath); + vfs_path_free (new_dir_vpath); + } #endif /* HAVE_SUBSHELL_SUPPORT */ - if (old_vfs_dir != NULL) + if (old_vfs_dir_vpath != NULL) { - vfs_path_t *vpath; - - vpath = vfs_path_from_str (old_vfs_dir); - mc_chdir (vpath); - vfs_path_free (vpath); - g_free (old_vfs_dir); + mc_chdir (old_vfs_dir_vpath); + vfs_path_free (old_vfs_dir_vpath); } if (mc_global.mc_run_mode == MC_RUN_FULL) @@ -322,8 +313,8 @@ void toggle_panels (void) { #ifdef HAVE_SUBSHELL_SUPPORT - char *new_dir = NULL; - char **new_dir_p; + vfs_path_t *new_dir_vpath = NULL; + vfs_path_t **new_dir_p; #endif /* HAVE_SUBSHELL_SUPPORT */ channels_down (); @@ -349,7 +340,7 @@ toggle_panels (void) #ifdef HAVE_SUBSHELL_SUPPORT if (mc_global.tty.use_subshell) { - new_dir_p = vfs_current_is_local ()? &new_dir : NULL; + new_dir_p = vfs_current_is_local () ? &new_dir_vpath : NULL; invoke_subshell (NULL, VISIBLY, new_dir_p); } else @@ -399,13 +390,15 @@ toggle_panels (void) if (mc_global.tty.use_subshell) { do_load_prompt (); - if (new_dir) - do_possible_cd (new_dir); + if (new_dir_vpath != NULL) + do_possible_cd (new_dir_vpath); if (mc_global.tty.console_flag != '\0' && output_lines) show_console_contents (output_start_y, LINES - mc_global.keybar_visible - output_lines - 1, LINES - mc_global.keybar_visible - 1); } + + vfs_path_free (new_dir_vpath); #endif /* HAVE_SUBSHELL_SUPPORT */ if (mc_global.mc_run_mode == MC_RUN_FULL) diff --git a/src/subshell.c b/src/subshell.c index 2bb9b61bc..e7acabf95 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -918,7 +918,7 @@ init_subshell (void) /* --------------------------------------------------------------------------------------------- */ int -invoke_subshell (const char *command, int how, char **new_dir) +invoke_subshell (const char *command, int how, vfs_path_t ** new_dir_vpath) { char *pcwd; @@ -926,7 +926,7 @@ invoke_subshell (const char *command, int how, char **new_dir) tcsetattr (STDOUT_FILENO, TCSANOW, &raw_mode); /* Make the subshell change to MC's working directory */ - if (new_dir != NULL) + if (new_dir_vpath != NULL) do_subshell_chdir (current_panel->cwd_vpath, TRUE, TRUE); if (command == NULL) /* The user has done "C-o" from MC */ @@ -961,8 +961,8 @@ invoke_subshell (const char *command, int how, char **new_dir) g_free (cwd_str); } - if (new_dir && subshell_alive && strcmp (subshell_cwd, pcwd)) - *new_dir = subshell_cwd; /* Make MC change to the subshell's CWD */ + if (new_dir_vpath != NULL && subshell_alive && strcmp (subshell_cwd, pcwd)) + *new_dir_vpath = vfs_path_from_str (subshell_cwd); /* Make MC change to the subshell's CWD */ g_free (pcwd); /* Restart the subshell if it has died by SIGHUP, SIGQUIT, etc. */ diff --git a/src/subshell.h b/src/subshell.h index 54433bfa6..49d2dbb39 100644 --- a/src/subshell.h +++ b/src/subshell.h @@ -45,7 +45,7 @@ extern gboolean update_subshell_prompt; /*** declarations of public functions ************************************************************/ void init_subshell (void); -int invoke_subshell (const char *command, int how, char **new_dir); +int invoke_subshell (const char *command, int how, vfs_path_t ** new_dir); int read_subshell_prompt (void); void do_update_prompt (void); int exit_subshell (void); -- 2.11.4.GIT