Ticket #3805: 0001-Fix-help-option-to-show-correct-syntax-for-editor-vi.patch

File 0001-Fix-help-option-to-show-correct-syntax-for-editor-vi.patch, 5.5 KB (added by vda, 7 years ago)

Patch is attached. Run-tested.

  • src/args.c

    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) 
    388388static gchar * 
    389389mc_args_add_usage_info (void) 
    390390{ 
    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 
    397416    return mc_args__loc__usage_string; 
    398417} 
    399418 
    parse_mcedit_arguments (int argc, char **argv) 
    613632/*** public functions ****************************************************************************/ 
    614633/* --------------------------------------------------------------------------------------------- */ 
    615634 
     635void 
     636mc_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 
    616659gboolean 
    617660mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror) 
    618661{ 
    mc_args_show_info (void) 
    730773gboolean 
    731774mc_setup_by_args (int argc, char **argv, GError ** mcerror) 
    732775{ 
    733     const char *base; 
    734776    char *tmp; 
    735777 
    736778    mc_return_val_if_error (mcerror, FALSE); 
    mc_setup_by_args (int argc, char **argv, GError ** mcerror) 
    764806        (void) vpath; 
    765807    } 
    766808 
    767     base = x_basename (argv[0]); 
    768809    tmp = (argc > 0) ? argv[1] : NULL; 
    769810 
    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  
    788811    switch (mc_global.mc_run_mode) 
    789812    { 
    790813    case MC_RUN_EDITOR: 
  • src/args.h

    diff --git a/src/args.h b/src/args.h
    index 53ff9ea..616864d 100644
    a b extern char *mc_run_param1; 
    4646 
    4747/*** declarations of public functions ************************************************************/ 
    4848 
     49void mc_setup_run_mode (char **argv); 
    4950gboolean mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror); 
    5051gboolean mc_args_show_info (void); 
    5152gboolean mc_setup_by_args (int argc, char **argv, GError ** mcerror); 
  • src/main.c

    diff --git a/src/main.c b/src/main.c
    index bdc40ba..9104438 100644
    a b main (int argc, char *argv[]) 
    234234    /* do this before args parsing */ 
    235235    str_init_strings (NULL); 
    236236 
     237    mc_setup_run_mode (argv); /* are we mc? editor? viewer? etc... */ 
     238 
    237239    if (!mc_args_parse (&argc, &argv, "mc", &mcerror)) 
    238240    { 
    239241      startup_exit_falure: