mirror of https://github.com/MidnightCommander/mc
Ticket #3805: fix --help option to show correct syntax for editor, viewer and mcdiff
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> Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
f4eb2c47c9
commit
f0d3241ecb
74
src/args.c
74
src/args.c
|
@ -388,12 +388,28 @@ mc_args_new_color_group (void)
|
|||
static gchar *
|
||||
mc_args_add_usage_info (void)
|
||||
{
|
||||
mc_args__loc__usage_string = g_strdup_printf ("[%s] %s\n %s - %s\n",
|
||||
_("+number"),
|
||||
_("[this_dir] [other_panel_dir]"),
|
||||
_("+number"),
|
||||
_
|
||||
("Set initial line number for the internal editor"));
|
||||
gchar *s;
|
||||
|
||||
switch (mc_global.mc_run_mode)
|
||||
{
|
||||
case MC_RUN_EDITOR:
|
||||
s = g_strdup_printf ("%s\n", _("[+lineno] file1[:lineno] [file2[:lineno]...]"));
|
||||
break;
|
||||
case MC_RUN_VIEWER:
|
||||
s = g_strdup_printf ("%s\n", _("file"));
|
||||
break;
|
||||
#ifdef USE_DIFF_VIEW
|
||||
case MC_RUN_DIFFVIEWER:
|
||||
s = g_strdup_printf ("%s\n", _("file1 file2"));
|
||||
break;
|
||||
#endif /* USE_DIFF_VIEW */
|
||||
case MC_RUN_FULL:
|
||||
default:
|
||||
s = g_strdup_printf ("%s\n", _("[this_dir] [other_panel_dir]"));
|
||||
}
|
||||
|
||||
mc_args__loc__usage_string = s;
|
||||
|
||||
return mc_args__loc__usage_string;
|
||||
}
|
||||
|
||||
|
@ -613,6 +629,32 @@ parse_mcedit_arguments (int argc, char **argv)
|
|||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
mc_setup_run_mode (char **argv)
|
||||
{
|
||||
const char *base;
|
||||
|
||||
base = x_basename (argv[0]);
|
||||
|
||||
if (strncmp (base, "mce", 3) == 0 || strcmp (base, "vi") == 0)
|
||||
{
|
||||
/* mce* or vi is link to mc */
|
||||
mc_global.mc_run_mode = MC_RUN_EDITOR;
|
||||
}
|
||||
else if (strncmp (base, "mcv", 3) == 0 || strcmp (base, "view") == 0)
|
||||
{
|
||||
/* mcv* or view is link to mc */
|
||||
mc_global.mc_run_mode = MC_RUN_VIEWER;
|
||||
}
|
||||
#ifdef USE_DIFF_VIEW
|
||||
else if (strncmp (base, "mcd", 3) == 0 || strcmp (base, "diff") == 0)
|
||||
{
|
||||
/* mcd* or diff is link to mc */
|
||||
mc_global.mc_run_mode = MC_RUN_DIFFVIEWER;
|
||||
}
|
||||
#endif /* USE_DIFF_VIEW */
|
||||
}
|
||||
|
||||
gboolean
|
||||
mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror)
|
||||
{
|
||||
|
@ -730,7 +772,6 @@ mc_args_show_info (void)
|
|||
gboolean
|
||||
mc_setup_by_args (int argc, char **argv, GError ** mcerror)
|
||||
{
|
||||
const char *base;
|
||||
char *tmp;
|
||||
|
||||
mc_return_val_if_error (mcerror, FALSE);
|
||||
|
@ -764,27 +805,8 @@ mc_setup_by_args (int argc, char **argv, GError ** mcerror)
|
|||
(void) vpath;
|
||||
}
|
||||
|
||||
base = x_basename (argv[0]);
|
||||
tmp = (argc > 0) ? argv[1] : NULL;
|
||||
|
||||
if (strncmp (base, "mce", 3) == 0 || strcmp (base, "vi") == 0)
|
||||
{
|
||||
/* mce* or vi is link to mc */
|
||||
mc_global.mc_run_mode = MC_RUN_EDITOR;
|
||||
}
|
||||
else if (strncmp (base, "mcv", 3) == 0 || strcmp (base, "view") == 0)
|
||||
{
|
||||
/* mcv* or view is link to mc */
|
||||
mc_global.mc_run_mode = MC_RUN_VIEWER;
|
||||
}
|
||||
#ifdef USE_DIFF_VIEW
|
||||
else if (strncmp (base, "mcd", 3) == 0 || strcmp (base, "diff") == 0)
|
||||
{
|
||||
/* mcd* or diff is link to mc */
|
||||
mc_global.mc_run_mode = MC_RUN_DIFFVIEWER;
|
||||
}
|
||||
#endif /* USE_DIFF_VIEW */
|
||||
|
||||
switch (mc_global.mc_run_mode)
|
||||
{
|
||||
case MC_RUN_EDITOR:
|
||||
|
|
|
@ -46,6 +46,7 @@ extern char *mc_run_param1;
|
|||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void mc_setup_run_mode (char **argv);
|
||||
gboolean mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror);
|
||||
gboolean mc_args_show_info (void);
|
||||
gboolean mc_setup_by_args (int argc, char **argv, GError ** mcerror);
|
||||
|
|
|
@ -234,6 +234,8 @@ main (int argc, char *argv[])
|
|||
/* do this before args parsing */
|
||||
str_init_strings (NULL);
|
||||
|
||||
mc_setup_run_mode (argv); /* are we mc? editor? viewer? etc... */
|
||||
|
||||
if (!mc_args_parse (&argc, &argv, "mc", &mcerror))
|
||||
{
|
||||
startup_exit_falure:
|
||||
|
|
Loading…
Reference in New Issue