2009-09-01 15:05:01 +04:00
|
|
|
/*
|
|
|
|
Handle command line arguments.
|
|
|
|
|
|
|
|
Copyright (C) 2009 The Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by:
|
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2009.
|
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
The Midnight Commander is free software; you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The Midnight Commander is distributed in the hope that it will be
|
|
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
|
|
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2010-02-15 14:21:30 +03:00
|
|
|
#include <stdlib.h>
|
2009-09-01 15:05:01 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2010-01-08 17:47:19 +03:00
|
|
|
#include "lib/tty/tty.h"
|
2010-04-23 11:54:25 +04:00
|
|
|
#include "lib/tty/color.h" /* command_line_colors */
|
2010-05-12 10:29:57 +04:00
|
|
|
#include "lib/tty/mouse.h"
|
2010-01-21 15:17:26 +03:00
|
|
|
#include "lib/strutil.h"
|
2011-02-15 16:44:17 +03:00
|
|
|
#include "lib/vfs/vfs.h"
|
|
|
|
#include "lib/util.h" /* x_basename() */
|
|
|
|
|
2010-07-18 11:32:24 +04:00
|
|
|
#ifdef ENABLE_VFS_SMB
|
2011-02-15 16:44:17 +03:00
|
|
|
#include "src/vfs/smbfs/smbfs.h" /* smbfs_set_debugf() */
|
2010-07-18 11:32:24 +04:00
|
|
|
#endif
|
2010-01-21 15:17:26 +03:00
|
|
|
|
2010-02-15 14:21:30 +03:00
|
|
|
#include "src/main.h"
|
2010-01-08 17:47:19 +03:00
|
|
|
#include "src/textconf.h"
|
2010-05-12 10:29:57 +04:00
|
|
|
#include "src/subshell.h" /* use_subshell */
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2010-02-15 14:21:30 +03:00
|
|
|
#include "src/args.h"
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2010-02-15 14:21:30 +03:00
|
|
|
/*** external variables **************************************************************************/
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/* If true, show version info and exit */
|
2010-05-12 10:29:57 +04:00
|
|
|
gboolean mc_args__show_version = FALSE;
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
/* If true, assume we are running on an xterm terminal */
|
|
|
|
gboolean mc_args__force_xterm = FALSE;
|
|
|
|
|
|
|
|
gboolean mc_args__nomouse = FALSE;
|
|
|
|
|
|
|
|
/* For slow terminals */
|
|
|
|
gboolean mc_args__slow_terminal = FALSE;
|
|
|
|
|
|
|
|
/* If true use +, -, | for line drawing */
|
|
|
|
gboolean mc_args__ugly_line_drawing = FALSE;
|
|
|
|
|
|
|
|
/* Set to force black and white display at program startup */
|
|
|
|
gboolean mc_args__disable_colors = FALSE;
|
|
|
|
|
|
|
|
/* Force colors, only used by Slang */
|
|
|
|
gboolean mc_args__force_colors = FALSE;
|
|
|
|
|
2011-02-21 13:49:45 +03:00
|
|
|
/* Don't load keymap form file and use default one */
|
|
|
|
gboolean mc_args__nokeymap = FALSE;
|
|
|
|
|
2010-05-12 10:29:57 +04:00
|
|
|
/* Line to start the editor on */
|
|
|
|
int mc_args__edit_start_line = 0;
|
|
|
|
|
2011-02-21 13:49:45 +03:00
|
|
|
/* Use the specified skin */
|
2009-09-04 18:22:49 +04:00
|
|
|
char *mc_args__skin = NULL;
|
|
|
|
|
2009-09-01 15:05:01 +04:00
|
|
|
char *mc_args__last_wd_file = NULL;
|
|
|
|
|
|
|
|
/* when enabled NETCODE, use folowing file as logfile */
|
|
|
|
char *mc_args__netfs_logfile = NULL;
|
|
|
|
|
2009-09-15 16:48:30 +04:00
|
|
|
/* keymap file */
|
|
|
|
char *mc_args__keymap_file = NULL;
|
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
/* Debug level */
|
2009-09-01 15:05:01 +04:00
|
|
|
int mc_args__debug_level = 0;
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
2010-05-12 11:12:27 +04:00
|
|
|
/* forward declarations */
|
2010-11-09 14:02:28 +03:00
|
|
|
static gboolean parse_mc_e_argument (const gchar * option_name, const gchar * value,
|
|
|
|
gpointer data, GError ** error);
|
|
|
|
static gboolean parse_mc_v_argument (const gchar * option_name, const gchar * value,
|
|
|
|
gpointer data, GError ** error);
|
2010-05-12 11:12:27 +04:00
|
|
|
|
2009-09-01 15:05:01 +04:00
|
|
|
static GOptionContext *context;
|
|
|
|
|
|
|
|
static gboolean mc_args__nouse_subshell = FALSE;
|
|
|
|
static gboolean mc_args__show_datadirs = FALSE;
|
|
|
|
|
2010-02-15 14:21:30 +03:00
|
|
|
static GOptionGroup *main_group;
|
|
|
|
|
2009-09-01 15:05:01 +04:00
|
|
|
static const GOptionEntry argument_main_table[] = {
|
2010-03-31 14:33:24 +04:00
|
|
|
/* *INDENT-OFF* */
|
2009-09-01 15:05:01 +04:00
|
|
|
/* generic options */
|
|
|
|
{
|
|
|
|
"version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
|
2010-05-12 10:29:57 +04:00
|
|
|
&mc_args__show_version,
|
2009-09-01 15:05:01 +04:00
|
|
|
N_("Displays the current version"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
/* options for wrappers */
|
|
|
|
{
|
|
|
|
"datadir", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
|
|
|
|
&mc_args__show_datadirs,
|
|
|
|
N_("Print data directory"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
"printwd", 'P', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
|
|
|
|
&mc_args__last_wd_file,
|
|
|
|
N_("Print last working directory to specified file"),
|
2010-03-31 14:33:24 +04:00
|
|
|
"<file>"
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
|
|
|
{
|
|
|
|
"subshell", 'U', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
|
|
|
|
&use_subshell,
|
|
|
|
N_("Enables subshell support (default)"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
"nosubshell", 'u', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
|
|
|
|
&mc_args__nouse_subshell,
|
|
|
|
N_("Disables subshell support"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* debug options */
|
2010-07-13 15:58:44 +04:00
|
|
|
#ifdef ENABLE_VFS_FTP
|
2009-09-01 15:05:01 +04:00
|
|
|
{
|
|
|
|
"ftplog", 'l', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
|
|
|
|
&mc_args__netfs_logfile,
|
|
|
|
N_("Log ftp dialog to specified file"),
|
2010-03-31 14:33:24 +04:00
|
|
|
"<file>"
|
|
|
|
},
|
2010-07-13 15:58:44 +04:00
|
|
|
#endif /* ENABLE_VFS_FTP */
|
2009-11-14 19:10:57 +03:00
|
|
|
#ifdef ENABLE_VFS_SMB
|
2009-09-01 15:05:01 +04:00
|
|
|
{
|
|
|
|
"debuglevel", 'D', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT,
|
|
|
|
&mc_args__debug_level,
|
|
|
|
N_("Set debug level"),
|
2010-03-31 14:33:24 +04:00
|
|
|
"<integer>"
|
|
|
|
},
|
2009-11-14 19:10:57 +03:00
|
|
|
#endif /* ENABLE_VFS_SMB */
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
/* single file operations */
|
|
|
|
{
|
2010-05-12 11:12:27 +04:00
|
|
|
"view", 'v', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_CALLBACK,
|
|
|
|
parse_mc_v_argument,
|
2009-09-01 15:05:01 +04:00
|
|
|
N_("Launches the file viewer on a file"),
|
2010-03-31 14:33:24 +04:00
|
|
|
"<file>"
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
{
|
2010-05-12 11:12:27 +04:00
|
|
|
"edit", 'e', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_CALLBACK,
|
|
|
|
parse_mc_e_argument,
|
2009-09-01 15:05:01 +04:00
|
|
|
N_("Edits one file"),
|
2010-04-23 11:54:25 +04:00
|
|
|
"<file>"},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2010-03-31 14:33:24 +04:00
|
|
|
{
|
|
|
|
NULL, '\0', 0, 0, NULL, NULL, NULL /* Complete struct initialization */
|
|
|
|
}
|
|
|
|
/* *INDENT-ON* */
|
2009-09-01 15:05:01 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
GOptionGroup *terminal_group;
|
|
|
|
#define ARGS_TERM_OPTIONS 0
|
|
|
|
static const GOptionEntry argument_terminal_table[] = {
|
2010-03-31 14:33:24 +04:00
|
|
|
/* *INDENT-OFF* */
|
2009-09-01 15:05:01 +04:00
|
|
|
/* terminal options */
|
|
|
|
{
|
|
|
|
"xterm", 'x', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
|
|
|
&mc_args__force_xterm,
|
|
|
|
N_("Forces xterm features"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
"nomouse", 'd', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
|
|
|
&mc_args__nomouse,
|
|
|
|
N_("Disable mouse support in text version"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_SLANG
|
|
|
|
{
|
|
|
|
"termcap", 't', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
|
|
|
&SLtt_Try_Termcap,
|
|
|
|
N_("Tries to use termcap instead of terminfo"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
{
|
|
|
|
"slow", 's', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
|
|
|
&mc_args__slow_terminal,
|
|
|
|
N_("To run on slow terminals"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
"stickchars", 'a', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
|
|
|
&mc_args__ugly_line_drawing,
|
|
|
|
N_("Use stickchars to draw"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
"resetsoft", 'k', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
|
|
|
&reset_hp_softkeys,
|
|
|
|
N_("Resets soft keys on HP terminals"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2009-09-15 16:48:30 +04:00
|
|
|
{
|
|
|
|
"keymap", 'K', ARGS_TERM_OPTIONS, G_OPTION_ARG_STRING,
|
|
|
|
&mc_args__keymap_file,
|
|
|
|
N_("Load definitions of key bindings from specified file"),
|
2010-03-31 14:33:24 +04:00
|
|
|
"<file>"
|
|
|
|
},
|
2009-09-15 16:48:30 +04:00
|
|
|
|
2011-02-21 13:49:45 +03:00
|
|
|
{
|
|
|
|
"nokeymap", '\0', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
|
|
|
&mc_args__nokeymap,
|
|
|
|
N_("Don't load definitions of key bindings from file, use defaults"),
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
|
2010-03-31 14:33:24 +04:00
|
|
|
{
|
|
|
|
NULL, '\0', 0, 0, NULL, NULL, NULL /* Complete struct initialization */
|
|
|
|
}
|
|
|
|
/* *INDENT-ON* */
|
2009-09-01 15:05:01 +04:00
|
|
|
};
|
2010-04-23 11:54:25 +04:00
|
|
|
|
2009-09-01 15:05:01 +04:00
|
|
|
#undef ARGS_TERM_OPTIONS
|
|
|
|
|
|
|
|
GOptionGroup *color_group;
|
|
|
|
#define ARGS_COLOR_OPTIONS 0
|
|
|
|
// #define ARGS_COLOR_OPTIONS G_OPTION_FLAG_IN_MAIN
|
|
|
|
static const GOptionEntry argument_color_table[] = {
|
2010-03-31 14:33:24 +04:00
|
|
|
/* *INDENT-OFF* */
|
2009-09-01 15:05:01 +04:00
|
|
|
/* color options */
|
|
|
|
{
|
|
|
|
"nocolor", 'b', ARGS_COLOR_OPTIONS, G_OPTION_ARG_NONE,
|
|
|
|
&mc_args__disable_colors,
|
|
|
|
N_("Requests to run in black and white"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
"color", 'c', ARGS_COLOR_OPTIONS, G_OPTION_ARG_NONE,
|
|
|
|
&mc_args__force_colors,
|
|
|
|
N_("Request to run in color mode"),
|
2010-03-31 14:33:24 +04:00
|
|
|
NULL
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
"colors", 'C', ARGS_COLOR_OPTIONS, G_OPTION_ARG_STRING,
|
|
|
|
&command_line_colors,
|
|
|
|
N_("Specifies a color configuration"),
|
2010-03-31 14:33:24 +04:00
|
|
|
"<string>"
|
|
|
|
},
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
|
|
|
"skin", 'S', ARGS_COLOR_OPTIONS, G_OPTION_ARG_STRING,
|
|
|
|
&mc_args__skin,
|
|
|
|
N_("Show mc with specified skin"),
|
2010-03-31 14:33:24 +04:00
|
|
|
"<string>"
|
|
|
|
},
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2010-03-31 14:33:24 +04:00
|
|
|
{
|
|
|
|
NULL, '\0', 0, 0, NULL, NULL, NULL /* Complete struct initialization */
|
|
|
|
}
|
|
|
|
/* *INDENT-ON* */
|
2009-09-01 15:05:01 +04:00
|
|
|
};
|
2010-04-23 11:54:25 +04:00
|
|
|
|
2009-09-01 15:05:01 +04:00
|
|
|
#undef ARGS_COLOR_OPTIONS
|
|
|
|
|
|
|
|
static gchar *mc_args__loc__colors_string = NULL;
|
|
|
|
static gchar *mc_args__loc__footer_string = NULL;
|
|
|
|
static gchar *mc_args__loc__header_string = NULL;
|
|
|
|
static gchar *mc_args__loc__usage_string = NULL;
|
|
|
|
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
static void
|
2010-04-23 11:54:25 +04:00
|
|
|
mc_args_clean_temp_help_strings (void)
|
2009-09-01 15:05:01 +04:00
|
|
|
{
|
2010-04-23 11:54:25 +04:00
|
|
|
g_free (mc_args__loc__colors_string);
|
2009-09-01 15:05:01 +04:00
|
|
|
mc_args__loc__colors_string = NULL;
|
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
g_free (mc_args__loc__footer_string);
|
2009-09-01 15:05:01 +04:00
|
|
|
mc_args__loc__footer_string = NULL;
|
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
g_free (mc_args__loc__header_string);
|
2009-09-01 15:05:01 +04:00
|
|
|
mc_args__loc__header_string = NULL;
|
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
g_free (mc_args__loc__usage_string);
|
2009-09-01 15:05:01 +04:00
|
|
|
mc_args__loc__usage_string = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static GOptionGroup *
|
2010-04-23 11:54:25 +04:00
|
|
|
mc_args_new_color_group (void)
|
2009-09-01 15:05:01 +04:00
|
|
|
{
|
2010-11-29 21:46:11 +03:00
|
|
|
/* FIXME: to preserve translations, lines should be split. */
|
|
|
|
mc_args__loc__colors_string = g_strdup_printf ("%s\n%s",
|
|
|
|
/* TRANSLATORS: don't translate keywords */
|
2010-12-29 12:58:10 +03:00
|
|
|
_("--colors KEYWORD={FORE},{BACK},{ATTR}:KEYWORD2=...\n\n"
|
|
|
|
"{FORE}, {BACK} and {ATTR} can be omitted, and the default will be used\n"
|
2010-11-29 21:46:11 +03:00
|
|
|
"\n Keywords:\n"
|
2010-12-29 10:02:27 +03:00
|
|
|
" Global: errors, disabled, reverse, gauge, header\n"
|
2010-05-03 02:33:08 +04:00
|
|
|
" input, inputmark, inputunchanged, commandlinemark\n"
|
2010-11-11 14:05:34 +03:00
|
|
|
" bbarhotkey, bbarbutton, statusbar\n"
|
2010-04-23 11:54:25 +04:00
|
|
|
" File display: normal, selected, marked, markselect\n"
|
|
|
|
" Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus, errdhotnormal,\n"
|
|
|
|
" errdhotfocus\n"
|
|
|
|
" Menus: menunormal, menuhot, menusel, menuhotsel, menuinactive\n"
|
2010-11-29 21:46:11 +03:00
|
|
|
" Popup menus: pmenunormal, pmenusel, pmenutitle\n"
|
2010-04-23 11:54:25 +04:00
|
|
|
" Editor: editnormal, editbold, editmarked, editwhitespace,\n"
|
2010-11-29 21:46:11 +03:00
|
|
|
" editlinestate\n"
|
2011-01-30 16:54:27 +03:00
|
|
|
" Viewer: viewbold, viewunderline, viewselected\n"
|
2010-11-29 21:46:11 +03:00
|
|
|
" Help: helpnormal, helpitalic, helpbold, helplink, helpslink\n"),
|
2010-12-29 12:58:10 +03:00
|
|
|
/* TRANSLATORS: don't translate color names and attributes */
|
|
|
|
_("Standard Colors:\n"
|
2010-04-23 11:54:25 +04:00
|
|
|
" black, gray, red, brightred, green, brightgreen, brown,\n"
|
|
|
|
" yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
|
2010-12-29 12:58:10 +03:00
|
|
|
" brightcyan, lightgray and white\n\n"
|
|
|
|
"Extended colors, when 256 colors are available:\n"
|
|
|
|
" color16 to color255, or rgb000 to rgb555 and gray0 to gray23\n\n"
|
|
|
|
"Attributes:\n"
|
|
|
|
" bold, underline, reverse, blink; append more with '+'\n")
|
|
|
|
);
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
return g_option_group_new ("color", mc_args__loc__colors_string,
|
2010-04-23 11:54:25 +04:00
|
|
|
_("Color options"), NULL, NULL);
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static gchar *
|
2010-04-23 11:54:25 +04:00
|
|
|
mc_args_add_usage_info (void)
|
2009-09-01 15:05:01 +04:00
|
|
|
{
|
2010-04-23 11:54:25 +04:00
|
|
|
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"));
|
2009-09-01 15:05:01 +04:00
|
|
|
return mc_args__loc__usage_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2010-04-23 11:54:25 +04:00
|
|
|
mc_args_add_extended_info_to_help (void)
|
2009-09-01 15:05:01 +04:00
|
|
|
{
|
2010-04-23 11:54:25 +04:00
|
|
|
mc_args__loc__footer_string = g_strdup_printf ("%s",
|
|
|
|
_
|
|
|
|
("\n"
|
|
|
|
"Please send any bug reports (including the output of `mc -V')\n"
|
2010-04-22 10:53:23 +04:00
|
|
|
"as tickets at www.midnight-commander.org\n"));
|
2009-09-01 15:05:01 +04:00
|
|
|
mc_args__loc__header_string = g_strdup_printf (_("GNU Midnight Commander %s\n"), VERSION);
|
|
|
|
|
|
|
|
#if GLIB_CHECK_VERSION(2,12,0)
|
|
|
|
g_option_context_set_description (context, mc_args__loc__footer_string);
|
|
|
|
g_option_context_set_summary (context, mc_args__loc__header_string);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2010-05-12 10:29:57 +04:00
|
|
|
static void
|
|
|
|
mc_setup_by_args (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
const char *base;
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (mc_args__nomouse)
|
|
|
|
use_mouse_p = MOUSE_DISABLED;
|
|
|
|
|
|
|
|
if (mc_args__netfs_logfile != NULL)
|
|
|
|
{
|
2010-07-13 15:58:44 +04:00
|
|
|
#ifdef ENABLE_VFS_FTP
|
2010-05-12 10:29:57 +04:00
|
|
|
mc_setctl ("/#ftp:", VFS_SETCTL_LOGFILE, (void *) mc_args__netfs_logfile);
|
2010-07-13 15:58:44 +04:00
|
|
|
#endif /* ENABLE_VFS_FTP */
|
2010-05-12 10:29:57 +04:00
|
|
|
#ifdef ENABLE_VFS_SMB
|
|
|
|
smbfs_set_debugf (mc_args__netfs_logfile);
|
|
|
|
#endif /* ENABLE_VFS_SMB */
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENABLE_VFS_SMB
|
|
|
|
if (mc_args__debug_level != 0)
|
|
|
|
smbfs_set_debug (mc_args__debug_level);
|
|
|
|
#endif /* ENABLE_VFS_SMB */
|
|
|
|
|
|
|
|
base = x_basename (argv[0]);
|
|
|
|
tmp = (argc > 0) ? argv[1] : NULL;
|
|
|
|
|
|
|
|
if (strncmp (base, "mce", 3) == 0 || strcmp (base, "vi") == 0)
|
|
|
|
{
|
2010-05-12 11:12:27 +04:00
|
|
|
/* mce* or vi is link to mc */
|
|
|
|
|
2010-05-12 10:29:57 +04:00
|
|
|
mc_run_param0 = g_strdup ("");
|
|
|
|
if (tmp != NULL)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check for filename:lineno, followed by an optional colon.
|
|
|
|
* This format is used by many programs (especially compilers)
|
|
|
|
* in error messages and warnings. It is supported so that
|
|
|
|
* users can quickly copy and paste file locations.
|
|
|
|
*/
|
|
|
|
char *end, *p;
|
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
end = tmp + strlen (tmp);
|
2010-05-12 10:29:57 +04:00
|
|
|
p = end;
|
|
|
|
|
|
|
|
if (p > tmp && p[-1] == ':')
|
|
|
|
p--;
|
|
|
|
while (p > tmp && g_ascii_isdigit ((gchar) p[-1]))
|
|
|
|
p--;
|
|
|
|
if (tmp < p && p < end && p[-1] == ':')
|
|
|
|
{
|
|
|
|
char *fname;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
fname = g_strndup (tmp, p - 1 - tmp);
|
|
|
|
/*
|
|
|
|
* Check that the file before the colon actually exists.
|
|
|
|
* If it doesn't exist, revert to the old behavior.
|
|
|
|
*/
|
|
|
|
if (mc_stat (tmp, &st) == -1 && mc_stat (fname, &st) != -1)
|
|
|
|
{
|
|
|
|
mc_run_param0 = fname;
|
|
|
|
mc_args__edit_start_line = atoi (p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (fname);
|
|
|
|
goto try_plus_filename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try_plus_filename:
|
|
|
|
if (*tmp == '+' && g_ascii_isdigit ((gchar) tmp[1]))
|
|
|
|
{
|
2010-09-09 12:29:32 +04:00
|
|
|
int start_line;
|
2010-05-12 10:29:57 +04:00
|
|
|
|
|
|
|
start_line = atoi (tmp);
|
2010-09-09 12:29:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If start_line is zero, position the cursor at the
|
|
|
|
* beginning of the file as other editors (vi, nano)
|
|
|
|
*/
|
|
|
|
if (start_line == 0)
|
|
|
|
start_line++;
|
|
|
|
|
2010-05-12 10:29:57 +04:00
|
|
|
if (start_line > 0)
|
|
|
|
{
|
|
|
|
char *file;
|
|
|
|
|
|
|
|
file = (argc > 1) ? argv[2] : NULL;
|
|
|
|
if (file != NULL)
|
|
|
|
{
|
|
|
|
tmp = file;
|
|
|
|
mc_args__edit_start_line = start_line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mc_run_param0 = g_strdup (tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mc_run_mode = MC_RUN_EDITOR;
|
|
|
|
}
|
|
|
|
else if (strncmp (base, "mcv", 3) == 0 || strcmp (base, "view") == 0)
|
|
|
|
{
|
2010-05-12 11:12:27 +04:00
|
|
|
/* mcv* or view is link to mc */
|
|
|
|
|
2010-05-12 10:29:57 +04:00
|
|
|
if (tmp != NULL)
|
|
|
|
mc_run_param0 = g_strdup (tmp);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s\n", _("No arguments given to the viewer."));
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
mc_run_mode = MC_RUN_VIEWER;
|
|
|
|
}
|
|
|
|
#ifdef USE_DIFF_VIEW
|
|
|
|
else if (strncmp (base, "mcd", 3) == 0 || strcmp (base, "diff") == 0)
|
|
|
|
{
|
2010-05-12 11:12:27 +04:00
|
|
|
/* mcd* or diff is link to mc */
|
|
|
|
|
2010-05-12 10:29:57 +04:00
|
|
|
if (argc < 3)
|
|
|
|
{
|
2010-06-23 22:01:41 +04:00
|
|
|
fprintf (stderr, "%s\n", _("Two files are required to evoke the diffviewer."));
|
2010-05-12 10:29:57 +04:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp != NULL)
|
|
|
|
{
|
|
|
|
mc_run_param0 = g_strdup (tmp);
|
|
|
|
tmp = (argc > 1) ? argv[2] : NULL;
|
|
|
|
if (tmp != NULL)
|
|
|
|
mc_run_param1 = g_strdup (tmp);
|
|
|
|
mc_run_mode = MC_RUN_DIFFVIEWER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* USE_DIFF_VIEW */
|
|
|
|
else
|
|
|
|
{
|
2010-05-12 11:12:27 +04:00
|
|
|
/* MC is run as mc */
|
|
|
|
|
|
|
|
switch (mc_run_mode)
|
2010-05-12 10:29:57 +04:00
|
|
|
{
|
2010-05-12 11:12:27 +04:00
|
|
|
case MC_RUN_EDITOR:
|
|
|
|
case MC_RUN_VIEWER:
|
|
|
|
/* mc_run_param0 is set up in parse_mc_e_argument() and parse_mc_v_argument() */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MC_RUN_DIFFVIEWER:
|
|
|
|
/* not implemented yet */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MC_RUN_FULL:
|
|
|
|
default:
|
|
|
|
/* sets the current dir and the other dir */
|
2010-05-12 10:29:57 +04:00
|
|
|
if (tmp != NULL)
|
2010-05-12 11:12:27 +04:00
|
|
|
{
|
|
|
|
mc_run_param0 = g_strdup (tmp);
|
|
|
|
tmp = (argc > 1) ? argv[2] : NULL;
|
|
|
|
if (tmp != NULL)
|
|
|
|
mc_run_param1 = g_strdup (tmp);
|
|
|
|
}
|
|
|
|
mc_run_mode = MC_RUN_FULL;
|
|
|
|
break;
|
2010-05-12 10:29:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-09-01 15:05:01 +04:00
|
|
|
static gboolean
|
2010-05-12 10:29:57 +04:00
|
|
|
mc_args_process (int argc, char *argv[])
|
2009-09-01 15:05:01 +04:00
|
|
|
{
|
2010-05-12 10:29:57 +04:00
|
|
|
if (mc_args__show_version)
|
2010-04-23 11:54:25 +04:00
|
|
|
{
|
|
|
|
show_version ();
|
|
|
|
return FALSE;
|
2009-09-01 15:05:01 +04:00
|
|
|
}
|
2010-04-23 11:54:25 +04:00
|
|
|
if (mc_args__show_datadirs)
|
|
|
|
{
|
2010-12-30 13:35:33 +03:00
|
|
|
printf ("%s (%s)\n", mc_sysconfig_dir, mc_share_data_dir);
|
2010-04-23 11:54:25 +04:00
|
|
|
return FALSE;
|
2009-09-01 15:05:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mc_args__force_colors)
|
2010-04-23 11:54:25 +04:00
|
|
|
mc_args__disable_colors = FALSE;
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_SUBSHELL_SUPPORT
|
|
|
|
if (mc_args__nouse_subshell)
|
2010-04-23 11:54:25 +04:00
|
|
|
use_subshell = 0;
|
|
|
|
#endif /* HAVE_SUBSHELL_SUPPORT */
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2010-05-12 10:29:57 +04:00
|
|
|
mc_setup_by_args (argc, argv);
|
|
|
|
|
2009-09-01 15:05:01 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static gchar *
|
2010-04-23 11:54:25 +04:00
|
|
|
mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_message,
|
|
|
|
const gchar * help_str)
|
2009-09-01 15:05:01 +04:00
|
|
|
{
|
2010-04-23 11:54:25 +04:00
|
|
|
GString *buffer = g_string_new ("");
|
|
|
|
GIConv conv = g_iconv_open (charset, "UTF-8");
|
|
|
|
gchar *full_help_str = g_strdup_printf ("%s\n\n%s\n", error_message, help_str);
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
str_convert (conv, full_help_str, buffer);
|
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
g_free (full_help_str);
|
2009-09-01 15:05:01 +04:00
|
|
|
g_iconv_close (conv);
|
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
return g_string_free (buffer, FALSE);
|
2009-09-01 15:05:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2010-05-12 11:12:27 +04:00
|
|
|
static gboolean
|
2010-11-09 14:02:28 +03:00
|
|
|
parse_mc_e_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error)
|
2010-05-12 11:12:27 +04:00
|
|
|
{
|
|
|
|
(void) option_name;
|
|
|
|
(void) data;
|
|
|
|
(void) error;
|
|
|
|
|
|
|
|
mc_run_mode = MC_RUN_EDITOR;
|
|
|
|
mc_run_param0 = g_strdup (value);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-09 14:02:28 +03:00
|
|
|
parse_mc_v_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error)
|
2010-05-12 11:12:27 +04:00
|
|
|
{
|
|
|
|
(void) option_name;
|
|
|
|
(void) data;
|
|
|
|
(void) error;
|
|
|
|
|
|
|
|
mc_run_mode = MC_RUN_VIEWER;
|
|
|
|
mc_run_param0 = g_strdup (value);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-09-01 15:05:01 +04:00
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
gboolean
|
2010-05-12 10:29:57 +04:00
|
|
|
mc_args_handle (int argc, char **argv, const char *translation_domain)
|
2009-09-01 15:05:01 +04:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2010-04-23 11:54:25 +04:00
|
|
|
const gchar *_system_codepage = str_detect_termencoding ();
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2009-11-20 12:11:31 +03:00
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
if (!str_isutf8 (_system_codepage))
|
2010-04-23 11:54:25 +04:00
|
|
|
bind_textdomain_codeset ("mc", "UTF-8");
|
2009-11-20 12:11:31 +03:00
|
|
|
#endif
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
context = g_option_context_new (mc_args_add_usage_info ());
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
g_option_context_set_ignore_unknown_options (context, FALSE);
|
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
mc_args_add_extended_info_to_help ();
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
main_group = g_option_group_new ("main", _("Main options"), _("Main options"), NULL, NULL);
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
g_option_group_add_entries (main_group, argument_main_table);
|
|
|
|
g_option_context_set_main_group (context, main_group);
|
2010-04-23 11:54:25 +04:00
|
|
|
g_option_group_set_translation_domain (main_group, translation_domain);
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
terminal_group = g_option_group_new ("terminal", _("Terminal options"),
|
2010-04-23 11:54:25 +04:00
|
|
|
_("Terminal options"), NULL, NULL);
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
g_option_group_add_entries (terminal_group, argument_terminal_table);
|
|
|
|
g_option_context_add_group (context, terminal_group);
|
2010-04-23 11:54:25 +04:00
|
|
|
g_option_group_set_translation_domain (terminal_group, translation_domain);
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
color_group = mc_args_new_color_group ();
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
g_option_group_add_entries (color_group, argument_color_table);
|
|
|
|
g_option_context_add_group (context, color_group);
|
2010-04-23 11:54:25 +04:00
|
|
|
g_option_group_set_translation_domain (color_group, translation_domain);
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2010-05-12 10:29:57 +04:00
|
|
|
if (!g_option_context_parse (context, &argc, &argv, &error))
|
2010-04-23 11:54:25 +04:00
|
|
|
{
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
gchar *full_help_str;
|
|
|
|
gchar *help_str;
|
2009-09-01 15:05:01 +04:00
|
|
|
|
|
|
|
#if GLIB_CHECK_VERSION(2,14,0)
|
2010-04-23 11:54:25 +04:00
|
|
|
help_str = g_option_context_get_help (context, TRUE, NULL);
|
2009-09-01 15:05:01 +04:00
|
|
|
#else
|
2010-04-23 11:54:25 +04:00
|
|
|
help_str = g_strdup ("");
|
2009-09-01 15:05:01 +04:00
|
|
|
#endif
|
2010-04-23 11:54:25 +04:00
|
|
|
if (!str_isutf8 (_system_codepage))
|
|
|
|
full_help_str =
|
|
|
|
mc_args__convert_help_to_syscharset (_system_codepage, error->message,
|
|
|
|
help_str);
|
|
|
|
else
|
|
|
|
full_help_str = g_strdup_printf ("%s\n\n%s\n", error->message, help_str);
|
|
|
|
|
|
|
|
fprintf (stderr, "%s", full_help_str);
|
|
|
|
|
|
|
|
g_free (help_str);
|
|
|
|
g_free (full_help_str);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_option_context_free (context);
|
|
|
|
mc_args_clean_temp_help_strings ();
|
|
|
|
return FALSE;
|
2009-09-01 15:05:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_option_context_free (context);
|
2010-04-23 11:54:25 +04:00
|
|
|
mc_args_clean_temp_help_strings ();
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2009-11-20 12:11:31 +03:00
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
if (!str_isutf8 (_system_codepage))
|
2010-04-23 11:54:25 +04:00
|
|
|
bind_textdomain_codeset ("mc", _system_codepage);
|
2009-11-20 12:11:31 +03:00
|
|
|
#endif
|
2009-09-01 15:05:01 +04:00
|
|
|
|
2010-05-12 10:29:57 +04:00
|
|
|
return mc_args_process (argc, argv);
|
2009-09-01 15:05:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|