📄 main.c
字号:
if (boot_current_is_left){
first = 1;
second = 0;
} else {
first = 0;
second = 1;
}
add_widget (midnight_dlg, get_panel_widget (first));
add_widget (midnight_dlg, get_panel_widget (second));
add_widget (midnight_dlg, the_menubar);
init_labels (get_panel_widget (0));
init_labels (get_panel_widget (1));
/* Run the Midnight Commander if no file was specified in the command line */
run_dlg (midnight_dlg);
}
/* result must be free'd (I think this should go in util.c) */
char *
prepend_cwd_on_local (char *filename)
{
char *d;
int l;
if (vfs_file_is_local (filename)){
if (*filename == PATH_SEP) /* an absolute pathname */
return strdup (filename);
d = malloc (MC_MAXPATHLEN + strlen (filename) + 2);
mc_get_current_wd (d, MC_MAXPATHLEN);
l = strlen(d);
d[l++] = PATH_SEP;
strcpy (d + l, filename);
return canonicalize_pathname (d);
} else
return strdup (filename);
}
#ifdef USE_INTERNAL_EDIT
void edit (const char *file_name, int startline);
int
mc_maybe_editor_or_viewer (void)
{
char *path;
if (!(view_one_file || edit_one_file))
return 0;
/* Invoke the internal view/edit routine with:
* the default processing and forcing the internal viewer/editor
*/
if (view_one_file) {
path = prepend_cwd_on_local (view_one_file);
setup_dummy_mc (path);
view_file (path, 0, 1);
}
#ifdef USE_INTERNAL_EDIT
else {
path = prepend_cwd_on_local ("");
setup_dummy_mc (path);
edit (edit_one_file, 1);
}
#endif
free (path);
midnight_shutdown = 1;
done_mc ();
return 1;
}
#endif
static void
do_nc (void)
{
midnight_dlg = create_dlg (0, 0, LINES, COLS, midnight_colors, midnight_callback, "[main]", "midnight", 0);
midnight_dlg->has_menubar = 1;
#ifdef USE_INTERNAL_EDIT
/* Check if we were invoked as an editor or file viewer */
if (mc_maybe_editor_or_viewer ())
return;
#endif
setup_mc ();
#ifndef HAVE_GNOME
setup_panels_and_run_mc ();
#endif
/* Program end */
midnight_shutdown = 1;
/* destroy_dlg destroys even cpanel->cwd, so we have to save a copy :) */
if (print_last_wd) {
if (!vfs_current_is_local ())
last_wd_string = strdup (".");
else
last_wd_string = strdup (cpanel->cwd);
}
done_mc ();
#ifndef HAVE_GNOME
destroy_dlg (midnight_dlg);
current_panel = 0;
#endif
done_mc_profile ();
}
#include "features.inc"
static void
version (int verbose)
{
fprintf (stderr, "The Midnight Commander %s\n", VERSION);
if (!verbose)
return;
#ifndef HAVE_X
fprintf (stderr,
_("with mouse support on xterm%s.\n"),
status_mouse_support ? _(" and the Linux console") : "");
#endif /* HAVE_X */
fprintf (stderr, features);
if (print_last_wd)
write (stdout_fd, ".", 1);
}
#if defined (_OS_NT)
/* Windows NT code */
#define CONTROL_FILE "\\mc.%d.control"
char control_file [sizeof (CONTROL_FILE) + 8];
void
OS_Setup ()
{
SetConsoleTitle ("GNU Midnight Commander");
shell = getenv ("COMSPEC");
if (!shell || !*shell)
shell = get_default_shell ();
/* Default opening mode for files is binary, not text (CR/LF translation) */
#ifndef __EMX__
_fmode = O_BINARY;
#endif
mc_home = get_mc_lib_dir ();
}
static void
sigchld_handler_no_subshell (int sig)
{
}
void
init_sigchld (void)
{
}
void
init_sigfatals (void)
{
/* Nothing to be done on the OS/2, Windows/NT */
}
#elif defined (__os2__)
/* OS/2 Version */
# define CONTROL_FILE "\\mc.%d.control"
char control_file [sizeof (CONTROL_FILE) + 8];
void
OS_Setup (void)
{
/* .ado: This does not work: */
/* DosSMSetTitle ((PSZ) "This is my app"); */
/* In DEF: IMPORTS
DosSMSetTitle = SESMGR.DOSSMSETTITLE */
shell = getenv ("COMSPEC");
if (!shell || !*shell)
shell = get_default_shell ();
mc_home = get_mc_lib_dir ();
}
static void
sigchld_handler_no_subshell (int sig)
{
}
void
init_sigchld (void)
{
}
void
init_sigfatals (void)
{
/* Nothing to be done on the OS/2, Windows/NT */
}
#else
/* Unix version */
#define CONTROL_FILE "/tmp/mc.%d.control"
char control_file [sizeof (CONTROL_FILE) + 8];
void
OS_Setup ()
{
char *termvalue;
char *mc_libdir;
termvalue = getenv ("TERM");
if (!termvalue){
fprintf (stderr, _("The TERM environment variable is unset!\n"));
termvalue = "";
}
#ifndef HAVE_X
if (force_xterm || (strncmp (termvalue, "xterm", 5) == 0 || strcmp (termvalue, "dtterm") == 0)){
use_mouse_p = XTERM_MOUSE;
xterm_flag = 1;
# ifdef SET_TITLE
printf ("\33]0;GNU Midnight Commander\7");
# endif
}
#endif /* ! HAVE_X */
shell = getenv ("SHELL");
if (!shell || !*shell)
shell = strdup (getpwuid (geteuid ())->pw_shell);
if (!shell || !*shell)
shell = "/bin/sh";
sprintf (control_file, CONTROL_FILE, getpid ());
my_putenv ("MC_CONTROL_FILE", control_file);
/* This is the directory, where MC was installed, on Unix this is LIBDIR */
/* and can be overriden by the MCHOME environment variable */
if ((mc_libdir = getenv ("MCHOME")) != NULL) {
mc_home = strdup (mc_libdir);
} else {
mc_home = strdup (LIBDIR);
}
}
static void
sigchld_handler_no_subshell (int sig)
{
#ifndef HAVE_X
int pid, status;
if (!console_flag)
return;
/* COMMENT: if it were true that after the call to handle_console(..INIT)
the value of console_flag never changed, we could simply not install
this handler at all if (!console_flag && !use_subshell). */
/* That comment is no longer true. We need to wait() on a sigchld
handler (that's at least what the tarfs code expects currently). */
#ifndef SCO_FLAVOR
pid = waitpid (cons_saver_pid, &status, WUNTRACED | WNOHANG);
if (pid == cons_saver_pid){
/* {{{ Someone has stopped or killed cons.saver; restart it */
if (WIFSTOPPED (status))
kill (pid, SIGCONT);
else
{
handle_console (CONSOLE_DONE);
handle_console (CONSOLE_INIT);
}
/* }}} */
}
#endif /* ! SCO_FLAVOR */
/* If we get here, some other child exited; ignore it */
#endif /* ! HAVE_X */
}
#if 0
void
mc_fatal_signal (int signum)
{
volatile int x;
char cmd;
pid_t pid;
char *args [4] = { "gdb", NULL, NULL, NULL };
char pid [20];
sprintf (buf, "%d", getpid ());
fprintf (stderr,
"Midnight Commander fatal error, PID=%d\n"
"What to do: [e]xit, [s]tack trace, [a]ttach to process\n", getpid ());
read (1, &cmd, 1);
if (cmd == 'a'){
for (x = 1; x;)
;
}
if (cmd == 's'){
args [1] = program_name;
args [2] = buf;
pid = fork ();
if (pid == -1){
fprintf (stderr, "Could not fork, exiting\n");
exit (0);
}
if (pid == 0){
stack_trace (args);
} else {
while (1)
;
}
}
exit (0);
}
void
init_sigfatals (void)
{
struct sigaction sa;
sa.sa_hanlder = mc_fatal_signal;
sa.sa_mask = 0;
sa.sa_flags = 0;
sigaction (SIGSEGV, &sa, NULL);
sigaction (SIGBUS, &sa, NULL);
sigaction (SIGFPE, &sa, NULL);
}
#else
#define init_sigfatals()
#endif
void
init_sigchld (void)
{
struct sigaction sigchld_action;
sigchld_action.sa_handler =
#ifdef HAVE_SUBSHELL_SUPPORT
use_subshell ? sigchld_handler :
#endif
sigchld_handler_no_subshell;
sigemptyset (&sigchld_action.sa_mask);
#ifdef SA_RESTART
sigchld_action.sa_flags = SA_RESTART;
#else
sigchld_action.sa_flags = 0;
#endif
sigaction (SIGCHLD, &sigchld_action, NULL);
}
#endif /* _OS_NT, __os2__, UNIX */
#if defined(HAVE_SLANG) && !defined(OS2_NT)
extern int SLtt_Try_Termcap;
#endif
#ifndef PORT_WANTS_ARGP
static void
print_mc_usage (void)
{
version (0);
fprintf (stderr,
"Usage is:\n\n"
"mc [flags] [this_dir] [other_panel_dir]\n\n"
#if defined(HAVE_SLANG) && !defined(OS2_NT)
"-a, --stickchars Force use of +, -, | for line drawing.\n"
#endif
"-b, --nocolor Force black and white display.\n"
#ifdef WITH_BACKGROUND
"-B, --background [DEVEL-ONLY: Debug the background code]\n"
#endif
"-c, --color Force color mode.\n"
"-C, --colors Specify colors (use --help-colors to get a list).\n"
#ifdef USE_INTERNAL_EDIT
"-e, --edit Startup the internal editor.\n"
#endif
"-d, --nomouse Disable mouse support.\n"
"-f, --libdir Print configured paths.\n"
"-h, --help Shows this help message.\n"
"-k, --resetsoft Reset softkeys (HP terminals only) to their terminfo/termcap\n"
" default.\n"
"-P, --printwd At exit, print the last working directory.\n"
"-s, --slow Disables verbose operation (for slow terminals).\n"
#if defined(HAVE_SLANG) && !defined(OS2_NT)
"-t, --termcap Activate support for the TERMCAP variable.\n"
#endif
#ifdef USE_NETCODE
"-l, --ftplog file Log ftpfs commands to the file.\n"
#endif
#if defined(HAVE_SLANG) && defined(OS2_NT)
"-S, --createcmdile Create command file to set default directory upon exit.\n"
#endif
#ifdef HAVE_SUBSHELL_SUPPORT
"-u, --nosubshell Disable the concurrent subshell mode.\n"
"-U, --subshell Force the concurrent subshell mode.\n"
"-r, --forceexec Force subshell execution.\n"
#endif
"-v, --view fname Start up into the viewer mode.\n"
"-V, --version Report version and configuration options.\n"
"-x, --xterm Force xterm mouse support and screen save/restore.\n"
#ifdef HAVE_SUBSHELL_SUPPORT
"-X, --dbgsubshell [DEVEL-ONLY: Debug the subshell].\n"
#endif
);
}
#endif /* PORT_WANTS_ARGP */
static void
print_color_usage (void)
{
fprintf (stderr,
"--colors KEYWORD={FORE},{BACK}\n\n"
"{FORE} and {BACK} can be ommited, and the default will be used\n"
"\n"
"Keywords:\n"
" Global: errors, reverse, gauge, input\n"
" File display: normal, selected, marked, markselect\n"
" Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus\n"
" Menus: menu, menuhot, menusel, menuhotsel\n"
" Help: helpnormal, helpitalic, helplink, helpslink\n"
" File types: directory, execute, link, 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");
}
static void
probably_finish_program (void)
{
if (finish_program){
if (print_last_wd)
printf (".");
exit (1);
}
}
enum {
GEOMETRY_KEY = -1,
NOWIN_KEY = -2
};
static void
process_args (int c, char *option_arg)
{
switch (c) {
case 'V':
version (1);
finish_program = 1;
break;
case 'c':
disable_colors = 0;
#ifdef HAVE_SLANG
force_colors = 1;
#endif
break;
case 'f':
fprintf (stderr, _("Library directory for the Midnight Commander: %s\n"), mc_home);
finish_program = 1;
break;
case 'm':
fprintf (stderr, _("Option -m is obsolete. Please look at Display Bits... in the Option's menu\n"));
finish_program = 1;
break;
#ifdef USE_NETCODE
case 'l':
ftpfs_set_debug (option_arg);
break;
#endif
#ifdef OS2_NT
case 'S':
print_last_wd = 2;
batch_file_name = option_arg;
break;
#endif
case 'd':
use_mouse_p = NO_MOUSE;
break;
case 'X':
#ifdef HAVE_SUBSHELL_SUPPORT
debug_subshell = 1;
#endif
break;
case 'U':
#ifdef HAVE_SUBSHELL_SUPPORT
use_subshell = 1;
#endif
break;
case 'u':
#ifdef HAVE_SUBSHELL_SUPPORT
use_subshell = 0;
#endif
break;
case 'r':
#ifdef HAVE_SUBSHELL_SUPPORT
force_subshell_execution = 1;
#endif
break;
case 'H':
print_color_usage ();
finish_program = 1;
break;
case 'h':
#ifn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -