From 6da546bcf3a09b7710bc3b69d38e736e3273c34b Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 25 Jul 2013 10:36:19 +0400 Subject: [PATCH] Ticket #3047: fix mc arguments handling. Following cases from command line are possible: * 'mc' (no arguments): active panel uses current directory passive panel uses "other_dir" from ini * 'mc dir1 dir2' (two arguments): left panel uses dir1 right panel uses dir2 * 'mc dir1' (single argument): active panel uses current directory passive panel uses dir1 Signed-off-by: Andrew Borodin --- doc/man/mc.1.in | 13 ++++++-- doc/man/ru/mc.1.in | 11 +++++-- src/filemanager/midnight.c | 62 +++++++++++++++++++++++++++++--------- src/main.c | 1 + src/setup.c | 7 +++-- src/setup.h | 3 ++ 6 files changed, 75 insertions(+), 22 deletions(-) diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in index da58ffbc9..3a58c1de4 100644 --- a/doc/man/mc.1.in +++ b/doc/man/mc.1.in @@ -171,9 +171,16 @@ screen modes, and able to send mouse escape sequences). .I \-X, \-\-no\-x11 Do not use X11 to get the state of modifiers Alt, Ctrl, Shift .PP -If specified, the first path name is the directory to show in the -selected panel; the second path name is the directory to be shown in -the other panel. +If both paths are specified, the first path name is the directory to show +in the left panel; the second path name is the directory to be shown in +the right panel. +.PP +If one path is specified, the path name is the directory to show +in the active panel; current directory is shown in the passive panel. +.PP +If no paths are specified, current directory is shown in the active panel; +value of "other_dir" from panels.ini is the directory to be shown in +the passive panel. .\"NODE "Overview" .SH "Overview" The screen of the Midnight Commander is divided into four parts. diff --git a/doc/man/ru/mc.1.in b/doc/man/ru/mc.1.in index eb8a4c0b3..0fcbf384c 100644 --- a/doc/man/ru/mc.1.in +++ b/doc/man/ru/mc.1.in @@ -148,9 +148,14 @@ modes, and able to send mouse escape sequences). .I \-X, \-\-no\-x11 Не использовать X11 для получения состояния модификаторов Alt, Ctrl, Shift. .PP -Первое путевое имя (path name) в командной строке (если указано) задает -каталог, который будет отображаться в активной панели; второй путь \- -каталог, отображаемый во второй панели. +Если в командной строке указаны два каталога, первый будет отображаться +в левой панели, второй \- в правой. +.PP +Если указан только один каталог, он будет отображён в активной панели, +во второй панели будет отображён текущий каталог. +.PP +Если каталоги не указаны, в активной панели будет отображён текущий каталог, +а во второй панели \- каталог, указанный в параметре "other_dir" в файла panels.ini. .\"NODE "Overview" .SH "Главное окно программы" Главное окно программы Midnight Commander состоит из трех полей. Два diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index c84082b27..f9127e013 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -580,6 +580,22 @@ create_panels (void) char *current_dir, *other_dir; vfs_path_t *original_dir; + /* + * Following cases from command line are possible: + * 'mc' (no arguments): mc_run_param0 == NULL, mc_run_param1 == NULL + * active panel uses current directory + * passive panel uses "other_dir" from ini + * + * 'mc dir1 dir2' (two arguments): mc_run_param0 != NULL, mc_run_param1 != NULL + * left panel uses mc_run_param0 + * right panel uses mc_run_param1 + * + * 'mc dir1' (single argument): mc_run_param0 != NULL, mc_run_param1 == NULL + * active panel uses current directory + * passive panel uses mc_run_param0 + */ + + /* Set up panel directories */ if (boot_current_is_left) { /* left panel is active */ @@ -587,11 +603,25 @@ create_panels (void) other_index = 1; current_mode = startup_left_mode; other_mode = startup_right_mode; - /* if mc_run_param0 is NULL, working directory will be used for the left panel */ - current_dir = (char *) mc_run_param0; - /* mc_run_param1 is never NULL. It is setup from command line or from panels.ini - * (value of other_dir). mc_run_param1 will be used for the right panel */ - other_dir = mc_run_param1; + + if (mc_run_param0 == NULL && mc_run_param1 == NULL) + { + /* no arguments */ + current_dir = NULL; /* assume current dir */ + other_dir = saved_other_dir; /* from ini */ + } + else if (mc_run_param0 != NULL && mc_run_param1 != NULL) + { + /* two arguments */ + current_dir = (char *) mc_run_param0; + other_dir = mc_run_param1; + } + else /* mc_run_param0 != NULL && mc_run_param1 == NULL */ + { + /* one argument */ + current_dir = NULL; /* assume current dir */ + other_dir = (char *) mc_run_param0; + } } else { @@ -601,19 +631,23 @@ create_panels (void) current_mode = startup_right_mode; other_mode = startup_left_mode; - /* if mc_run_param0 is not NULL (it was setup from command line), it will be used - * for the left panel, working directory will be used for the right one; - * if mc_run_param0 is NULL, working directory will be used for the right (active) panel, - * mc_run_param1 will be used for the left one */ - if (mc_run_param0 != NULL) + if (mc_run_param0 == NULL && mc_run_param1 == NULL) { - current_dir = NULL; + /* no arguments */ + current_dir = NULL; /* assume current dir */ + other_dir = saved_other_dir; /* from ini */ + } + else if (mc_run_param0 != NULL && mc_run_param1 != NULL) + { + /* two arguments */ + current_dir = mc_run_param1; other_dir = (char *) mc_run_param0; } - else + else /* mc_run_param0 != NULL && mc_run_param1 == NULL */ { - current_dir = NULL; - other_dir = mc_run_param1; + /* one argument */ + current_dir = NULL; /* assume current dir */; + other_dir = (char *) mc_run_param0; } } diff --git a/src/main.c b/src/main.c index e8807eec0..21588ff4d 100644 --- a/src/main.c +++ b/src/main.c @@ -469,6 +469,7 @@ main (int argc, char *argv[]) g_list_free ((GList *) mc_run_param0); } g_free (mc_run_param1); + g_free (saved_other_dir); mc_config_deinit_config_paths (); diff --git a/src/setup.c b/src/setup.c index bdd49d964..dcbf9294e 100644 --- a/src/setup.c +++ b/src/setup.c @@ -193,6 +193,9 @@ gboolean is_autodetect_codeset_enabled = FALSE; char *spell_language = NULL; #endif +/* Value of "other_dir" key in ini file */ +char *saved_other_dir = NULL; + /* If set, then print to the given file the last directory we were at */ char *last_wd_string = NULL; @@ -986,13 +989,13 @@ load_setup (void) if (startup_left_mode != view_listing && startup_right_mode != view_listing) startup_left_mode = view_listing; - if (mc_run_param1 == NULL) { vfs_path_t *vpath; + buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", "."); vpath = vfs_path_from_str (buffer); if (vfs_file_is_local (vpath)) - mc_run_param1 = buffer; + saved_other_dir = buffer; else g_free (buffer); vfs_path_free (vpath); diff --git a/src/setup.h b/src/setup.h index 991b3e94c..218afc711 100644 --- a/src/setup.h +++ b/src/setup.h @@ -117,6 +117,9 @@ extern gboolean is_autodetect_codeset_enabled; extern char *spell_language; #endif +/* Value of "other_dir" key in ini file */ +extern char *saved_other_dir; + /* If set, then print to the given file the last directory we were at */ extern char *last_wd_string;