Ticket #390: remove own 'libpopt' stuff.

We really not need for all libpopt features.
As fact, simple POSIX getopt() is enough.
But if we have glib - we must use glib for unification.

Created two files: src/args.c and src/args.h
Parce of command line options now processed in these files.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2009-09-01 14:05:01 +03:00
parent 0ce827bb60
commit 88b4ce4cbe
17 changed files with 544 additions and 1758 deletions

View File

@ -50,22 +50,20 @@ mc_LDADD = $(EDITLIB) $(VFSLIB) \
CHARSET_SRC = charsets.c charsets.h selcodepage.c selcodepage.h
SRCS = achown.c achown.h background.c background.h boxes.c boxes.h \
chmod.c chmod.h chown.c chown.h cmd.c cmd.h \
SRCS = args.c args.h achown.c achown.h background.c background.h \
boxes.c boxes.h chmod.c chmod.h chown.c chown.h cmd.c cmd.h \
command.c command.h complete.c cons.handler.c \
cons.saver.h dialog.c dialog.h dir.c dir.h \
execute.c execute.h ext.c ext.h file.c filegui.c \
filegui.h file.h filenot.c fileopctx.c fileopctx.h find.c \
find.h findme.c findme.h fs.h \
find.h fs.h \
glibcompat.c glibcompat.h global.h help.c help.h hotlist.c \
hotlist.h info.c info.h layout.c \
layout.h learn.c learn.h listmode.c listmode.h history.h \
logging.h logging.c main.c main.h main-widgets.h \
menu.c menu.h mountlist.c mountlist.h \
option.c option.h panel.h panelize.c panelize.h poptalloca.h \
popt.c poptconfig.c popt.h popthelp.c poptint.h poptparse.c \
screen.c setup.c setup.h \
subshell.c subshell.h textconf.c textconf.h \
option.c option.h panel.h panelize.c panelize.h screen.c \
setup.c setup.h subshell.c subshell.h textconf.c textconf.h \
tree.c tree.h treestore.c treestore.h timefmt.h user.c \
user.h util.c util.h utilunix.c vfsdummy.h \
widget.c widget.h wtools.c wtools.h unixcompat.h \

474
src/args.c Normal file
View File

@ -0,0 +1,474 @@
/*
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>
#include <stdio.h>
#include "../src/global.h"
#include "../src/tty/tty.h"
#include "../src/args.h"
#include "../src/strutil.h"
/*** external variables **************************************************************************/
extern int reset_hp_softkeys;
extern int use_subshell;
extern char *mc_home;
extern char *mc_home_alt;
/* colors specified on the command line: they override any other setting */
extern char *command_line_colors;
extern const char *edit_one_file;
extern const char *view_one_file;
/*** global variables ****************************************************************************/
/* If true, show version info and exit */
gboolean mc_args__version = FALSE;
/* 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;
char *mc_args__last_wd_file = NULL;
/* when enabled NETCODE, use folowing file as logfile */
char *mc_args__netfs_logfile = NULL;
/* Debug level*/
int mc_args__debug_level = 0;
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
static GOptionContext *context;
static gboolean mc_args__nouse_subshell = FALSE;
static gboolean mc_args__show_datadirs = FALSE;
GOptionGroup *main_group;
static const GOptionEntry argument_main_table[] = {
/* generic options */
{
"version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
&mc_args__version,
N_("Displays the current version"),
NULL
},
/* options for wrappers */
{
"datadir", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
&mc_args__show_datadirs,
N_("Print data directory"),
NULL
},
{
"printwd", 'P', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&mc_args__last_wd_file,
N_("Print last working directory to specified file"),
"<file>"
},
#ifdef HAVE_SUBSHELL_SUPPORT
{
"subshell", 'U', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
&use_subshell,
N_("Enables subshell support (default)"),
NULL
},
{
"nosubshell", 'u', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
&mc_args__nouse_subshell,
N_("Disables subshell support"),
NULL
},
#endif
/* debug options */
#ifdef USE_NETCODE
{
"ftplog", 'l', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&mc_args__netfs_logfile,
N_("Log ftp dialog to specified file"),
"<file>"
},
#ifdef WITH_SMBFS
{
"debuglevel", 'D', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT,
&mc_args__debug_level,
N_("Set debug level"),
"<integer>"
},
#endif
#endif
/* single file operations */
{
"view", 'v', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&view_one_file,
N_("Launches the file viewer on a file"),
"<file>"
},
{
"edit", 'e', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&edit_one_file,
N_("Edits one file"),
"<file>"
},
{NULL}
};
GOptionGroup *terminal_group;
#define ARGS_TERM_OPTIONS 0
static const GOptionEntry argument_terminal_table[] = {
/* terminal options */
{
"xterm", 'x', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
&mc_args__force_xterm,
N_("Forces xterm features"),
NULL
},
{
"nomouse", 'd', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
&mc_args__nomouse,
N_("Disable mouse support in text version"),
NULL
},
#ifdef HAVE_SLANG
{
"termcap", 't', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
&SLtt_Try_Termcap,
N_("Tries to use termcap instead of terminfo"),
NULL
},
#endif
{
"slow", 's', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
&mc_args__slow_terminal,
N_("To run on slow terminals"),
NULL
},
{
"stickchars", 'a', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
&mc_args__ugly_line_drawing,
N_("Use stickchars to draw"),
NULL
},
{
"resetsoft", 'k', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
&reset_hp_softkeys,
N_("Resets soft keys on HP terminals"),
NULL
},
{NULL}
};
#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[] = {
/* color options */
{
"nocolor", 'b', ARGS_COLOR_OPTIONS, G_OPTION_ARG_NONE,
&mc_args__disable_colors,
N_("Requests to run in black and white"),
NULL
},
{
"color", 'c', ARGS_COLOR_OPTIONS, G_OPTION_ARG_NONE,
&mc_args__force_colors,
N_("Request to run in color mode"),
NULL
},
{
"colors", 'C', ARGS_COLOR_OPTIONS, G_OPTION_ARG_STRING,
&command_line_colors,
N_("Specifies a color configuration"),
"<string>"
},
{NULL}
};
#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
mc_args_clean_temp_help_strings(void)
{
g_free(mc_args__loc__colors_string);
mc_args__loc__colors_string = NULL;
g_free(mc_args__loc__footer_string);
mc_args__loc__footer_string = NULL;
g_free(mc_args__loc__header_string);
mc_args__loc__header_string = NULL;
g_free(mc_args__loc__usage_string);
mc_args__loc__usage_string = NULL;
}
/* --------------------------------------------------------------------------------------------- */
static GOptionGroup *
mc_args_new_color_group(void)
{
/*
* FIXME: undocumented keywords: viewunderline, editnormal, editbold,
* and editmarked. To preserve translations, lines should be split.
*/
/* TRANSLATORS: don't translate keywords and names of colors */
mc_args__loc__colors_string = g_strdup_printf("%s%s",
_
("--colors KEYWORD={FORE},{BACK}\n\n"
"{FORE} and {BACK} can be omitted, and the default will be used\n"
"\n" "Keywords:\n"
" Global: errors, reverse, gauge, input, viewunderline\n"
" File display: normal, selected, marked, markselect\n"
" Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus, errdhotnormal,\n"
" errdhotfocus\n"
" Menus: menu, menuhot, menusel, menuhotsel\n"
" Editor: editnormal, editbold, editmarked, editwhitespace,\n"
" editlinestate\n"),
_
(
" Help: helpnormal, helpitalic, helpbold, helplink, helpslink\n"
" File types: directory, executable, link, stalelink, device, special, core\n"
"\n" "Colors:\n"
" black, gray, red, brightred, green, brightgreen, brown,\n"
" yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
" brightcyan, lightgray and white\n\n")
);
return g_option_group_new ("color", mc_args__loc__colors_string,
_("Color options"),NULL, NULL);
}
/* --------------------------------------------------------------------------------------------- */
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")
);
return mc_args__loc__usage_string;
}
/* --------------------------------------------------------------------------------------------- */
static void
mc_args_add_extended_info_to_help(void)
{
mc_args__loc__footer_string = g_strdup_printf("%s",
_
("\n"
"Please send any bug reports (including the output of `mc -V')\n"
"to mc-devel@gnome.org\n")
);
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
}
/* --------------------------------------------------------------------------------------------- */
static gboolean
mc_args_process(void)
{
if (mc_args__version){
show_version ();
return FALSE;
}
if (mc_args__show_datadirs){
printf ("%s (%s)\n", mc_home, mc_home_alt);
return FALSE;
}
if (mc_args__force_colors)
mc_args__disable_colors = FALSE;
#ifdef HAVE_SUBSHELL_SUPPORT
if (mc_args__nouse_subshell)
use_subshell = 0;
if (mc_args__nouse_subshell)
use_subshell = 0;
#endif /* HAVE_SUBSHELL_SUPPORT */
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
static gchar *
mc_args__convert_help_to_syscharset(const gchar *charset, const gchar *error_message, const gchar *help_str)
{
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);
str_convert (conv, full_help_str, buffer);
g_free(full_help_str);
g_iconv_close (conv);
return g_string_free(buffer, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
gboolean
mc_args_handle(int *argc, char ***argv, const gchar *translation_domain)
{
GError *error = NULL;
const gchar *_system_codepage = str_detect_termencoding();
if ( !str_isutf8 (_system_codepage))
bind_textdomain_codeset ("mc", "UTF-8");
context = g_option_context_new (mc_args_add_usage_info());
g_option_context_set_ignore_unknown_options (context, FALSE);
mc_args_add_extended_info_to_help();
main_group = g_option_group_new ("main", _("Main options"),
_("Main options"),NULL, NULL);
g_option_group_add_entries (main_group, argument_main_table);
g_option_context_set_main_group (context, main_group);
g_option_group_set_translation_domain(main_group, translation_domain);
terminal_group = g_option_group_new ("terminal", _("Terminal options"),
_("Terminal options"),NULL, NULL);
g_option_group_add_entries (terminal_group, argument_terminal_table);
g_option_context_add_group (context, terminal_group);
g_option_group_set_translation_domain(terminal_group, translation_domain);
color_group = mc_args_new_color_group();
g_option_group_add_entries (color_group, argument_color_table);
g_option_context_add_group (context, color_group);
g_option_group_set_translation_domain(color_group, translation_domain);
if (! g_option_context_parse (context, argc, argv, &error)) {
if (error != NULL)
{
gchar *full_help_str;
gchar *help_str;
#if GLIB_CHECK_VERSION(2,14,0)
help_str = g_option_context_get_help (context, TRUE, NULL);
#else
help_str = g_strdup("");
#endif
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;
}
g_option_context_free (context);
mc_args_clean_temp_help_strings();
if ( !str_isutf8 (_system_codepage))
bind_textdomain_codeset ("mc", _system_codepage);
return mc_args_process();
}
/* --------------------------------------------------------------------------------------------- */

27
src/args.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef MC__ARGS_H
#define MC__ARGS_H
/*** typedefs(not structures) and defined constants **********************************************/
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
/*** global variables defined in .c file *********************************************************/
extern gboolean mc_args__force_xterm;
extern gboolean mc_args__nomouse;
extern gboolean mc_args__slow_terminal;
extern gboolean mc_args__ugly_line_drawing;
extern gboolean mc_args__disable_colors;
extern gboolean mc_args__force_colors;
extern gboolean mc_args__version;
extern char *mc_args__last_wd_file;
extern char *mc_args__netfs_logfile;
extern int mc_args__debug_level;
/*** declarations of public functions ************************************************************/
gboolean mc_args_handle(int *, char ***, const gchar *);
#endif

View File

@ -1,61 +0,0 @@
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
/** \file findme.c
* \brief Source: findProgramPath function
*/
#include <config.h>
#include "poptalloca.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef __NeXT
/* access macros are not declared in non posix mode in unistd.h -
don't try to use posix on NeXTstep 3.3 ! */
#include <libc.h>
#endif
#include "findme.h"
const char * findProgramPath(const char * argv0) {
char * path = getenv("PATH");
char * pathbuf;
char * start, * chptr;
char * buf;
/* If there is a / in the argv[0], it has to be an absolute
path */
if (strchr(argv0, '/'))
return strdup(argv0);
if (!path) return NULL;
start = pathbuf = alloca(strlen(path) + 1);
buf = malloc(strlen(path) + strlen(argv0) + 2);
strcpy(pathbuf, path);
chptr = NULL;
do {
if ((chptr = strchr(start, ':')))
*chptr = '\0';
sprintf(buf, "%s/%s", start, argv0);
if (!access(buf, X_OK))
return buf;
if (chptr)
start = chptr + 1;
else
start = NULL;
} while (start && *start);
free(buf);
return NULL;
}

View File

@ -1,14 +0,0 @@
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
/** \file findme.h
* \brief Header: findProgramPath function
*/
#ifndef MC_FINDME_H
#define MC_FINDME_H
const char * findProgramPath(const char * argv0);
#endif

View File

@ -48,6 +48,7 @@
#include "../src/tty/win.h" /* xterm_flag */
#include "../src/mcconfig/mcconfig.h"
#include "../src/args.h"
#include "dir.h"
#include "dialog.h"
@ -97,8 +98,6 @@
#include "../vfs/gc.h"
#endif
#include "popt.h"
/* When the modes are active, left_panel, right_panel and tree_panel */
/* Point to a proper data structure. You should check with the functions */
/* get_current_type and get_other_type the types of the panels before using */
@ -202,18 +201,9 @@ WLabel *the_hint;
/* The button bar */
WButtonBar *the_bar;
/* For slow terminals */
static int slow_terminal = 0;
/* If true use +, -, | for line drawing */
static int ugly_line_drawing = 0;
/* Mouse type: GPM, xterm or none */
Mouse_Type use_mouse_p = MOUSE_NONE;
/* If true, assume we are running on an xterm terminal */
static int force_xterm = 0;
/* If on, default for "No" in delete operations */
int safe_delete = 0;
@ -272,21 +262,12 @@ static char *this_dir = NULL;
int xtree_mode = 0;
/* If set, then print to the given file the last directory we were at */
static char *last_wd_file = NULL;
static char *last_wd_string = NULL;
/* Set to 1 to suppress printing the last directory */
static int print_last_revert = 0;
/* Set to force black and white display at program startup */
static gboolean disable_colors = FALSE;
/* Force colors, only used by Slang */
static gboolean force_colors = FALSE;
/* colors specified on the command line: they override any other setting */
char *command_line_colors = NULL;
/* File name to view if argument was supplied */
static const char *view_one_file = NULL;
const char *view_one_file = NULL;
/* File name to edit if argument was supplied */
const char *edit_one_file = NULL;
@ -1215,11 +1196,11 @@ init_xterm_support (void)
xmouse_seq = tty_tgetstr ("Km");
if (strcmp (termvalue, "cygwin") == 0) {
force_xterm = 1;
mc_args__force_xterm = 1;
use_mouse_p = MOUSE_DISABLED;
}
if (force_xterm || strncmp (termvalue, "xterm", 5) == 0
if (mc_args__force_xterm || strncmp (termvalue, "xterm", 5) == 0
|| strncmp (termvalue, "konsole", 7) == 0
|| strncmp (termvalue, "rxvt", 4) == 0
|| strcmp (termvalue, "Eterm") == 0
@ -1706,7 +1687,7 @@ do_nc (void)
midnight_shutdown = 1;
/* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
if (last_wd_file && vfs_current_is_local ()) {
if (mc_args__last_wd_file && vfs_current_is_local ()) {
last_wd_string = g_strdup (current_panel->cwd);
}
done_mc ();
@ -1821,208 +1802,36 @@ init_sigchld (void)
}
static void
print_mc_usage (poptContext ctx, FILE *stream)
mc_main__setup_by_args(int argc, char *argv[])
{
int leftColWidth;
const char *base;
char *tmp;
poptSetOtherOptionHelp (ctx,
_("[flags] [this_dir] [other_panel_dir]\n"));
/* print help for options */
leftColWidth = poptPrintHelp (ctx, stream, 0);
fprintf (stream, " %-*s %s\n", leftColWidth, _("+number"),
_("Set initial line number for the internal editor"));
fputs (_
("\n"
"Please send any bug reports (including the output of `mc -V')\n"
"to mc-devel@gnome.org\n"), stream);
show_version (0);
}
static void
print_color_usage (void)
{
/*
* FIXME: undocumented keywords: viewunderline, editnormal, editbold,
* and editmarked. To preserve translations, lines should be split.
*/
/* TRANSLATORS: don't translate keywords and names of colors */
fputs (_
("--colors KEYWORD={FORE},{BACK}\n\n"
"{FORE} and {BACK} can be omitted, and the default will be used\n"
"\n" "Keywords:\n"
" Global: errors, reverse, gauge, input, viewunderline\n"
" File display: normal, selected, marked, markselect\n"
" Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus, errdhotnormal,\n"
" errdhotfocus\n"
" Menus: menu, menuhot, menusel, menuhotsel\n"
" Editor: editnormal, editbold, editmarked, editwhitespace,\n"
" editlinestate\n"), stdout);
fputs (_
(
" Help: helpnormal, helpitalic, helpbold, helplink, helpslink\n"
" File types: directory, executable, link, stalelink, device, special, core\n"
"\n" "Colors:\n"
" black, gray, red, brightred, green, brightgreen, brown,\n"
" yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
" brightcyan, lightgray and white\n\n"), stdout);
}
static void
process_args (poptContext ctx, int c, const char *option_arg)
{
switch (c) {
case 'V':
show_version (1);
exit (0);
break;
case 'c':
disable_colors = FALSE;
force_colors = TRUE; /* for S-Lang only */
break;
case 'f':
printf ("%s (%s)\n", mc_home, mc_home_alt);
exit (0);
break;
if (mc_args__nomouse)
use_mouse_p = MOUSE_DISABLED;
#ifdef USE_NETCODE
case 'l':
mc_setctl ("/#ftp:", VFS_SETCTL_LOGFILE, (void *) option_arg);
if (mc_args__netfs_logfile != NULL)
{
mc_setctl ("/#ftp:", VFS_SETCTL_LOGFILE, (void *) mc_args__netfs_logfile);
#ifdef WITH_SMBFS
smbfs_set_debugf (option_arg);
smbfs_set_debugf (mc_args__netfs_logfile);
#endif /* WITH_SMBFS */
break;
}
#ifdef WITH_SMBFS
case 'D':
smbfs_set_debug (atoi (option_arg));
break;
if (mc_args__debug_level != 0)
{
smbfs_set_debug (mc_args__debug_level);
}
#endif /* WITH_SMBFS */
#endif /* USE_NETCODE */
case 'd':
use_mouse_p = MOUSE_DISABLED;
break;
#ifdef HAVE_SUBSHELL_SUPPORT
case 'u':
use_subshell = 0;
break;
#endif /* HAVE_SUBSHELL_SUPPORT */
case 'H':
print_color_usage ();
exit (0);
break;
case 'h':
print_mc_usage (ctx, stdout);
exit (0);
}
}
static const struct poptOption argument_table[] = {
/* generic options */
{"help", 'h', POPT_ARG_NONE, {NULL}, 'h',
N_("Displays this help message"), NULL},
{"version", 'V', POPT_ARG_NONE, {NULL}, 'V',
N_("Displays the current version"), NULL},
/* terminal options */
{"xterm", 'x', POPT_ARG_NONE, {&force_xterm}, 0,
N_("Forces xterm features"), NULL},
{"nomouse", 'd', POPT_ARG_NONE, {NULL}, 'd',
N_("Disable mouse support in text version"), NULL},
#ifdef HAVE_SLANG
{"termcap", 't', 0, {&SLtt_Try_Termcap}, 0,
N_("Tries to use termcap instead of terminfo"), NULL},
#endif
{"resetsoft", 'k', POPT_ARG_NONE, {&reset_hp_softkeys}, 0,
N_("Resets soft keys on HP terminals"), NULL},
{"slow", 's', POPT_ARG_NONE, {&slow_terminal}, 0,
N_("To run on slow terminals"), NULL},
{"stickchars", 'a', POPT_ARG_NONE, {&ugly_line_drawing}, 0,
N_("Use stickchars to draw"), NULL},
/* color options */
{"nocolor", 'b', POPT_ARG_NONE, {&disable_colors}, 0,
N_("Requests to run in black and white"), NULL},
{"color", 'c', POPT_ARG_NONE, {NULL}, 'c',
N_("Request to run in color mode"), NULL},
{"colors", 'C', POPT_ARG_STRING, {&command_line_colors}, 0,
N_("Specifies a color configuration"), NULL},
{"help-colors", 'H', POPT_ARG_NONE, {NULL}, 'H',
N_("Displays a help screen on how to change the color scheme"), NULL},
/* debug options */
#ifdef USE_NETCODE
{"ftplog", 'l', POPT_ARG_STRING, {NULL}, 'l',
N_("Log ftp dialog to specified file"), NULL},
#ifdef WITH_SMBFS
{"debuglevel", 'D', POPT_ARG_STRING, {NULL}, 'D',
N_("Set debug level"), NULL},
#endif
#endif
/* options for wrappers */
{"datadir", 'f', POPT_ARG_NONE, {NULL}, 'f',
N_("Print data directory"), NULL},
{"printwd", 'P', POPT_ARG_STRING, {&last_wd_file}, 0,
N_("Print last working directory to specified file"), NULL},
/* subshell options */
#ifdef HAVE_SUBSHELL_SUPPORT
{"subshell", 'U', POPT_ARG_NONE, {&use_subshell}, 0,
N_("Enables subshell support (default)"), NULL},
{"nosubshell", 'u', POPT_ARG_NONE, {NULL}, 'u',
N_("Disables subshell support"), NULL},
#endif
/* single file operations */
{"view", 'v', POPT_ARG_STRING, {&view_one_file}, 0,
N_("Launches the file viewer on a file"), NULL},
#ifdef USE_INTERNAL_EDIT
{"edit", 'e', POPT_ARG_STRING, {&edit_one_file}, 0,
N_("Edits one file"), NULL},
#endif
{NULL, '\0', 0, {NULL}, 0, NULL , NULL}
};
static void
handle_args (int argc, char *argv[])
{
char *tmp;
poptContext ctx;
const char *base;
int c;
ctx =
poptGetContext ("mc", argc, argv, argument_table,
POPT_CONTEXT_NO_EXEC);
while ((c = poptGetNextOpt (ctx)) > 0) {
process_args (ctx, c, poptGetOptArg (ctx));
}
if (c < -1) {
print_mc_usage (ctx, stderr);
fprintf (stderr, "%s: %s\n",
poptBadOption (ctx, POPT_BADOPTION_NOALIAS),
poptStrerror (c));
exit (1);
}
tmp = poptGetArg (ctx);
/*
* Check for special invocation names mcedit and mcview,
* if none apply then set the current directory and the other
* directory from the command line arguments
*/
base = x_basename (argv[0]);
tmp = (argc > 0)? argv[1] : NULL;
if (!STRNCOMP (base, "mce", 3) || !STRCOMP (base, "vi")) {
edit_one_file = "";
if (tmp) {
@ -2056,7 +1865,7 @@ handle_args (int argc, char *argv[])
if (*tmp == '+' && g_ascii_isdigit ((gchar) tmp[1])) {
int start_line = atoi (tmp);
if (start_line > 0) {
char *file = poptGetArg (ctx);
char *file = (argc > 1) ? argv[2] : NULL;
if (file) {
tmp = file;
edit_one_file_start_line = start_line;
@ -2077,12 +1886,13 @@ handle_args (int argc, char *argv[])
/* sets the current dir and the other dir */
if (tmp) {
this_dir = g_strdup (tmp);
if ((tmp = poptGetArg (ctx)))
tmp = (argc > 1) ? argv[2] : NULL;
if (tmp)
other_dir = g_strdup (tmp);
}
}
poptFreeContext (ctx);
}
int
@ -2113,7 +1923,10 @@ main (int argc, char *argv[])
SLtt_Ignore_Beep = 1;
#endif
handle_args (argc, argv);
if ( !mc_args_handle (&argc, &argv, "mc"))
return 1;
mc_main__setup_by_args(argc,argv);
/* NOTE: This has to be called before tty_init or whatever routine
calls any define_sequence */
@ -2139,11 +1952,11 @@ main (int argc, char *argv[])
/* Must be done before init_subshell, to set up the terminal size: */
/* FIXME: Should be removed and LINES and COLS computed on subshell */
tty_init ((gboolean) slow_terminal, (gboolean) ugly_line_drawing);
tty_init ((gboolean) mc_args__slow_terminal, (gboolean) mc_args__ugly_line_drawing);
load_setup ();
tty_init_colors (disable_colors, force_colors);
tty_init_colors (mc_args__disable_colors, mc_args__force_colors);
dlg_set_default_colors ();
/* create home directory */
@ -2210,10 +2023,10 @@ main (int argc, char *argv[])
handle_console (CONSOLE_DONE);
putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
if (last_wd_file && last_wd_string && !print_last_revert
if (mc_args__last_wd_file && last_wd_string && !print_last_revert
&& !edit_one_file && !view_one_file) {
int last_wd_fd =
open (last_wd_file, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL,
open (mc_args__last_wd_file, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL,
S_IRUSR | S_IWUSR);
if (last_wd_fd != -1) {

View File

@ -1,590 +0,0 @@
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
/** \file popt.c
* \brief Source: a module for parsing command line options
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "poptalloca.h"
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "global.h"
#include "findme.h"
#include "popt.h"
#include "poptint.h"
#ifndef HAVE_STRERROR
static char * strerror(int errno) {
extern int sys_nerr;
extern char * sys_errlist[];
if ((0 <= errno) && (errno < sys_nerr))
return sys_errlist[errno];
else
return POPT_("unknown errno");
}
#endif
void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) {
if (con->execPath) free(con->execPath);
con->execPath = strdup(path);
con->execAbsolute = allowAbsolute;
}
static void invokeCallbacks(poptContext con, const struct poptOption * table,
int post) {
const struct poptOption * opt = table;
while (opt->longName || opt->shortName || opt->arg.p) {
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
invokeCallbacks(con, opt->arg.p, post);
} else if (((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) &&
((!post && (opt->argInfo & POPT_CBFLAG_PRE)) ||
( post && (opt->argInfo & POPT_CBFLAG_POST)))) {
opt->arg.f1(con, post ? POPT_CALLBACK_REASON_POST : POPT_CALLBACK_REASON_PRE,
NULL, NULL, opt->descrip);
}
opt++;
}
}
poptContext poptGetContext(const char * name, int argc, char ** argv,
const struct poptOption * options, int flags) {
poptContext con = malloc(sizeof(*con));
memset(con, 0, sizeof(*con));
con->os = con->optionStack;
con->os->argc = argc;
con->os->argv = argv;
if (!(flags & POPT_CONTEXT_KEEP_FIRST))
con->os->next = 1; /* skip argv[0] */
con->leftovers = malloc(sizeof(char *) * (argc + 1));
con->options = options;
con->finalArgv = malloc(sizeof(*con->finalArgv) * (argc * 2));
con->finalArgvAlloced = argc * 2;
con->flags = flags;
con->execAbsolute = 1;
if (getenv("POSIXLY_CORRECT") || getenv("POSIX_ME_HARDER"))
con->flags |= POPT_CONTEXT_POSIXMEHARDER;
if (name)
con->appName = strcpy(malloc(strlen(name) + 1), name);
invokeCallbacks(con, con->options, 0);
return con;
}
void poptResetContext(poptContext con) {
int i;
con->os = con->optionStack;
con->os->currAlias = NULL;
con->os->nextCharArg = NULL;
con->os->nextArg = NULL;
con->os->next = 1; /* skip argv[0] */
con->numLeftovers = 0;
con->nextLeftover = 0;
con->restLeftover = 0;
con->doExec = NULL;
for (i = 0; i < con->finalArgvCount; i++)
free(con->finalArgv[i]);
con->finalArgvCount = 0;
}
/* Only one of longName, shortName may be set at a time */
static int handleExec(poptContext con, char * longName, char shortName) {
int i;
i = con->numExecs - 1;
if (longName) {
while (i >= 0 && (!con->execs[i].longName ||
strcmp(con->execs[i].longName, longName))) i--;
} else {
while (i >= 0 &&
con->execs[i].shortName != shortName) i--;
}
if (i < 0) return 0;
if (con->flags & POPT_CONTEXT_NO_EXEC)
return 1;
if (!con->doExec) {
con->doExec = con->execs + i;
return 1;
}
/* We already have an exec to do; remember this option for next
time 'round */
if ((con->finalArgvCount + 1) >= (con->finalArgvAlloced)) {
con->finalArgvAlloced += 10;
con->finalArgv = realloc(con->finalArgv,
sizeof(*con->finalArgv) * con->finalArgvAlloced);
}
i = con->finalArgvCount++;
con->finalArgv[i] = malloc((longName ? strlen(longName) : 0) + 3);
if (longName)
sprintf(con->finalArgv[i], "--%s", longName);
else
sprintf(con->finalArgv[i], "-%c", shortName);
return 1;
}
/* Only one of longName, shortName may be set at a time */
static int handleAlias(poptContext con, char * longName, char shortName,
char * nextCharArg) {
int i;
if (con->os->currAlias && con->os->currAlias->longName && longName &&
!strcmp(con->os->currAlias->longName, longName))
return 0;
if (con->os->currAlias && shortName &&
shortName == con->os->currAlias->shortName)
return 0;
i = con->numAliases - 1;
if (longName) {
while (i >= 0 && (!con->aliases[i].longName ||
strcmp(con->aliases[i].longName, longName))) i--;
} else {
while (i >= 0 &&
con->aliases[i].shortName != shortName) i--;
}
if (i < 0) return 0;
if ((con->os - con->optionStack + 1)
== POPT_OPTION_DEPTH)
return POPT_ERROR_OPTSTOODEEP;
if (nextCharArg && *nextCharArg)
con->os->nextCharArg = nextCharArg;
con->os++;
con->os->next = 0;
con->os->stuffed = 0;
con->os->nextArg = con->os->nextCharArg = NULL;
con->os->currAlias = con->aliases + i;
con->os->argc = con->os->currAlias->argc;
con->os->argv = con->os->currAlias->argv;
return 1;
}
static void execCommand(poptContext con) {
#if 0
char ** argv;
int pos = 0;
char * script = con->doExec->script;
argv = malloc(sizeof(*argv) *
(6 + con->numLeftovers + con->finalArgvCount));
if (!con->execAbsolute && strchr(script, '/')) return;
if (!strchr(script, '/') && con->execPath) {
argv[pos] = alloca(strlen(con->execPath) + strlen(script) + 2);
sprintf(argv[pos], "%s/%s", con->execPath, script);
} else {
argv[pos] = script;
}
pos++;
argv[pos] = findProgramPath(con->os->argv[0]);
if (argv[pos]) pos++;
argv[pos++] = ";";
memcpy(argv + pos, con->finalArgv, sizeof(*argv) * con->finalArgvCount);
pos += con->finalArgvCount;
if (con->numLeftovers) {
argv[pos++] = "--";
memcpy(argv + pos, con->leftovers, sizeof(*argv) * con->numLeftovers);
pos += con->numLeftovers;
}
argv[pos++] = NULL;
execvp(argv[0], argv);
#else
(void) con;
abort();
#endif
}
static const struct poptOption * findOption(const struct poptOption * table,
const char * longName,
char shortName,
poptCallbackType * callback,
void ** callbackData,
int singleDash) {
const struct poptOption * opt = table;
const struct poptOption * opt2;
const struct poptOption * cb = NULL;
/* This happens when a single - is given */
if (singleDash && !shortName && !*longName)
shortName = '-';
while (opt->longName || opt->shortName || opt->arg.p) {
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
opt2 = findOption(opt->arg.p, longName, shortName, callback,
callbackData, singleDash);
if (opt2) {
if (*callback && !*callbackData)
*callbackData = opt->descrip;
return opt2;
}
} else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) {
cb = opt;
} else if (longName && opt->longName &&
(!singleDash || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) &&
!strcmp(longName, opt->longName)) {
break;
} else if (shortName && shortName == opt->shortName) {
break;
}
opt++;
}
if (!opt->longName && !opt->shortName) return NULL;
*callbackData = NULL;
*callback = NULL;
if (cb) {
*callback = cb->arg.f2;
if (!(cb->argInfo & POPT_CBFLAG_INC_DATA))
*callbackData = cb->descrip;
}
return opt;
}
/* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
int poptGetNextOpt(poptContext con) {
char * optString, * chptr, * localOptString;
char * longArg = NULL;
char * origOptString;
long aLong;
char * end;
const struct poptOption * opt = NULL;
int done = 0;
int i;
poptCallbackType cb;
void * cbData;
int singleDash;
while (!done) {
while (!con->os->nextCharArg && con->os->next == con->os->argc
&& con->os > con->optionStack)
con->os--;
if (!con->os->nextCharArg && con->os->next == con->os->argc) {
invokeCallbacks(con, con->options, 1);
if (con->doExec) execCommand(con);
return -1;
}
if (!con->os->nextCharArg) {
origOptString = con->os->argv[con->os->next++];
if (con->restLeftover || *origOptString != '-') {
con->leftovers[con->numLeftovers++] = origOptString;
if (con->flags & POPT_CONTEXT_POSIXMEHARDER)
con->restLeftover = 1;
continue;
}
/* Make a copy we can hack at */
localOptString = optString =
strcpy(alloca(strlen(origOptString) + 1),
origOptString);
if (!optString[0])
return POPT_ERROR_BADOPT;
if (optString[1] == '-' && !optString[2]) {
con->restLeftover = 1;
continue;
} else {
optString++;
if (*optString == '-')
singleDash = 0, optString++;
else
singleDash = 1;
if (handleAlias(con, optString, '\0', NULL))
continue;
if (handleExec(con, optString, '\0'))
continue;
chptr = optString;
while (*chptr && *chptr != '=') chptr++;
if (*chptr == '=') {
longArg = origOptString + (chptr - localOptString) + 1;
*chptr = '\0';
}
opt = findOption(con->options, optString, '\0', &cb, &cbData,
singleDash);
if (!opt && !singleDash) return POPT_ERROR_BADOPT;
}
if (!opt)
con->os->nextCharArg = origOptString + 1;
}
if (con->os->nextCharArg) {
origOptString = con->os->nextCharArg;
con->os->nextCharArg = NULL;
if (handleAlias(con, NULL, *origOptString,
origOptString + 1)) {
origOptString++;
continue;
}
if (handleExec(con, NULL, *origOptString))
continue;
opt = findOption(con->options, NULL, *origOptString, &cb,
&cbData, 0);
if (!opt) return POPT_ERROR_BADOPT;
origOptString++;
if (*origOptString)
con->os->nextCharArg = origOptString;
}
if (opt->arg.p && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) {
*((int *)opt->arg.p) = 1;
} else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) {
if (opt->arg.p) *((int *) opt->arg.p) = opt->val;
} else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) {
if (longArg) {
con->os->nextArg = longArg;
} else if (con->os->nextCharArg) {
con->os->nextArg = con->os->nextCharArg;
con->os->nextCharArg = NULL;
} else {
while (con->os->next == con->os->argc &&
con->os > con->optionStack)
con->os--;
if (con->os->next == con->os->argc)
return POPT_ERROR_NOARG;
con->os->nextArg = con->os->argv[con->os->next++];
}
if (opt->arg.p) {
switch (opt->argInfo & POPT_ARG_MASK) {
case POPT_ARG_STRING:
*((char **) opt->arg.p) = con->os->nextArg;
break;
case POPT_ARG_INT:
case POPT_ARG_LONG:
aLong = strtol(con->os->nextArg, &end, 0);
if (!(end && *end == '\0'))
return POPT_ERROR_BADNUMBER;
if (aLong == LONG_MIN || aLong == LONG_MAX)
return POPT_ERROR_OVERFLOW;
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
*((long *) opt->arg.p) = aLong;
} else {
if (aLong > INT_MAX || aLong < INT_MIN)
return POPT_ERROR_OVERFLOW;
*((int *) opt->arg.p) =aLong;
}
break;
default:
fprintf(stdout, POPT_("option type (%d) not implemented in popt\n"),
opt->argInfo & POPT_ARG_MASK);
exit(1);
}
}
}
if (cb)
cb(con, POPT_CALLBACK_REASON_OPTION, opt, con->os->nextArg, cbData);
else if (opt->val && ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL))
done = 1;
if ((con->finalArgvCount + 2) >= (con->finalArgvAlloced)) {
con->finalArgvAlloced += 10;
con->finalArgv = realloc(con->finalArgv,
sizeof(*con->finalArgv) * con->finalArgvAlloced);
}
i = con->finalArgvCount++;
con->finalArgv[i] =
malloc((opt->longName ? strlen(opt->longName) : 0) + 3);
if (opt->longName)
sprintf(con->finalArgv[i], "--%s", opt->longName);
else
sprintf(con->finalArgv[i], "-%c", opt->shortName);
if (opt->arg.p && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE
&& (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL)
con->finalArgv[con->finalArgvCount++] = strdup(con->os->nextArg);
}
return opt->val;
}
char * poptGetOptArg(poptContext con) {
char * ret = con->os->nextArg;
con->os->nextArg = NULL;
return ret;
}
char * poptGetArg(poptContext con) {
if (con->numLeftovers == con->nextLeftover) return NULL;
return (con->leftovers[con->nextLeftover++]);
}
char * poptPeekArg(poptContext con) {
if (con->numLeftovers == con->nextLeftover) return NULL;
return (con->leftovers[con->nextLeftover]);
}
char ** poptGetArgs(poptContext con) {
if (con->numLeftovers == con->nextLeftover) return NULL;
/* some apps like [like RPM ;-) ] need this NULL terminated */
con->leftovers[con->numLeftovers] = NULL;
return (con->leftovers + con->nextLeftover);
}
void poptFreeContext(poptContext con) {
int i;
for (i = 0; i < con->numAliases; i++) {
if (con->aliases[i].longName) free(con->aliases[i].longName);
free(con->aliases[i].argv);
}
for (i = 0; i < con->numExecs; i++) {
if (con->execs[i].longName) free(con->execs[i].longName);
free(con->execs[i].script);
}
for (i = 0; i < con->finalArgvCount; i++)
free(con->finalArgv[i]);
free(con->leftovers);
free(con->finalArgv);
if (con->appName) free(con->appName);
if (con->aliases) free(con->aliases);
if (con->otherHelp) free(con->otherHelp);
if (con->execPath) free(con->execPath);
free(con);
}
int poptAddAlias(poptContext con, struct poptAlias newAlias, int flags) {
int aliasNum = con->numAliases++;
struct poptAlias * alias;
(void) flags;
/* SunOS won't realloc(NULL, ...) */
if (!con->aliases)
con->aliases = malloc(sizeof(newAlias) * con->numAliases);
else
con->aliases = realloc(con->aliases,
sizeof(newAlias) * con->numAliases);
alias = con->aliases + aliasNum;
*alias = newAlias;
if (alias->longName)
alias->longName = strcpy(malloc(strlen(alias->longName) + 1),
alias->longName);
else
alias->longName = NULL;
return 0;
}
char * poptBadOption(poptContext con, int flags) {
struct optionStackEntry * os;
if (flags & POPT_BADOPTION_NOALIAS)
os = con->optionStack;
else
os = con->os;
return os->argv[os->next - 1];
}
#define POPT_ERROR_NOARG -10
#define POPT_ERROR_BADOPT -11
#define POPT_ERROR_OPTSTOODEEP -13
#define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */
#define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
const char * poptStrerror(const int error) {
switch (error) {
case POPT_ERROR_NOARG:
return _("missing argument");
case POPT_ERROR_BADOPT:
return _("unknown option");
case POPT_ERROR_OPTSTOODEEP:
return POPT_("aliases nested too deeply");
case POPT_ERROR_BADQUOTE:
return POPT_("error in parameter quoting");
case POPT_ERROR_BADNUMBER:
return _("invalid numeric value");
case POPT_ERROR_OVERFLOW:
return POPT_("number too large or too small");
case POPT_ERROR_ERRNO:
return strerror(errno);
default:
return POPT_("unknown error");
}
}
int poptStuffArgs(poptContext con, char ** argv) {
int i;
if ((con->os - con->optionStack) == POPT_OPTION_DEPTH)
return POPT_ERROR_OPTSTOODEEP;
for (i = 0; argv[i]; i++);
con->os++;
con->os->next = 0;
con->os->nextArg = con->os->nextCharArg = NULL;
con->os->currAlias = NULL;
con->os->argc = i;
con->os->argv = argv;
con->os->stuffed = 1;
return 0;
}
const char * poptGetInvocationName(poptContext con) {
return con->os->argv[0];
}

View File

@ -1,134 +0,0 @@
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
/** \file popt.h
* \brief Header: a module for parsing command line options
*/
#ifndef MC_POPT_H
#define MC_POPT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h> /* for FILE * */
#define POPT_OPTION_DEPTH 10
#define POPT_ARG_NONE 0
#define POPT_ARG_STRING 1
#define POPT_ARG_INT 2
#define POPT_ARG_LONG 3
#define POPT_ARG_INCLUDE_TABLE 4 /* arg points to table */
#define POPT_ARG_CALLBACK 5 /* table-wide callback... must be
set first in table; arg points
to callback, descrip points to
callback data to pass */
#define POPT_ARG_INTL_DOMAIN 6 /* set the translation domain
for this table and any
included tables; arg points
to the domain string */
#define POPT_ARG_VAL 7 /* arg should take value val */
#define POPT_ARG_MASK 0x0000FFFF
#define POPT_ARGFLAG_ONEDASH 0x80000000 /* allow -longoption */
#define POPT_ARGFLAG_DOC_HIDDEN 0x40000000 /* don't show in help/usage */
#define POPT_CBFLAG_PRE 0x80000000 /* call the callback before parse */
#define POPT_CBFLAG_POST 0x40000000 /* call the callback after parse */
#define POPT_CBFLAG_INC_DATA 0x20000000 /* use data from the include line,
not the subtable */
#define POPT_ERROR_NOARG -10
#define POPT_ERROR_BADOPT -11
#define POPT_ERROR_OPTSTOODEEP -13
#define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */
#define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
#define POPT_ERROR_BADNUMBER -17
#define POPT_ERROR_OVERFLOW -18
/* poptBadOption() flags */
#define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */
/* poptGetContext() flags */
#define POPT_CONTEXT_NO_EXEC (1 << 0) /* ignore exec expansions */
#define POPT_CONTEXT_KEEP_FIRST (1 << 1) /* pay attention to argv[0] */
#define POPT_CONTEXT_POSIXMEHARDER (1 << 2) /* options can't follow args */
struct poptOption;
enum poptCallbackReason { POPT_CALLBACK_REASON_PRE,
POPT_CALLBACK_REASON_POST,
POPT_CALLBACK_REASON_OPTION };
typedef struct poptContext_s * poptContext;
typedef void (*poptCallbackType)(poptContext con,
enum poptCallbackReason reason,
const struct poptOption * opt,
const char * arg, void * data);
typedef union {
void *p;
void (*f1)(poptContext , enum poptCallbackReason, struct poptOption *,
const char *, void *);
poptCallbackType f2;
} popt_arg_t;
struct poptOption {
const char * longName; /* may be NULL */
char shortName; /* may be '\0' */
int argInfo;
popt_arg_t arg; /* depends on argInfo */
int val; /* 0 means don't return, just update flag */
char * descrip; /* description for autohelp -- may be NULL */
const char * argDescrip; /* argument description for autohelp */
};
struct poptAlias {
char * longName; /* may be NULL */
char shortName; /* may be '\0' */
int argc;
char ** argv; /* must be free()able */
};
#ifndef __cplusplus
typedef struct poptOption * poptOption;
#endif
poptContext poptGetContext(const char * name, int argc, char ** argv,
const struct poptOption * options, int flags);
void poptResetContext(poptContext con);
/* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
int poptGetNextOpt(poptContext con);
/* returns NULL if no argument is available */
char * poptGetOptArg(poptContext con);
/* returns NULL if no more options are available */
char * poptGetArg(poptContext con);
char * poptPeekArg(poptContext con);
char ** poptGetArgs(poptContext con);
/* returns the option which caused the most recent error */
char * poptBadOption(poptContext con, int flags);
void poptFreeContext(poptContext con);
int poptStuffArgs(poptContext con, char ** argv);
int poptAddAlias(poptContext con, struct poptAlias alias, int flags);
int poptReadConfigFile(poptContext con, const char * fn);
/* like above, but reads /etc/popt and $HOME/.popt along with environment
vars */
int poptReadDefaultConfig(poptContext con, int useEnv);
/* argv should be freed -- this allows ', ", and \ quoting, but ' is treated
the same as " and both may include \ quotes */
int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr);
const char * poptStrerror(const int error);
void poptSetExecPath(poptContext con, const char * path, int allowAbsolute);
int poptPrintHelp(poptContext con, FILE * f, int flags);
void poptPrintUsage(poptContext con, FILE * f, int flags);
void poptSetOtherOptionHelp(poptContext con, const char * text);
const char * poptGetInvocationName(poptContext con);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,52 +0,0 @@
/** \file poptalloca.h
* \brief Header: definitions for alloca for popt
*
* Definitions for alloca (mostly extracted from AC_FUNC_ALLOCA). According
* to the autoconf manual in dome versions of AIX the declaration of alloca
* has to precede everything else execept comments and prepocessor directives,
* i.e. including this file has to preceed anything else.
*
* NOTE: alloca is redefined as malloc on systems which fail to support alloca.
* Don't include this header if you frequently use alloca in order to avoid an
* unlimited amount of memory leaks.
* popt uses alloca only during program startup, i.e. the memory leaks caused
* by this redefinition are limited.
*/
#ifndef MC_POPTALLOCA_H
#define MC_POPTALLOCA_H
/* AIX requires this to be the first thing in the file. */
#ifdef __GNUC__
# define alloca __builtin_alloca
#else
# ifdef _MSC_VER
# include <malloc.h>
# define alloca _alloca
# elif __TINYC__
# include <stddef.h>
# else
# if HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifdef _AIX
#pragma alloca
# else
# ifndef alloca /* predefined by HP cc +Olibcalls */
char *alloca ();
# endif
# endif
# endif
# endif
#endif
#ifndef HAVE_ALLOCA
# include <stdlib.h>
# if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H)
# include <malloc.h>
# endif
# define alloca malloc
#endif
#endif

View File

@ -1,155 +0,0 @@
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
/** \file poptconfig.c
* \brief Source: a module for configuring popt
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "poptalloca.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "popt.h"
#include "poptint.h"
static void configLine(poptContext con, char * line) {
int nameLength = strlen(con->appName);
char * opt;
struct poptAlias alias;
char * entryType;
char * longName = NULL;
char shortName = '\0';
if (strncmp(line, con->appName, nameLength)) return;
line += nameLength;
if (!*line || !isspace((unsigned char) *line)) return;
while (*line && isspace((unsigned char) *line)) line++;
entryType = line;
while (!*line || !isspace((unsigned char) *line)) line++;
*line++ = '\0';
while (*line && isspace((unsigned char) *line)) line++;
if (!*line) return;
opt = line;
while (!*line || !isspace((unsigned char) *line)) line++;
*line++ = '\0';
while (*line && isspace((unsigned char) *line)) line++;
if (!*line) return;
if (opt[0] == '-' && opt[1] == '-')
longName = opt + 2;
else if (opt[0] == '-' && !opt[2])
shortName = opt[1];
if (!strcmp(entryType, "alias")) {
if (poptParseArgvString(line, &alias.argc, &alias.argv)) return;
alias.longName = longName, alias.shortName = shortName;
poptAddAlias(con, alias, 0);
} else if (!strcmp(entryType, "exec")) {
con->execs = realloc(con->execs,
sizeof(*con->execs) * (con->numExecs + 1));
if (longName)
con->execs[con->numExecs].longName = strdup(longName);
else
con->execs[con->numExecs].longName = NULL;
con->execs[con->numExecs].shortName = shortName;
con->execs[con->numExecs].script = strdup(line);
con->numExecs++;
}
}
int poptReadConfigFile(poptContext con, const char * fn) {
char * file, * chptr, * end;
char * buf, * dst;
int fd, rc;
int fileLength;
fd = open(fn, O_RDONLY);
if (fd < 0) {
if (errno == ENOENT)
return 0;
else
return POPT_ERROR_ERRNO;
}
fileLength = lseek(fd, 0, SEEK_END);
lseek(fd, 0, 0);
file = alloca(fileLength + 1);
if (read(fd, file, fileLength) != fileLength) {
rc = errno;
close(fd);
errno = rc;
return POPT_ERROR_ERRNO;
}
close(fd);
dst = buf = alloca(fileLength + 1);
chptr = file;
end = (file + fileLength);
while (chptr < end) {
switch (*chptr) {
case '\n':
*dst = '\0';
dst = buf;
while (*dst && isspace((unsigned char) *dst)) dst++;
if (*dst && *dst != '#') {
configLine(con, dst);
}
chptr++;
break;
case '\\':
*dst++ = *chptr++;
if (chptr < end) {
if (*chptr == '\n')
dst--, chptr++;
/* \ at the end of a line does not insert a \n */
else
*dst++ = *chptr++;
}
break;
default:
*dst++ = *chptr++;
}
}
return 0;
}
int poptReadDefaultConfig(poptContext con, int useEnv) {
char *fn;
const char* home;
int rc;
(void) useEnv;
if (!con->appName) return 0;
rc = poptReadConfigFile(con, "/etc/popt");
if (rc) return rc;
if (getuid() != geteuid()) return 0;
if ((home = getenv("HOME"))) {
fn = alloca(strlen(home) + 20);
strcpy(fn, home);
strcat(fn, "/.popt");
rc = poptReadConfigFile(con, fn);
if (rc) return rc;
}
return 0;
}

