From 45073c35e797dcb37c6790c368b83a7004e27509 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 15 Feb 2010 11:14:01 +0000 Subject: [PATCH 1/2] Ticket #1992: incorrect sturtup of MC with some special paths. Problem description: 1. Run mc as mc /#ftp:user@server 2. If FTP server asks password, MC shows the password dialog window. 3. If type the first symbol in input line, MC crashes. Bug cause: MC asks ftp password before initialize of input line keybindings. Solution: Reimplemented MC startup sequence. Signed-off-by: Andrew Borodin --- src/main.c | 100 +++++++++++++++++++++++----------------------------- src/main.h | 2 ++ src/setup.c | 3 ++ 3 files changed, 50 insertions(+), 55 deletions(-) diff --git a/src/main.c b/src/main.c index 1c0089325..2717726e1 100644 --- a/src/main.c +++ b/src/main.c @@ -937,9 +937,7 @@ create_panels (void) int current_index; int other_index; panel_view_mode_t current_mode, other_mode; - char original_dir[1024]; - - original_dir[0] = 0; + char original_dir[BUF_1K] = "\0"; if (boot_current_is_left) { current_index = 0; @@ -967,7 +965,7 @@ create_panels (void) /* The other panel */ if (other_dir) { - if (original_dir[0]) + if (original_dir[0] != '\0') translated_mc_chdir (original_dir); translated_mc_chdir (other_dir); } @@ -1388,18 +1386,6 @@ midnight_execute_cmd (Widget *sender, unsigned long command) return res; } -static void -setup_pre (void) -{ - /* Call all the inits */ - -#ifdef HAVE_SLANG - tty_display_8bit (full_eight_bits != 0); -#else - tty_display_8bit (eight_bit_clean != 0); -#endif -} - static void init_xterm_support (void) { @@ -1448,9 +1434,11 @@ init_xterm_support (void) static void setup_mc (void) { - setup_pre (); - create_panels (); - setup_panels (); +#ifdef HAVE_SLANG + tty_display_8bit (full_eight_bits != 0); +#else + tty_display_8bit (eight_bit_clean != 0); +#endif #ifdef HAVE_SUBSHELL_SUPPORT if (use_subshell) @@ -1552,6 +1540,9 @@ midnight_callback (Dlg_head *h, Widget *sender, unsigned long command; switch (msg) { + case DLG_INIT: + setup_panels (); + return MSG_HANDLED; case DLG_DRAW: load_hint (1); @@ -1570,6 +1561,12 @@ midnight_callback (Dlg_head *h, Widget *sender, case DLG_IDLE: /* We only need the first idle event to show user menu after start */ set_idle_proc (h, 0); + + if (boot_current_is_left) + dlg_select_widget (get_panel_widget (0)); + else + dlg_select_widget (get_panel_widget (1)); + if (auto_menu) midnight_execute_cmd (NULL, CK_UserMenuCmd); return MSG_HANDLED; @@ -1777,15 +1774,18 @@ load_hint (int force) } static void -setup_panels_and_run_mc (void) +create_panels_and_run_mc (void) { midnight_dlg->get_shortcut = midnight_get_shortcut; + create_panels (); + add_widget (midnight_dlg, the_menubar); init_menu (); add_widget (midnight_dlg, get_panel_widget (0)); add_widget (midnight_dlg, get_panel_widget (1)); + add_widget (midnight_dlg, the_hint); add_widget (midnight_dlg, cmdline); add_widget (midnight_dlg, the_prompt); @@ -1793,11 +1793,6 @@ setup_panels_and_run_mc (void) add_widget (midnight_dlg, the_bar); midnight_set_buttonbar (the_bar); - if (boot_current_is_left) - dlg_select_widget (get_panel_widget (0)); - else - dlg_select_widget (get_panel_widget (1)); - /* Run the Midnight Commander if no file was specified in the command line */ run_dlg (midnight_dlg); } @@ -1807,45 +1802,39 @@ static char * prepend_cwd_on_local (const char *filename) { char *d; - int l; + size_t l; - if (vfs_file_is_local (filename)) { - if (*filename == PATH_SEP) /* an absolute pathname */ - return g_strdup (filename); - d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2); - mc_get_current_wd (d, MC_MAXPATHLEN); - l = strlen (d); - d[l++] = PATH_SEP; - strcpy (d + l, filename); - canonicalize_pathname (d); - return d; - } else + if (!vfs_file_is_local (filename) + || g_path_is_absolute (filename)) return g_strdup (filename); + + d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2); + mc_get_current_wd (d, MC_MAXPATHLEN); + l = strlen (d); + d[l++] = PATH_SEP; + strcpy (d + l, filename); + canonicalize_pathname (d); + return d; } -static int +/* Invoke the internal view/edit routine with: + * the default processing and forcing the internal viewer/editor + */ +static void mc_maybe_editor_or_viewer (void) { - if (!(view_one_file || edit_one_file)) - return 0; - - /* Invoke the internal view/edit routine with: - * the default processing and forcing the internal viewer/editor - */ - if (view_one_file) { - char *path = NULL; + if (view_one_file != NULL) { + char *path; path = prepend_cwd_on_local (view_one_file); view_file (path, 0, 1); g_free (path); } #ifdef USE_INTERNAL_EDIT - else { + else edit_file (edit_one_file, edit_one_file_start_line); - } #endif /* USE_INTERNAL_EDIT */ midnight_shutdown = 1; done_mc (); - return 1; } /* Run the main dialog that occupies the whole screen */ @@ -1863,7 +1852,7 @@ do_nc (void) midnight_dlg = create_dlg (0, 0, LINES, COLS, midnight_colors, midnight_callback, "[main]", NULL, DLG_WANT_IDLE); - if (view_one_file || edit_one_file) + if ((view_one_file != NULL) || (edit_one_file != NULL)) setup_dummy_mc (); else setup_mc (); @@ -1896,8 +1885,10 @@ do_nc (void) help_map = (global_keymap_t *) help_keymap->data; /* Check if we were invoked as an editor or file viewer */ - if (!mc_maybe_editor_or_viewer ()) { - setup_panels_and_run_mc (); + if ((view_one_file != NULL) || (edit_one_file != NULL)) + mc_maybe_editor_or_viewer (); + else { + create_panels_and_run_mc (); /* Program end */ midnight_shutdown = 1; @@ -2149,7 +2140,7 @@ 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) + if ((view_one_file != NULL) || (edit_one_file != NULL)) use_subshell = 0; if (use_subshell) @@ -2216,12 +2207,11 @@ main (int argc, char *argv[]) if (use_subshell) { mc_prompt = strip_ctrl_codes (subshell_prompt); if (mc_prompt == NULL) - mc_prompt = ""; + mc_prompt = (geteuid () == 0) ? "# " : "$ "; } else #endif /* HAVE_SUBSHELL_SUPPORT */ mc_prompt = (geteuid () == 0) ? "# " : "$ "; - /* Program main loop */ if (!midnight_shutdown) do_nc (); diff --git a/src/main.h b/src/main.h index cc35a8d6c..a21d21333 100644 --- a/src/main.h +++ b/src/main.h @@ -29,6 +29,8 @@ struct WButtonBar; void midnight_set_buttonbar (struct WButtonBar *b); /* See main.c for details on these variables */ +extern const char *edit_one_file; +extern const char *view_one_file; extern int mark_moves_down; extern int auto_menu; extern int pause_after_run; diff --git a/src/setup.c b/src/setup.c index 97d3b5025..2c9d2c32b 100644 --- a/src/setup.c +++ b/src/setup.c @@ -344,6 +344,9 @@ save_panel_types (void) { panel_view_mode_t type; + if ((view_one_file != NULL) || (edit_one_file != NULL)) + return; + if (!mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, "auto_save_setup_panels", auto_save_setup)) return; From a78115ad8ee16a56e40df7e11b2e68fcbdb01a15 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 15 Feb 2010 11:21:30 +0000 Subject: [PATCH 2/2] Fixed variable declarations and added missing includes. Signed-off-by: Andrew Borodin --- lib/tty/color.h | 1 + lib/tty/tty.c | 5 +++++ lib/tty/tty.h | 2 ++ src/args.c | 23 ++++++++--------------- src/main.c | 8 ++------ src/main.h | 2 +- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/lib/tty/color.h b/lib/tty/color.h index 0f2593276..c204d0a2b 100644 --- a/lib/tty/color.h +++ b/lib/tty/color.h @@ -20,6 +20,7 @@ # include "tty-ncurses.h" #endif +/* colors specified on the command line: they override any other setting */ extern char *command_line_colors; void tty_init_colors (gboolean disable, gboolean force); diff --git a/lib/tty/tty.c b/lib/tty/tty.c index 3c869e19e..da23d90db 100644 --- a/lib/tty/tty.c +++ b/lib/tty/tty.c @@ -43,6 +43,11 @@ /*** global variables **************************************************/ +/* If true program softkeys (HP terminals only) on startup and after every + command ran in the subshell to the description found in the termcap/terminfo + database */ +int reset_hp_softkeys = 0; + /* If true lines are drown by spaces */ gboolean slow_tty = FALSE; diff --git a/lib/tty/tty.h b/lib/tty/tty.h index e3133e3b7..72b7941bc 100644 --- a/lib/tty/tty.h +++ b/lib/tty/tty.h @@ -21,6 +21,8 @@ /* {{{ Input }}} */ +extern int reset_hp_softkeys; + extern void tty_init (gboolean slow, gboolean ugly_lines); extern void tty_shutdown (void); diff --git a/src/args.c b/src/args.c index 203650de3..128469522 100644 --- a/src/args.c +++ b/src/args.c @@ -25,29 +25,22 @@ */ #include +#include #include - #include "lib/global.h" #include "lib/tty/tty.h" +#include "lib/tty/color.h" /* command_line_colors */ #include "lib/strutil.h" -#include "src/args.h" +#include "src/main.h" #include "src/textconf.h" +#include "subshell.h" /* use_subshell */ + +#include "src/args.h" /*** external variables **************************************************************************/ -extern int reset_hp_softkeys; -extern int use_subshell; - -extern char *mc_home; -extern char *mc_home_alt; - -/* colors specified on the command line: they override any other setting */ -extern char *command_line_colors; - -extern const char *edit_one_file; -extern const char *view_one_file; /*** global variables ****************************************************************************/ /* If true, show version info and exit */ @@ -93,11 +86,11 @@ int mc_args__debug_level = 0; static GOptionContext *context; - static gboolean mc_args__nouse_subshell = FALSE; static gboolean mc_args__show_datadirs = FALSE; -GOptionGroup *main_group; +static GOptionGroup *main_group; + static const GOptionEntry argument_main_table[] = { /* generic options */ { diff --git a/src/main.c b/src/main.c index 2717726e1..27e34b768 100644 --- a/src/main.c +++ b/src/main.c @@ -42,11 +42,12 @@ #include "lib/global.h" #include "lib/tty/tty.h" -#include "lib/skin.h" #include "lib/tty/mouse.h" #include "lib/tty/key.h" /* For init_key() */ #include "lib/tty/win.h" /* xterm_flag */ +#include "lib/skin.h" + #include "lib/mcconfig.h" #include "lib/filehighlight.h" #include "lib/fileloc.h" /* MC_USERCONF_DIR */ @@ -197,11 +198,6 @@ int mouse_move_pages = 1; /* If true: l&r arrows are used to chdir if the input line is empty */ int navigate_with_arrows = 0; -/* If true program softkeys (HP terminals only) on startup and after every - command ran in the subshell to the description found in the termcap/terminfo - database */ -int reset_hp_softkeys = 0; - /* The prompt */ const char *mc_prompt = NULL; diff --git a/src/main.h b/src/main.h index a21d21333..3ad59c1fc 100644 --- a/src/main.h +++ b/src/main.h @@ -105,6 +105,7 @@ extern const global_keymap_t *help_map; #ifdef HAVE_SUBSHELL_SUPPORT void do_update_prompt (void); +int load_prompt (int fd, void *unused); #endif enum cd_enum { @@ -115,7 +116,6 @@ enum cd_enum { int do_cd (const char *new_dir, enum cd_enum cd_type); /* For find.c */ void sort_cmd (void); void change_panel (void); -int load_prompt (int, void *); void save_cwds_stat (void); void quiet_quit_cmd (void); /* For cmd.c and command.c */