From cfc0ed218814f20472b98e11984aec85dbacee62 Mon Sep 17 00:00:00 2001
From: Denys Vlasenko <dvlasenk@redhat.com>
Date: Thu, 13 Apr 2017 19:27:46 +0200
Subject: [PATCH] Fix --help option to show correct syntax for editor, viewer
and mcdiff
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Before the patch: --help shows the same text for all tools, only "mc"
is replaced by tool name. For example, "mcedit --help" says:
Usage:
mcedit [OPTION…] [+number] [this_dir] [other_panel_dir]
+number - Set initial line number for the internal editor
which is wrong: mcedit does not take [this_dir] [other_panel_dir]
syntax, that's mc syntax.
After the patch, each tool has its own syntax string shown.
"Usage:" message for each tool is as follows now:
mc [OPTION…] [this_dir] [other_panel_dir]
mcedit [OPTION…] [+lineno] file1[:lineno] [file2[:lineno]...]
mcview [OPTION…] file
mcdiff [OPTION…] file1 file2
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
---
src/args.c | 75 ++++++++++++++++++++++++++++++++++++++++----------------------
src/args.h | 1 +
src/main.c | 2 ++
3 files changed, 52 insertions(+), 26 deletions(-)
diff --git a/src/args.c b/src/args.c
index 5ee5470..0c677c7 100644
a
|
b
|
mc_args_new_color_group (void) |
388 | 388 | static gchar * |
389 | 389 | mc_args_add_usage_info (void) |
390 | 390 | { |
391 | | mc_args__loc__usage_string = g_strdup_printf ("[%s] %s\n %s - %s\n", |
392 | | _("+number"), |
393 | | _("[this_dir] [other_panel_dir]"), |
394 | | _("+number"), |
395 | | _ |
396 | | ("Set initial line number for the internal editor")); |
| 391 | gchar *s; |
| 392 | |
| 393 | switch (mc_global.mc_run_mode) |
| 394 | { |
| 395 | case MC_RUN_EDITOR: |
| 396 | s = g_strdup_printf ("%s\n", |
| 397 | _("[+lineno] file1[:lineno] [file2[:lineno]...]")); |
| 398 | break; |
| 399 | case MC_RUN_VIEWER: |
| 400 | s = g_strdup_printf ("%s\n", |
| 401 | _("file")); |
| 402 | break; |
| 403 | #ifdef USE_DIFF_VIEW |
| 404 | case MC_RUN_DIFFVIEWER: |
| 405 | s = g_strdup_printf ("%s\n", |
| 406 | _("file1 file2")); |
| 407 | break; |
| 408 | #endif /* USE_DIFF_VIEW */ |
| 409 | case MC_RUN_FULL: |
| 410 | default: |
| 411 | s = g_strdup_printf ("%s\n", |
| 412 | _("[this_dir] [other_panel_dir]")); |
| 413 | } |
| 414 | mc_args__loc__usage_string = s; |
| 415 | |
397 | 416 | return mc_args__loc__usage_string; |
398 | 417 | } |
399 | 418 | |
… |
… |
parse_mcedit_arguments (int argc, char **argv) |
613 | 632 | /*** public functions ****************************************************************************/ |
614 | 633 | /* --------------------------------------------------------------------------------------------- */ |
615 | 634 | |
| 635 | void |
| 636 | mc_setup_run_mode (char **argv) |
| 637 | { |
| 638 | const char *base = x_basename (argv[0]); |
| 639 | |
| 640 | if (strncmp (base, "mce", 3) == 0 || strcmp (base, "vi") == 0) |
| 641 | { |
| 642 | /* mce* or vi is link to mc */ |
| 643 | mc_global.mc_run_mode = MC_RUN_EDITOR; |
| 644 | } |
| 645 | else if (strncmp (base, "mcv", 3) == 0 || strcmp (base, "view") == 0) |
| 646 | { |
| 647 | /* mcv* or view is link to mc */ |
| 648 | mc_global.mc_run_mode = MC_RUN_VIEWER; |
| 649 | } |
| 650 | #ifdef USE_DIFF_VIEW |
| 651 | else if (strncmp (base, "mcd", 3) == 0 || strcmp (base, "diff") == 0) |
| 652 | { |
| 653 | /* mcd* or diff is link to mc */ |
| 654 | mc_global.mc_run_mode = MC_RUN_DIFFVIEWER; |
| 655 | } |
| 656 | #endif /* USE_DIFF_VIEW */ |
| 657 | } |
| 658 | |
616 | 659 | gboolean |
617 | 660 | mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror) |
618 | 661 | { |
… |
… |
mc_args_show_info (void) |
730 | 773 | gboolean |
731 | 774 | mc_setup_by_args (int argc, char **argv, GError ** mcerror) |
732 | 775 | { |
733 | | const char *base; |
734 | 776 | char *tmp; |
735 | 777 | |
736 | 778 | mc_return_val_if_error (mcerror, FALSE); |
… |
… |
mc_setup_by_args (int argc, char **argv, GError ** mcerror) |
764 | 806 | (void) vpath; |
765 | 807 | } |
766 | 808 | |
767 | | base = x_basename (argv[0]); |
768 | 809 | tmp = (argc > 0) ? argv[1] : NULL; |
769 | 810 | |
770 | | if (strncmp (base, "mce", 3) == 0 || strcmp (base, "vi") == 0) |
771 | | { |
772 | | /* mce* or vi is link to mc */ |
773 | | mc_global.mc_run_mode = MC_RUN_EDITOR; |
774 | | } |
775 | | else if (strncmp (base, "mcv", 3) == 0 || strcmp (base, "view") == 0) |
776 | | { |
777 | | /* mcv* or view is link to mc */ |
778 | | mc_global.mc_run_mode = MC_RUN_VIEWER; |
779 | | } |
780 | | #ifdef USE_DIFF_VIEW |
781 | | else if (strncmp (base, "mcd", 3) == 0 || strcmp (base, "diff") == 0) |
782 | | { |
783 | | /* mcd* or diff is link to mc */ |
784 | | mc_global.mc_run_mode = MC_RUN_DIFFVIEWER; |
785 | | } |
786 | | #endif /* USE_DIFF_VIEW */ |
787 | | |
788 | 811 | switch (mc_global.mc_run_mode) |
789 | 812 | { |
790 | 813 | case MC_RUN_EDITOR: |
diff --git a/src/args.h b/src/args.h
index 53ff9ea..616864d 100644
a
|
b
|
extern char *mc_run_param1; |
46 | 46 | |
47 | 47 | /*** declarations of public functions ************************************************************/ |
48 | 48 | |
| 49 | void mc_setup_run_mode (char **argv); |
49 | 50 | gboolean mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror); |
50 | 51 | gboolean mc_args_show_info (void); |
51 | 52 | gboolean mc_setup_by_args (int argc, char **argv, GError ** mcerror); |
diff --git a/src/main.c b/src/main.c
index bdc40ba..9104438 100644
a
|
b
|
main (int argc, char *argv[]) |
234 | 234 | /* do this before args parsing */ |
235 | 235 | str_init_strings (NULL); |
236 | 236 | |
| 237 | mc_setup_run_mode (argv); /* are we mc? editor? viewer? etc... */ |
| 238 | |
237 | 239 | if (!mc_args_parse (&argc, &argv, "mc", &mcerror)) |
238 | 240 | { |
239 | 241 | startup_exit_falure: |