View File

@ -1,364 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
/** \file popthelp.c
* \brief Source: popt helper module
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "global.h"
#include "popt.h"
#include "poptint.h"
static void displayArgs(poptContext con, enum poptCallbackReason foo,
struct poptOption * key,
const char * arg, void * data)
{
(void) foo;
(void) arg;
(void) data;
if (key->shortName== '?')
poptPrintHelp(con, stdout, 0);
else
poptPrintUsage(con, stdout, 0);
exit(0);
}
static const char *
getTableTranslationDomain(const struct poptOption *table)
{
const struct poptOption *opt;
for(opt = table;
opt->longName || opt->shortName || opt->arg.p;
opt++) {
if(opt->argInfo == POPT_ARG_INTL_DOMAIN)
return opt->arg.p;
}
return NULL;
}
static const char * getArgDescrip(const struct poptOption * opt,
const char *translation_domain) {
struct poptOption *poptHelpOptions;
(void) translation_domain;
poptHelpOptions = g_malloc(sizeof(struct poptOption)*4);
poptHelpOptions[0].longName = NULL;
poptHelpOptions[0].shortName = '\0';
poptHelpOptions[0].argInfo = POPT_ARG_CALLBACK;
poptHelpOptions[0].arg.f1 = &displayArgs;
poptHelpOptions[0].val = '\0';
poptHelpOptions[0].descrip = NULL;
poptHelpOptions[0].argDescrip = NULL;
poptHelpOptions[1].longName = "help";
poptHelpOptions[1].shortName = '?';
poptHelpOptions[1].argInfo = 0;
poptHelpOptions[1].arg.p = NULL;
poptHelpOptions[1].val = '?';
poptHelpOptions[1].descrip = _("Show this help message");
poptHelpOptions[1].argDescrip = NULL;
poptHelpOptions[2].longName = "usage";
poptHelpOptions[2].shortName = '\0';
poptHelpOptions[2].argInfo = 0;
poptHelpOptions[2].arg.p = NULL;
poptHelpOptions[2].val = 'u';
poptHelpOptions[2].descrip = _("Display brief usage message");
poptHelpOptions[2].argDescrip = NULL;
poptHelpOptions[3].longName = NULL;
poptHelpOptions[3].shortName = '\0';
poptHelpOptions[3].argInfo = 0;
poptHelpOptions[3].arg.p = NULL;
poptHelpOptions[3].val = 0;
poptHelpOptions[3].descrip = NULL;
poptHelpOptions[3].argDescrip = NULL;
if (!(opt->argInfo & POPT_ARG_MASK)){
g_free(poptHelpOptions);
return NULL;
}
if (opt == (poptHelpOptions + 1) || opt == (poptHelpOptions + 2))
if (opt->argDescrip)
{
g_free(poptHelpOptions);
return POPT_(opt->argDescrip);
}
if (opt->argDescrip)
{
g_free(poptHelpOptions);
return D_(translation_domain, opt->argDescrip);
}
g_free(poptHelpOptions);
return _("ARG");
}
static void singleOptionHelp(FILE * f, int maxLeftCol,
const struct poptOption * opt,
const char *translation_domain) {
int indentLength = maxLeftCol + 5;
int lineLength = 79 - indentLength;
const char * help = D_(translation_domain, opt->descrip);
int helpLength;
const char * ch;
char * left;
const char * argDescrip = getArgDescrip(opt, translation_domain);
left = malloc(maxLeftCol + 1);
*left = '\0';
if (opt->longName && opt->shortName)
sprintf(left, "-%c, --%s", opt->shortName, opt->longName);
else if (opt->shortName)
sprintf(left, "-%c", opt->shortName);
else if (opt->longName)
sprintf(left, "--%s", opt->longName);
if (!*left) return ;
if (argDescrip) {
strcat(left, "=");
strcat(left, argDescrip);
}
if (help)
fprintf(f," %-*s ", maxLeftCol, left);
else {
fprintf(f," %s\n", left);
goto out;
}
helpLength = strlen(help);
while (helpLength > lineLength) {
ch = help + lineLength - 1;
while (ch > help && !isspace((unsigned char) *ch)) ch--;
if (ch == help) break; /* give up */
while (ch > (help + 1) && isspace((unsigned char) *ch)) ch--;
ch++;
fprintf(f, "%.*s\n%*s", (int) (ch - help), help, indentLength, " ");
help = ch;
while (isspace((unsigned char) *help) && *help) help++;
helpLength = strlen(help);
}
if (helpLength) fprintf(f, "%s\n", help);
out:
free(left);
}
static int maxArgWidth(const struct poptOption * opt,
const char * translation_domain) {
int max = 0;
int this;
const char * s;
while (opt->longName || opt->shortName || opt->arg.p) {
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
this = maxArgWidth(opt->arg.p, translation_domain);
if (this > max) max = this;
} else if (!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) {
this = opt->shortName ? 2 : 0;
if (opt->longName) {
if (this) this += 2;
this += strlen(opt->longName) + 2;
}
s = getArgDescrip(opt, translation_domain);
if (s)
this += strlen(s) + 1;
if (this > max) max = this;
}
opt++;
}
return max;
}
static void singleTableHelp(FILE * f, const struct poptOption * table,
int left,
const char *translation_domain) {
const struct poptOption * opt;
const char *sub_transdom;
opt = table;
while (opt->longName || opt->shortName || opt->arg.p) {
if ((opt->longName || opt->shortName) &&
!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN))
singleOptionHelp(f, left, opt, translation_domain);
opt++;
}
opt = table;
while (opt->longName || opt->shortName || opt->arg.p) {
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
sub_transdom = getTableTranslationDomain(opt->arg.p);
if(!sub_transdom)
sub_transdom = translation_domain;
if (opt->descrip)
fprintf(f, "\n%s\n", D_(sub_transdom, opt->descrip));
singleTableHelp(f, opt->arg.p, left, sub_transdom);
}
opt++;
}
}
static int showHelpIntro(poptContext con, FILE * f) {
int len = 6;
const char * fn;
fprintf(f, _("Usage:"));
if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) {
fn = con->optionStack->argv[0];
if (strrchr(fn, '/')) fn = strrchr(fn, '/') + 1;
fprintf(f, " %s", fn);
len += strlen(fn) + 1;
}
return len;
}
int poptPrintHelp(poptContext con, FILE * f, int flags) {
int leftColWidth;
(void) flags;
showHelpIntro(con, f);
if (con->otherHelp)
fprintf(f, " %s\n", con->otherHelp);
else
fprintf(f, " %s\n", POPT_("[OPTION...]"));
leftColWidth = maxArgWidth(con->options, NULL);
singleTableHelp(f, con->options, leftColWidth, NULL);
return leftColWidth;
}
static int singleOptionUsage(FILE * f, int cursor,
const struct poptOption * opt,
const char *translation_domain) {
int len = 3;
char shortStr[2];
const char * item = shortStr;
const char * argDescrip = getArgDescrip(opt, translation_domain);
if (opt->shortName) {
if (!(opt->argInfo & POPT_ARG_MASK))
return cursor; /* we did these already */
len++;
*shortStr = opt->shortName;
shortStr[1] = '\0';
} else if (opt->longName) {
len += 1 + strlen(opt->longName);
item = opt->longName;
}
if (len == 3) return cursor;
if (argDescrip)
len += strlen(argDescrip) + 1;
if ((cursor + len) > 79) {
fprintf(f, "\n ");
cursor = 7;
}
fprintf(f, " [-%s%s%s%s]", opt->shortName ? "" : "-", item,
argDescrip ? (opt->shortName ? " " : "=") : "",
argDescrip ? argDescrip : "");
return cursor + len + 1;
}
static int singleTableUsage(FILE * f, int cursor, const struct poptOption * table,
const char *translation_domain) {
const struct poptOption * opt;
opt = table;
while (opt->longName || opt->shortName || opt->arg.p) {
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN)
translation_domain = (const char *)opt->arg.p;
else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE)
cursor = singleTableUsage(f, cursor, opt->arg.p,
translation_domain);
else if ((opt->longName || opt->shortName) &&
!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN))
cursor = singleOptionUsage(f, cursor, opt, translation_domain);
opt++;
}
return cursor;
}
static int showShortOptions(const struct poptOption * opt, FILE * f,
char * str) {
char s[300]; /* this is larger then the ascii set, so
it should do just fine */
if (!str) {
str = s;
memset(str, 0, sizeof(s));
}
while (opt->longName || opt->shortName || opt->arg.p) {
if (opt->shortName && !(opt->argInfo & POPT_ARG_MASK))
str[strlen(str)] = opt->shortName;
else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE)
showShortOptions(opt->arg.p, f, str);
opt++;
}
if (s != str || !*s)
return 0;
fprintf(f, " [-%s]", s);
return strlen(s) + 4;
}
void poptPrintUsage(poptContext con, FILE * f, int flags) {
int cursor;
(void) flags;
cursor = showHelpIntro(con, f);
cursor += showShortOptions(con->options, f, NULL);
singleTableUsage(f, cursor, con->options, NULL);
if (con->otherHelp) {
cursor += strlen(con->otherHelp) + 1;
if (cursor > 79) fprintf(f, "\n ");
fprintf(f, " %s", con->otherHelp);
}
fprintf(f, "\n");
}
void poptSetOtherOptionHelp(poptContext con, const char * text) {
if (con->otherHelp) free(con->otherHelp);
con->otherHelp = strdup(text);
}

View File

@ -1,53 +0,0 @@
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
/** \file poptint.h
* \brief Header: a module (internal?) for popt
*/
#ifndef MC_POPTINT_H
#define MC_POPTINT_H
struct optionStackEntry {
int argc;
char ** argv;
int next;
char * nextArg;
char * nextCharArg;
struct poptAlias * currAlias;
int stuffed;
};
struct execEntry {
char * longName;
char shortName;
char * script;
};
struct poptContext_s {
struct optionStackEntry optionStack[POPT_OPTION_DEPTH], * os;
char ** leftovers;
int numLeftovers;
int nextLeftover;
const struct poptOption * options;
int restLeftover;
char * appName;
struct poptAlias * aliases;
int numAliases;
int flags;
struct execEntry * execs;
int numExecs;
char ** finalArgv;
int finalArgvCount;
int finalArgvAlloced;
struct execEntry * doExec;
char * execPath;
int execAbsolute;
char * otherHelp;
};
#define D_(dom, str) _(str)
#define POPT_(foo) _(foo)
#endif

View File

@ -1,101 +0,0 @@
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
/** \file poptparse.c
* \brief Source: popt parser
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "poptalloca.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "popt.h"
#define POPT_ARGV_ARRAY_GROW_DELTA 5
int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) {
char * buf, * bufStart, * dst;
const char * src;
char quote = '\0';
int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA;
char ** argv = malloc(sizeof(*argv) * argvAlloced);
char ** argv2;
int argc = 0;
int i, buflen;
buflen = strlen(s) + 1;
bufStart = buf = alloca(buflen);
memset(buf, '\0', buflen);
src = s;
argv[argc] = buf;
while (*src) {
if (quote == *src) {
quote = '\0';
} else if (quote) {
if (*src == '\\') {
src++;
if (!*src) {
free(argv);
return POPT_ERROR_BADQUOTE;
}
if (*src != quote) *buf++ = '\\';
}
*buf++ = *src;
} else if (isspace((unsigned char) *src)) {
if (*argv[argc]) {
buf++, argc++;
if (argc == argvAlloced) {
argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA;
argv = realloc(argv, sizeof(*argv) * argvAlloced);
}
argv[argc] = buf;
}
} else switch (*src) {
case '"':
case '\'':
quote = *src;
break;
case '\\':
src++;
if (!*src) {
free(argv);
return POPT_ERROR_BADQUOTE;
}
/* fallthrough */
default:
*buf++ = *src;
}
src++;
}
if (strlen(argv[argc])) {
argc++, buf++;
}
dst = malloc(argc * sizeof(*argv) + (buf - bufStart));
argv2 = (void *) dst;
dst += argc * sizeof(*argv);
memcpy(argv2, argv, argc * sizeof(*argv));
memcpy(dst, bufStart, buf - bufStart);
for (i = 0; i < argc; i++) {
argv2[i] = dst + (argv[i] - bufStart);
}
free(argv);
*argvPtr = argv2;
*argcPtr = argc;
return 0;
}

View File

@ -113,13 +113,11 @@ static const char *const features[] = {
};
void
show_version (int verbose)
show_version (void)
{
int i;
printf (_("GNU Midnight Commander %s\n"), VERSION);
if (!verbose)
return;
#ifdef USE_VFS
printf (_("Virtual File System:"));

View File

@ -6,6 +6,6 @@
#ifndef MC_TEXTCONF_H
#define MC_TEXTCONF_H
extern void show_version (int verbose);
extern void show_version (void);
#endif

View File

@ -38,7 +38,7 @@
#include "../../src/setup.h" /* setup_color_string, term_color_string */
extern char *command_line_colors;
char *command_line_colors = NULL;
/* Set if we are actually using colors */
gboolean use_colors = FALSE;

View File

@ -20,6 +20,6 @@ libmcviewer_la_SOURCES = \
search.c
libmcviewer_la_CFLAGS=-I../ -I$(top_srcdir)/src \
$(GLIB_CFLAGS) \
$(GLIB_CFLAGS) $(PCRE_CFLAGS) \
-DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\"