1 /* Main program for the Midnight Commander
2 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
5 Written by: 1994, 1995, 1996, 1997 Miguel de Icaza
6 1994, 1995 Janne Kukonlehto
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
24 * \brief Source: this is a main module
36 #include <sys/types.h>
40 #include <pwd.h> /* for username in xterm title */
42 #include "lib/global.h"
44 #include "lib/tty/tty.h"
45 #include "lib/tty/mouse.h"
46 #include "lib/tty/key.h" /* For init_key() */
47 #include "lib/tty/win.h" /* xterm_flag */
49 #include "lib/mcconfig.h"
50 #include "lib/filehighlight.h"
51 #include "lib/fileloc.h" /* MC_USERCONF_DIR */
52 #include "lib/strutil.h"
54 #include "lib/vfs/mc-vfs/vfs.h" /* vfs_translate_url() */
56 #include "lib/vfs/mc-vfs/smbfs.h" /* smbfs_set_debug() */
57 #endif /* ENABLE_VFS_SMB */
60 #include "lib/widget.h"
67 #include "treestore.h"
68 #include "consaver/cons.saver.h"
70 #include "setup.h" /* save_setup() */
71 #include "boxes.h" /* sort_box() */
73 #include "cmd.h" /* Normal commands */
76 #include "learn.h" /* learn_keys() */
79 #include "ext.h" /* For flush_extension_file() */
81 #include "cmddef.h" /* CK_ cmd name const */
82 #include "user.h" /* user_file_menu_cmd() */
90 #ifdef USE_INTERNAL_EDIT
91 #include "src/editor/edit.h"
95 #include "src/diffviewer/ydiff.h"
99 #include "lib/charsets.h"
100 #include "selcodepage.h"
101 #endif /* HAVE_CHARSET */
103 #include "keybind.h" /* type global_keymap_t */
105 /*** global variables ****************************************************************************/
107 /* When the modes are active, left_panel, right_panel and tree_panel */
108 /* Point to a proper data structure. You should check with the functions */
109 /* get_current_type and get_other_type the types of the panels before using */
110 /* This pointer variables */
112 /* The structures for the panels */
113 WPanel
*left_panel
= NULL
;
114 WPanel
*right_panel
= NULL
;
116 mc_fhl_t
*mc_filehighlight
;
118 /* The pointer to the tree */
119 WTree
*the_tree
= NULL
;
122 struct WMenuBar
*the_menubar
= NULL
;
123 static Menu
*left_menu
, *right_menu
;
125 /* Pointers to the selected and unselected panel */
126 WPanel
*current_panel
= NULL
;
128 /* Set if the command is being run from the "Right" menu */
131 /* Set when main loop should be terminated */
132 volatile int quit
= 0;
134 /* Set if you want the possible completions dialog for the first time */
135 int show_all_if_ambiguous
= 0;
137 /* Set when cd symlink following is desirable (bash mode) */
140 /* If set then dialogs just clean the screen when refreshing, else */
141 /* they do a complete refresh, refreshing all the parts of the program */
142 int fast_refresh
= 0;
144 /* If true, at startup the user-menu is invoked */
147 /* If true, then the +, - and \ keys have their special meaning only if the
148 * command line is emtpy, otherwise they behave like regular letters
150 int only_leading_plus_minus
= 1;
152 int pause_after_run
= pause_on_dumb_terminals
;
154 /* It true saves the setup when quitting */
155 int auto_save_setup
= 1;
158 /* If true, allow characters in the range 160-255 */
159 int eight_bit_clean
= 1;
161 * If true, also allow characters in the range 128-159.
162 * This is reported to break on many terminals (xterm, qansi-m).
164 int full_eight_bits
= 0;
165 #endif /* !HAVE_CHARSET */
168 * If utf-8 terminal utf8_display = 1
169 * Display bits set UTF-8
172 int utf8_display
= 0;
174 /* If true use the internal viewer */
175 int use_internal_view
= 1;
178 const char *mc_prompt
= NULL
;
180 /* The widget where we draw the prompt */
189 /* Mouse type: GPM, xterm or none */
190 Mouse_Type use_mouse_p
= MOUSE_NONE
;
192 /* If on, default for "No" in delete operations */
195 /* Controls screen clearing before an exec */
196 int clear_before_exec
= 1;
198 /* Asks for confirmation before deleting a file */
199 int confirm_delete
= 1;
201 /* Asks for confirmation before deleting a hotlist entry */
202 int confirm_directory_hotlist_delete
= 1;
204 /* Asks for confirmation before overwriting a file */
205 int confirm_overwrite
= 1;
207 /* Asks for confirmation before executing a program by pressing enter */
208 int confirm_execute
= 0;
210 /* Asks for confirmation before leaving the program */
211 int confirm_exit
= 1;
213 /* Asks for confirmation before clean up of history */
214 int confirm_history_cleanup
= 1;
216 /* Asks for confirmation when using F3 to view a directory and there
218 int confirm_view_dir
= 0;
220 /* This flag indicates if the pull down menus by default drop down */
223 /* The dialog handle for the main program */
224 Dlg_head
*midnight_dlg
= NULL
;
226 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
227 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
228 int update_prompt
= 0;
230 /* The home directory */
231 const char *home_dir
= NULL
;
233 /* Only used at program boot */
234 int boot_current_is_left
= 1;
236 /* If this is true, then when browsing the tree the other window will
237 * automatically reload it's directory with the contents of the currently
238 * selected directory.
242 /* path to X clipboard utility */
243 char *clipboard_store_path
= NULL
;
244 char *clipboard_paste_path
= NULL
;
246 mc_run_mode_t mc_run_mode
= MC_RUN_FULL
;
247 char *mc_run_param0
= NULL
;
248 char *mc_run_param1
= NULL
;
250 /* Used so that widgets know if they are being destroyed or
252 int midnight_shutdown
= 0;
254 /* The user's shell */
257 /* mc_home: The home of MC - /etc/mc or defined by MC_DATADIR */
258 char *mc_home
= NULL
;
260 /* mc_home_alt: Alternative home of MC - deprecated /usr/share/mc */
261 char *mc_home_alt
= NULL
;
263 /*** file scope macro definitions ****************************************************************/
267 * Don't restrict the output on the screen manager level,
268 * the translation tables take care of it.
270 #define full_eight_bits (1)
271 #define eight_bit_clean (1)
272 #endif /* !HAVE_CHARSET */
274 /*** file scope type declarations ****************************************************************/
276 /*** file scope variables ************************************************************************/
278 /* If set, then print to the given file the last directory we were at */
279 static char *last_wd_string
= NULL
;
280 /* Set to 1 to suppress printing the last directory */
281 static int print_last_revert
= 0;
283 static gboolean ctl_x_map_enabled
= FALSE
;
285 /*** file scope functions ************************************************************************/
286 /* --------------------------------------------------------------------------------------------- */
288 /** Stop MC main dialog and the current dialog if it exists.
289 * Needed to provide fast exit from MC viewer or editor on shell exit */
294 midnight_dlg
->state
= DLG_CLOSED
;
296 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
297 ((Dlg_head
*) top_dlg
->data
)->state
= DLG_CLOSED
;
300 /* --------------------------------------------------------------------------------------------- */
303 quit_cmd_internal (int quiet
)
306 size_t n
= dialog_switch_num () - 1;
310 char msg
[BUF_MEDIUM
];
312 g_snprintf (msg
, sizeof (msg
),
313 ngettext ("You have %zd opened screen. Quit anyway?",
314 "You have %zd opened screens. Quit anyway?", n
), n
);
316 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
320 else if (quiet
|| !confirm_exit
)
322 else if (query_dialog (_("The Midnight Commander"),
323 _("Do you really want to quit the Midnight Commander?"),
324 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
329 #ifdef HAVE_SUBSHELL_SUPPORT
332 else if ((q
= exit_subshell ()))
342 /* --------------------------------------------------------------------------------------------- */
347 return quit_cmd_internal (0);
350 /* --------------------------------------------------------------------------------------------- */
357 sel_dir
= tree_box (selection (current_panel
)->fname
);
360 do_cd (sel_dir
, cd_exact
);
365 /* --------------------------------------------------------------------------------------------- */
367 #ifdef LISTMODE_EDITOR
373 if (get_current_type () != view_listing
)
376 newmode
= listmode_edit (current_panel
->user_format
);
380 g_free (current_panel
->user_format
);
381 current_panel
->list_type
= list_user
;
382 current_panel
->user_format
= newmode
;
383 set_panel_formats (current_panel
);
387 #endif /* LISTMODE_EDITOR */
389 /* --------------------------------------------------------------------------------------------- */
390 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
393 create_panel_menu (void)
395 GList
*entries
= NULL
;
397 entries
= g_list_append (entries
, menu_entry_create (_("File listin&g"), CK_ListingCmd
));
398 entries
= g_list_append (entries
, menu_entry_create (_("&Quick view"), CK_QuickViewCmd
));
399 entries
= g_list_append (entries
, menu_entry_create (_("&Info"), CK_InfoCmd
));
400 entries
= g_list_append (entries
, menu_entry_create (_("&Tree"), CK_TreeCmd
));
401 entries
= g_list_append (entries
, menu_separator_create ());
403 g_list_append (entries
, menu_entry_create (_("&Listing mode..."), CK_ChangeListingCmd
));
404 entries
= g_list_append (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
405 entries
= g_list_append (entries
, menu_entry_create (_("&Filter..."), CK_FilterCmd
));
408 g_list_append (entries
, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding
));
410 #ifdef ENABLE_VFS_NET
411 entries
= g_list_append (entries
, menu_separator_create ());
412 #ifdef ENABLE_VFS_FTP
413 entries
= g_list_append (entries
, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd
));
415 #ifdef ENABLE_VFS_FISH
416 entries
= g_list_append (entries
, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd
));
418 #ifdef ENABLE_VFS_SMB
419 entries
= g_list_append (entries
, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd
));
421 #endif /* ENABLE_VFS_NET */
422 entries
= g_list_append (entries
, menu_separator_create ());
423 entries
= g_list_append (entries
, menu_entry_create (_("&Rescan"), CK_RereadCmd
));
428 /* --------------------------------------------------------------------------------------------- */
431 create_file_menu (void)
433 GList
*entries
= NULL
;
435 entries
= g_list_append (entries
, menu_entry_create (_("&View"), CK_ViewCmd
));
436 entries
= g_list_append (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd
));
437 entries
= g_list_append (entries
, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd
));
438 entries
= g_list_append (entries
, menu_entry_create (_("&Edit"), CK_EditCmd
));
439 entries
= g_list_append (entries
, menu_entry_create (_("&Copy"), CK_CopyCmd
));
440 entries
= g_list_append (entries
, menu_entry_create (_("C&hmod"), CK_ChmodCmd
));
441 entries
= g_list_append (entries
, menu_entry_create (_("&Link"), CK_LinkCmd
));
442 entries
= g_list_append (entries
, menu_entry_create (_("&Symlink"), CK_SymlinkCmd
));
444 g_list_append (entries
, menu_entry_create (_("Relative symlin&k"), CK_RelativeSymlinkCmd
));
445 entries
= g_list_append (entries
, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd
));
446 entries
= g_list_append (entries
, menu_entry_create (_("Ch&own"), CK_ChownCmd
));
448 g_list_append (entries
, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd
));
449 entries
= g_list_append (entries
, menu_entry_create (_("&Rename/Move"), CK_RenameCmd
));
450 entries
= g_list_append (entries
, menu_entry_create (_("&Mkdir"), CK_MkdirCmd
));
451 entries
= g_list_append (entries
, menu_entry_create (_("&Delete"), CK_DeleteCmd
));
452 entries
= g_list_append (entries
, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd
));
453 entries
= g_list_append (entries
, menu_separator_create ());
454 entries
= g_list_append (entries
, menu_entry_create (_("Select &group"), CK_SelectCmd
));
455 entries
= g_list_append (entries
, menu_entry_create (_("U&nselect group"), CK_UnselectCmd
));
457 g_list_append (entries
,
458 menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd
));
459 entries
= g_list_append (entries
, menu_separator_create ());
460 entries
= g_list_append (entries
, menu_entry_create (_("E&xit"), CK_QuitCmd
));
465 /* --------------------------------------------------------------------------------------------- */
468 create_command_menu (void)
470 /* I know, I'm lazy, but the tree widget when it's not running
471 * as a panel still has some problems, I have not yet finished
472 * the WTree widget port, sorry.
474 GList
*entries
= NULL
;
476 entries
= g_list_append (entries
, menu_entry_create (_("&User menu"), CK_UserMenuCmd
));
477 entries
= g_list_append (entries
, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd
));
478 entries
= g_list_append (entries
, menu_entry_create (_("&Find file"), CK_FindCmd
));
479 entries
= g_list_append (entries
, menu_entry_create (_("S&wap panels"), CK_SwapCmd
));
481 g_list_append (entries
, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine
));
483 g_list_append (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd
));
485 entries
= g_list_append (entries
, menu_entry_create (_("&View diff files"), CK_DiffViewCmd
));
488 g_list_append (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
490 g_list_append (entries
,
491 menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd
));
492 entries
= g_list_append (entries
, menu_separator_create ());
493 entries
= g_list_append (entries
, menu_entry_create (_("Command &history"), CK_HistoryCmd
));
495 g_list_append (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd
));
497 entries
= g_list_append (entries
, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs
));
499 #ifdef WITH_BACKGROUND
500 entries
= g_list_append (entries
, menu_entry_create (_("&Background jobs"), CK_JobsCmd
));
502 entries
= g_list_append (entries
, menu_entry_create (_("Screen lis&t"), CK_DialogListCmd
));
503 entries
= g_list_append (entries
, menu_separator_create ());
504 #ifdef ENABLE_VFS_UNDELFS
506 g_list_append (entries
,
507 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_UndeleteCmd
));
509 #ifdef LISTMODE_EDITOR
511 g_list_append (entries
, menu_entry_create (_("&Listing format edit"), CK_ListmodeCmd
));
513 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
514 entries
= g_list_append (entries
, menu_separator_create ());
517 g_list_append (entries
, menu_entry_create (_("Edit &extension file"), CK_EditExtFileCmd
));
518 entries
= g_list_append (entries
, menu_entry_create (_("Edit &menu file"), CK_EditMcMenuCmd
));
520 g_list_append (entries
,
521 menu_entry_create (_("Edit hi&ghlighting group file"), CK_EditFhlFileCmd
));
526 /* --------------------------------------------------------------------------------------------- */
529 create_options_menu (void)
531 GList
*entries
= NULL
;
533 entries
= g_list_append (entries
, menu_entry_create (_("&Configuration..."), CK_ConfigureBox
));
534 entries
= g_list_append (entries
, menu_entry_create (_("&Layout..."), CK_LayoutBox
));
536 g_list_append (entries
, menu_entry_create (_("&Panel options..."), CK_PanelOptionsBox
));
537 entries
= g_list_append (entries
, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox
));
538 entries
= g_list_append (entries
, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox
));
539 entries
= g_list_append (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
541 entries
= g_list_append (entries
, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs
));
543 entries
= g_list_append (entries
, menu_separator_create ());
544 entries
= g_list_append (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd
));
549 /* --------------------------------------------------------------------------------------------- */
554 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
555 menubar_add_menu (the_menubar
, left_menu
);
556 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
557 menubar_add_menu (the_menubar
,
558 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
559 menubar_add_menu (the_menubar
,
560 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
561 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
562 menubar_add_menu (the_menubar
, right_menu
);
564 menubar_set_visible (the_menubar
, menubar_visible
);
567 /* --------------------------------------------------------------------------------------------- */
570 menu_last_selected_cmd (void)
572 the_menubar
->is_active
= TRUE
;
573 the_menubar
->is_dropped
= (drop_menus
!= 0);
574 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
575 dlg_select_widget (the_menubar
);
578 /* --------------------------------------------------------------------------------------------- */
583 if (the_menubar
->is_active
)
586 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
587 the_menubar
->selected
= 0;
589 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
590 menu_last_selected_cmd ();
593 /* --------------------------------------------------------------------------------------------- */
596 midnight_get_shortcut (unsigned long command
)
599 const char *shortcut
= NULL
;
601 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
602 if (shortcut
!= NULL
)
603 return g_strdup (shortcut
);
605 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
606 if (shortcut
!= NULL
)
607 return g_strdup (shortcut
);
609 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_StartExtMap1
);
611 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
612 if (shortcut
!= NULL
)
613 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
618 /* --------------------------------------------------------------------------------------------- */
621 midnight_get_title (const Dlg_head
* h
, size_t len
)
623 /* TODO: share code with update_xterm_title_path() */
628 struct passwd
*pw
= NULL
;
634 path
= strip_home_and_password (current_panel
->cwd
);
635 res
= gethostname (host
, sizeof (host
));
639 host
[sizeof (host
) - 1] = '\0';
641 pw
= getpwuid (getuid ());
643 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
645 login
= g_strdup (host
);
647 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
648 path
= str_trunc (p
, len
- 4);
652 return g_strdup (path
);
655 /* --------------------------------------------------------------------------------------------- */
658 toggle_panels_split (void)
660 horizontal_split
= !horizontal_split
;
665 /* --------------------------------------------------------------------------------------------- */
667 * Just a hack for allowing url-like pathnames to be accepted from the
672 translated_mc_chdir (char *dir
)
677 newdir
= vfs_translate_url (dir
);
678 ret
= mc_chdir (newdir
);
682 /* --------------------------------------------------------------------------------------------- */
689 panel_view_mode_t current_mode
, other_mode
;
690 char original_dir
[BUF_1K
] = "\0";
692 if (boot_current_is_left
)
696 current_mode
= startup_left_mode
;
697 other_mode
= startup_right_mode
;
703 current_mode
= startup_right_mode
;
704 other_mode
= startup_left_mode
;
706 /* Creates the left panel */
707 if (mc_run_param0
!= NULL
)
709 if (mc_run_param1
!= NULL
)
711 /* Ok, user has specified two dirs, save the original one,
712 * since we may not be able to chdir to the proper
713 * second directory later
715 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
717 translated_mc_chdir (mc_run_param0
);
719 set_display_type (current_index
, current_mode
);
721 /* The other panel */
722 if (mc_run_param1
!= NULL
)
724 if (original_dir
[0] != '\0')
725 translated_mc_chdir (original_dir
);
726 translated_mc_chdir (mc_run_param1
);
728 set_display_type (other_index
, other_mode
);
730 if (startup_left_mode
== view_listing
)
732 current_panel
= left_panel
;
737 current_panel
= right_panel
;
739 current_panel
= left_panel
;
742 /* Create the nice widgets */
743 cmdline
= command_new (0, 0, 0);
744 the_prompt
= label_new (0, 0, mc_prompt
);
745 the_prompt
->transparent
= 1;
746 the_bar
= buttonbar_new (keybar_visible
);
748 the_hint
= label_new (0, 0, 0);
749 the_hint
->transparent
= 1;
750 the_hint
->auto_adjust_cols
= 0;
751 the_hint
->widget
.cols
= COLS
;
753 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
756 /* --------------------------------------------------------------------------------------------- */
759 copy_current_pathname (void)
765 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
766 command_insert (cmdline
, cwd_path
, FALSE
);
768 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
769 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
773 /* --------------------------------------------------------------------------------------------- */
776 copy_other_pathname (void)
780 if (get_other_type () != view_listing
)
786 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
787 command_insert (cmdline
, cwd_path
, FALSE
);
789 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
790 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
794 /* --------------------------------------------------------------------------------------------- */
797 copy_readlink (WPanel
* panel
)
801 if (S_ISLNK (selection (panel
)->st
.st_mode
))
803 char buffer
[MC_MAXPATHLEN
];
804 char *p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
807 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
812 command_insert (cmdline
, buffer
, TRUE
);
817 /* --------------------------------------------------------------------------------------------- */
820 copy_current_readlink (void)
822 copy_readlink (current_panel
);
825 /* --------------------------------------------------------------------------------------------- */
828 copy_other_readlink (void)
830 if (get_other_type () == view_listing
)
831 copy_readlink (other_panel
);
834 /* --------------------------------------------------------------------------------------------- */
835 /** Insert the selected file name into the input line */
838 copy_prog_name (void)
844 if (get_current_type () == view_tree
)
846 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
847 tmp
= tree_selected_name (tree
);
850 tmp
= selection (current_panel
)->fname
;
852 command_insert (cmdline
, tmp
, TRUE
);
855 /* --------------------------------------------------------------------------------------------- */
858 copy_tagged (WPanel
* panel
)
864 input_disable_update (cmdline
);
867 for (i
= 0; i
< panel
->count
; i
++)
869 if (panel
->dir
.list
[i
].f
.marked
)
870 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
875 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
877 input_enable_update (cmdline
);
880 /* --------------------------------------------------------------------------------------------- */
883 copy_current_tagged (void)
885 copy_tagged (current_panel
);
888 /* --------------------------------------------------------------------------------------------- */
891 copy_other_tagged (void)
893 if (get_other_type () == view_listing
)
894 copy_tagged (other_panel
);
897 /* --------------------------------------------------------------------------------------------- */
902 ctl_x_map_enabled
= TRUE
;
905 /* --------------------------------------------------------------------------------------------- */
908 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
910 cb_ret_t res
= MSG_HANDLED
;
914 /* stop quick search before executing any command */
915 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
922 case CK_ChangeListingCmd
:
923 change_listing_cmd ();
931 case CK_ChownAdvancedCmd
:
932 chown_advanced_cmd ();
934 case CK_CompareDirsCmd
:
937 case CK_ConfigureBox
:
941 case CK_ConfigureVfs
:
951 case CK_CopyCurrentPathname
:
952 copy_current_pathname ();
954 case CK_CopyCurrentReadlink
:
955 copy_current_readlink ();
957 case CK_CopyCurrentTagged
:
958 copy_current_tagged ();
960 case CK_CopyOtherPathname
:
961 copy_other_pathname ();
963 case CK_CopyOtherReadlink
:
964 copy_other_readlink ();
966 case CK_CopyOtherTagged
:
967 copy_other_tagged ();
972 case CK_DialogListCmd
:
973 dialog_switch_list ();
980 case CK_DisplayBitsBox
:
986 #ifdef USE_INTERNAL_EDIT
987 case CK_EditForceInternalCmd
:
988 edit_cmd_force_internal ();
991 case CK_EditExtFileCmd
:
994 case CK_EditFhlFileCmd
:
997 case CK_EditMcMenuCmd
:
1000 case CK_EditSymlinkCmd
:
1001 edit_symlink_cmd ();
1003 case CK_ExternalPanelize
:
1004 external_panelize ();
1009 case CK_FilteredViewCmd
:
1010 filtered_view_cmd ();
1015 #ifdef ENABLE_VFS_FISH
1016 case CK_FishlinkCmd
:
1020 #ifdef ENABLE_VFS_FTP
1032 if (sender
== (Widget
*) the_menubar
)
1033 info_cmd (); /* mwnu */
1035 info_cmd_no_menu (); /* shortcut or buttonbar */
1037 #ifdef WITH_BACKGROUND
1049 link_cmd (LINK_HARDLINK
);
1054 #ifdef LISTMODE_EDITOR
1055 case CK_ListmodeCmd
:
1062 case CK_MenuLastSelectedCmd
:
1063 menu_last_selected_cmd ();
1068 case CK_PanelOptionsBox
:
1069 panel_options_box ();
1072 case CK_PanelSetPanelEncoding
:
1079 case CK_QuickChdirCmd
:
1082 case CK_QuickViewCmd
:
1083 if (sender
== (Widget
*) the_menubar
)
1084 quick_view_cmd (); /* menu */
1086 quick_cmd_no_menu (); /* shortcut or buttonabr */
1088 case CK_QuietQuitCmd
:
1094 case CK_RelativeSymlinkCmd
:
1095 link_cmd (LINK_SYMLINK_RELATIVE
);
1104 case CK_ReselectVfs
:
1108 case CK_ReverseSelectionCmd
:
1109 reverse_selection_cmd ();
1111 case CK_SaveSetupCmd
:
1117 case CK_ShowCommandLine
:
1120 case CK_SingleDirsizeCmd
:
1121 smart_dirsize_cmd ();
1123 #ifdef ENABLE_VFS_SMB
1127 #endif /* ENABLE_VFS_SMB */
1131 case CK_StartExtMap1
:
1141 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1143 case CK_ToggleListingCmd
:
1144 toggle_listing_cmd ();
1146 case CK_ToggleShowHidden
:
1147 toggle_show_hidden ();
1149 case CK_TogglePanelsSplit
:
1150 toggle_panels_split ();
1158 #ifdef ENABLE_VFS_UNDELFS
1159 case CK_UndeleteCmd
:
1163 case CK_UnselectCmd
:
1166 case CK_UserMenuCmd
:
1167 user_file_menu_cmd ();
1172 case CK_ViewFileCmd
:
1176 res
= MSG_NOT_HANDLED
;
1182 /* --------------------------------------------------------------------------------------------- */
1185 init_xterm_support (void)
1187 const char *termvalue
;
1189 termvalue
= getenv ("TERM");
1190 if (!termvalue
|| !(*termvalue
))
1192 fputs (_("The TERM environment variable is unset!\n"), stderr
);
1193 exit (EXIT_FAILURE
);
1196 /* Check mouse capabilities */
1197 xmouse_seq
= tty_tgetstr ("Km");
1199 if (strcmp (termvalue
, "cygwin") == 0)
1201 mc_args__force_xterm
= 1;
1202 use_mouse_p
= MOUSE_DISABLED
;
1205 if (mc_args__force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
1206 || strncmp (termvalue
, "konsole", 7) == 0
1207 || strncmp (termvalue
, "rxvt", 4) == 0
1208 || strcmp (termvalue
, "Eterm") == 0 || strcmp (termvalue
, "dtterm") == 0)
1212 /* Default to the standard xterm sequence */
1215 xmouse_seq
= ESC_STR
"[M";
1218 /* Enable mouse unless explicitly disabled by --nomouse */
1219 if (use_mouse_p
!= MOUSE_DISABLED
)
1221 const char *color_term
= getenv ("COLORTERM");
1222 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
1223 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
1224 strcmp (termvalue
, "Eterm") == 0)
1226 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
1230 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
1236 /* --------------------------------------------------------------------------------------------- */
1242 tty_display_8bit (full_eight_bits
!= 0);
1244 tty_display_8bit (eight_bit_clean
!= 0);
1247 #ifdef HAVE_SUBSHELL_SUPPORT
1249 add_select_channel (subshell_pty
, load_prompt
, 0);
1250 #endif /* !HAVE_SUBSHELL_SUPPORT */
1252 tty_setup_sigwinch (sigwinch_handler
);
1254 if ((tty_baudrate () < 9600) || tty_is_slow ())
1257 init_xterm_support ();
1261 /* --------------------------------------------------------------------------------------------- */
1264 setup_dummy_mc (void)
1266 char d
[MC_MAXPATHLEN
];
1269 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1274 /* --------------------------------------------------------------------------------------------- */
1279 const char *current_system_codepage
= NULL
;
1281 current_system_codepage
= str_detect_termencoding ();
1285 const char *_display_codepage
;
1287 _display_codepage
= get_codepage_id (display_codepage
);
1289 if (!strcmp (_display_codepage
, current_system_codepage
))
1291 utf8_display
= str_isutf8 (current_system_codepage
);
1295 display_codepage
= get_codepage_index (current_system_codepage
);
1296 if (display_codepage
== -1)
1298 display_codepage
= 0;
1301 mc_config_set_string (mc_main_config
, "Misc", "display_codepage", cp_display
);
1304 utf8_display
= str_isutf8 (current_system_codepage
);
1307 /* --------------------------------------------------------------------------------------------- */
1312 if (!(quit
& SUBSHELL_EXIT
))
1314 tty_reset_shell_mode ();
1320 /* --------------------------------------------------------------------------------------------- */
1329 * We sync the profiles since the hotlist may have changed, while
1330 * we only change the setup data if we have the auto save feature set
1333 if (auto_save_setup
)
1334 save_setup (); /* does also call save_hotlist */
1338 save_panel_types ();
1342 vfs_stamp_path (vfs_get_current_dir ());
1344 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
1345 vfs_stamp_path (current_panel
->cwd
);
1347 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
1348 vfs_stamp_path (other_panel
->cwd
);
1351 /* --------------------------------------------------------------------------------------------- */
1354 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1356 unsigned long command
;
1366 /* We handle the special case of the output lines */
1367 if (console_flag
&& output_lines
)
1368 show_console_contents (output_start_y
,
1369 LINES
- output_lines
- keybar_visible
-
1370 1, LINES
- keybar_visible
- 1);
1375 menubar_arrange (the_menubar
);
1379 /* We only need the first idle event to show user menu after start */
1380 set_idle_proc (h
, 0);
1382 if (boot_current_is_left
)
1383 dlg_select_widget (get_panel_widget (0));
1385 dlg_select_widget (get_panel_widget (1));
1388 midnight_execute_cmd (NULL
, CK_UserMenuCmd
);
1392 if (ctl_x_map_enabled
)
1394 ctl_x_map_enabled
= FALSE
;
1395 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1396 if (command
!= CK_Ignore_Key
)
1397 return midnight_execute_cmd (NULL
, command
);
1400 /* FIXME: should handle all menu shortcuts before this point */
1401 if (the_menubar
->is_active
)
1402 return MSG_NOT_HANDLED
;
1405 input_free_completions (cmdline
);
1411 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1412 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1415 if (cmdline
->buffer
[i
] != '\0')
1417 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1421 input_insert (cmdline
, "", FALSE
);
1425 /* Ctrl-Enter and Alt-Enter */
1426 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1432 /* Ctrl-Shift-Enter */
1433 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1435 copy_current_pathname ();
1440 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1441 && !quote
&& !current_panel
->searching
)
1443 if (!only_leading_plus_minus
)
1445 /* Special treatement, since the input line will eat them */
1452 if (parm
== '\\' || parm
== '-')
1460 reverse_selection_cmd ();
1464 else if (!command_prompt
|| !cmdline
->buffer
[0])
1466 /* Special treatement '+', '-', '\', '*' only when this is
1467 * first char on input line
1476 if (parm
== '\\' || parm
== '-')
1484 reverse_selection_cmd ();
1489 return MSG_NOT_HANDLED
;
1491 case DLG_HOTKEY_HANDLED
:
1492 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1494 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1495 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
1499 case DLG_UNHANDLED_KEY
:
1504 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1505 if (v
== MSG_HANDLED
)
1509 if (ctl_x_map_enabled
)
1511 ctl_x_map_enabled
= FALSE
;
1512 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1515 command
= keybind_lookup_keymap_command (main_map
, parm
);
1517 return (command
== CK_Ignore_Key
) ? MSG_NOT_HANDLED
: midnight_execute_cmd (NULL
, command
);
1520 if (!the_menubar
->is_active
)
1521 update_dirty_panels ();
1527 midnight_execute_cmd (NULL
, parm
);
1528 /* message from menu */
1529 else if (sender
== (Widget
*) the_menubar
)
1530 midnight_execute_cmd (sender
, parm
);
1531 /* message from buttonbar */
1532 else if (sender
== (Widget
*) the_bar
)
1535 midnight_execute_cmd (sender
, parm
);
1537 send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1542 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1546 /* --------------------------------------------------------------------------------------------- */
1549 create_panels_and_run_mc (void)
1551 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
1552 midnight_dlg
->get_title
= midnight_get_title
;
1556 add_widget (midnight_dlg
, the_menubar
);
1559 add_widget (midnight_dlg
, get_panel_widget (0));
1560 add_widget (midnight_dlg
, get_panel_widget (1));
1562 add_widget (midnight_dlg
, the_hint
);
1563 add_widget (midnight_dlg
, cmdline
);
1564 add_widget (midnight_dlg
, the_prompt
);
1566 add_widget (midnight_dlg
, the_bar
);
1567 midnight_set_buttonbar (the_bar
);
1569 /* Run the Midnight Commander if no file was specified in the command line */
1570 run_dlg (midnight_dlg
);
1573 /* --------------------------------------------------------------------------------------------- */
1574 /** result must be free'd (I think this should go in util.c) */
1577 prepend_cwd_on_local (const char *filename
)
1582 if (!vfs_file_is_local (filename
) || g_path_is_absolute (filename
))
1583 return g_strdup (filename
);
1585 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1586 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1589 strcpy (d
+ l
, filename
);
1590 canonicalize_pathname (d
);
1594 /* --------------------------------------------------------------------------------------------- */
1595 /** Invoke the internal view/edit routine with:
1596 * the default processing and forcing the internal viewer/editor
1600 mc_maybe_editor_or_viewer (void)
1602 switch (mc_run_mode
)
1604 #ifdef USE_INTERNAL_EDIT
1606 edit_file (mc_run_param0
, mc_args__edit_start_line
);
1608 #endif /* USE_INTERNAL_EDIT */
1612 path
= prepend_cwd_on_local (mc_run_param0
);
1613 view_file (path
, 0, 1);
1617 #ifdef USE_DIFF_VIEW
1618 case MC_RUN_DIFFVIEWER
:
1619 diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
1621 #endif /* USE_DIFF_VIEW */
1625 midnight_shutdown
= 1;
1628 /* --------------------------------------------------------------------------------------------- */
1629 /** Run the main dialog that occupies the whole screen */
1634 dlg_colors_t midnight_colors
;
1635 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1636 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1637 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1638 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1639 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1643 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1644 "[main]", NULL
, DLG_WANT_IDLE
);
1646 if (mc_run_mode
== MC_RUN_FULL
)
1651 /* start check display_codepage and source_codepage */
1654 /* Check if we were invoked as an editor or file viewer */
1655 if (mc_run_mode
!= MC_RUN_FULL
)
1656 mc_maybe_editor_or_viewer ();
1659 create_panels_and_run_mc ();
1662 midnight_shutdown
= 1;
1664 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1665 if (mc_args__last_wd_file
&& vfs_current_is_local ())
1666 last_wd_string
= g_strdup (current_panel
->cwd
);
1670 dialog_switch_shutdown ();
1672 destroy_dlg (midnight_dlg
);
1678 /* --------------------------------------------------------------------------------------------- */
1679 /** POSIX version. The only version we support. */
1684 const char *shell_env
= getenv ("SHELL");
1685 const char *mc_libdir
;
1687 if ((shell_env
== NULL
) || (shell_env
[0] == '\0'))
1690 pwd
= getpwuid (geteuid ());
1692 shell
= g_strdup (pwd
->pw_shell
);
1695 shell
= g_strdup (shell_env
);
1697 if ((shell
== NULL
) || (shell
[0] == '\0'))
1700 shell
= g_strdup ("/bin/sh");
1703 /* This is the directory, where MC was installed, on Unix this is DATADIR */
1704 /* and can be overriden by the MC_DATADIR environment variable */
1705 mc_libdir
= getenv ("MC_DATADIR");
1706 if (mc_libdir
!= NULL
)
1708 mc_home
= g_strdup (mc_libdir
);
1709 mc_home_alt
= g_strdup (SYSCONFDIR
);
1713 mc_home
= g_strdup (SYSCONFDIR
);
1714 mc_home_alt
= g_strdup (DATADIR
);
1717 /* This variable is used by the subshell */
1718 home_dir
= getenv ("HOME");
1724 /* --------------------------------------------------------------------------------------------- */
1727 sigchld_handler_no_subshell (int sig
)
1735 /* COMMENT: if it were true that after the call to handle_console(..INIT)
1736 the value of console_flag never changed, we could simply not install
1737 this handler at all if (!console_flag && !use_subshell). */
1739 /* That comment is no longer true. We need to wait() on a sigchld
1740 handler (that's at least what the tarfs code expects currently). */
1742 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
1744 if (pid
== cons_saver_pid
)
1747 if (WIFSTOPPED (status
))
1749 /* Someone has stopped cons.saver - restart it */
1750 kill (pid
, SIGCONT
);
1754 /* cons.saver has died - disable console saving */
1755 handle_console (CONSOLE_DONE
);
1759 /* If we got here, some other child exited; ignore it */
1760 #endif /* __linux__ */
1765 /* --------------------------------------------------------------------------------------------- */
1770 struct sigaction sigchld_action
;
1772 sigchld_action
.sa_handler
=
1773 #ifdef HAVE_SUBSHELL_SUPPORT
1774 use_subshell
? sigchld_handler
:
1775 #endif /* HAVE_SUBSHELL_SUPPORT */
1776 sigchld_handler_no_subshell
;
1778 sigemptyset (&sigchld_action
.sa_mask
);
1781 sigchld_action
.sa_flags
= SA_RESTART
;
1783 sigchld_action
.sa_flags
= 0;
1784 #endif /* !SA_RESTART */
1786 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1)
1788 #ifdef HAVE_SUBSHELL_SUPPORT
1790 * This may happen on QNX Neutrino 6, where SA_RESTART
1791 * is defined but not implemented. Fallback to no subshell.
1794 #endif /* HAVE_SUBSHELL_SUPPORT */
1798 /* --------------------------------------------------------------------------------------------- */
1799 /*** public functions ****************************************************************************/
1800 /* --------------------------------------------------------------------------------------------- */
1802 /** Define this function for glib-style error handling */
1804 mc_main_error_quark (void)
1806 return g_quark_from_static_string (PACKAGE
);
1809 /* --------------------------------------------------------------------------------------------- */
1810 /** Save current stat of directories to avoid reloading the panels
1811 * when no modifications have taken place
1815 save_cwds_stat (void)
1817 if (panels_options
.fast_reload
)
1819 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
1820 if (get_other_type () == view_listing
)
1821 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
1825 /* --------------------------------------------------------------------------------------------- */
1827 #ifdef HAVE_SUBSHELL_SUPPORT
1829 do_update_prompt (void)
1833 printf ("\r\n%s", subshell_prompt
);
1838 #endif /* HAVE_SUBSHELL_SUPPORT */
1840 /* --------------------------------------------------------------------------------------------- */
1845 input_free_completions (cmdline
);
1846 dlg_one_down (midnight_dlg
);
1849 /* --------------------------------------------------------------------------------------------- */
1854 menu_set_name (left_menu
, horizontal_split
? _("&Above") : _("&Left"));
1855 menu_set_name (right_menu
, horizontal_split
? _("&Below") : _("&Right"));
1856 menubar_arrange (the_menubar
);
1859 /* --------------------------------------------------------------------------------------------- */
1862 quiet_quit_cmd (void)
1864 print_last_revert
= 1;
1865 return quit_cmd_internal (1);
1868 /* --------------------------------------------------------------------------------------------- */
1869 /** Wrapper for do_subshell_chdir, check for availability of subshell */
1872 subshell_chdir (const char *directory
)
1874 #ifdef HAVE_SUBSHELL_SUPPORT
1877 if (vfs_current_is_local ())
1878 do_subshell_chdir (directory
, 0, 1);
1880 #endif /* HAVE_SUBSHELL_SUPPORT */
1883 /* --------------------------------------------------------------------------------------------- */
1886 do_cd (const char *new_dir
, enum cd_enum exact
)
1890 res
= do_panel_cd (current_panel
, new_dir
, exact
);
1895 const char *enc_name
;
1897 enc_name
= vfs_get_encoding (current_panel
->cwd
);
1898 if (enc_name
!= NULL
)
1899 current_panel
->codepage
= get_codepage_index (enc_name
);
1901 current_panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
1903 #endif /* HAVE_CHARSET */
1908 /* --------------------------------------------------------------------------------------------- */
1910 #ifdef HAVE_SUBSHELL_SUPPORT
1912 load_prompt (int fd
, void *unused
)
1917 if (!read_subshell_prompt ())
1920 /* Don't actually change the prompt if it's invisible */
1921 if (((Dlg_head
*) top_dlg
->data
== midnight_dlg
) && command_prompt
)
1926 tmp_prompt
= strip_ctrl_codes (subshell_prompt
);
1927 prompt_len
= str_term_width1 (tmp_prompt
);
1929 /* Check for prompts too big */
1930 if (COLS
> 8 && prompt_len
> COLS
- 8)
1932 prompt_len
= COLS
- 8;
1933 tmp_prompt
[prompt_len
] = '\0';
1935 mc_prompt
= tmp_prompt
;
1936 label_set_text (the_prompt
, mc_prompt
);
1937 input_set_origin ((WInput
*) cmdline
, prompt_len
, COLS
- prompt_len
);
1939 /* since the prompt has changed, and we are called from one of the
1940 * tty_get_event channels, the prompt updating does not take place
1941 * automatically: force a cursor update and a screen refresh
1943 update_cursor (midnight_dlg
);
1949 #endif /* HAVE_SUBSHELL_SUPPORT */
1951 /* --------------------------------------------------------------------------------------------- */
1957 const panel_field_t
*sort_order
;
1959 if (!SELECTED_IS_PANEL
)
1963 sort_order
= sort_box (p
->current_sort_field
, &p
->reverse
, &p
->case_sensitive
, &p
->exec_first
);
1965 panel_set_sort_order (p
, sort_order
);
1969 /* --------------------------------------------------------------------------------------------- */
1972 toggle_show_hidden (void)
1974 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1975 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1978 /* --------------------------------------------------------------------------------------------- */
1981 midnight_set_buttonbar (WButtonBar
* b
)
1983 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1984 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1985 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1986 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1987 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1988 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1989 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1990 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1991 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1992 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1995 /* --------------------------------------------------------------------------------------------- */
1996 /** Show current directory in the xterm title */
1999 update_xterm_title_path (void)
2001 /* TODO: share code with midnight_get_title () */
2004 char host
[BUF_TINY
];
2006 struct passwd
*pw
= NULL
;
2010 if (xterm_flag
&& xterm_title
)
2012 path
= strip_home_and_password (current_panel
->cwd
);
2013 res
= gethostname (host
, sizeof (host
));
2015 { /* On success, res = 0 */
2020 host
[sizeof (host
) - 1] = '\0';
2022 pw
= getpwuid (getuid ());
2025 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
2029 login
= g_strdup (host
);
2031 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
2032 fprintf (stdout
, "\33]0;%s\7", str_term_form (p
));
2035 if (!alternate_plus_minus
)
2036 numeric_keypad_mode ();
2041 /* --------------------------------------------------------------------------------------------- */
2043 * Load new hint and display it.
2044 * IF force is not 0, ignore the timeout.
2048 load_hint (int force
)
2052 if (!the_hint
->widget
.owner
)
2055 if (!message_visible
)
2057 label_set_text (the_hint
, NULL
);
2061 hint
= get_random_hint (force
);
2071 char text
[BUF_SMALL
];
2073 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
2078 /* --------------------------------------------------------------------------------------------- */
2081 main (int argc
, char *argv
[])
2085 GError
*error
= NULL
;
2086 gboolean isInitialized
;
2088 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2089 setlocale (LC_ALL
, "");
2090 bindtextdomain ("mc", LOCALEDIR
);
2093 /* Set up temporary directory */
2098 str_init_strings (NULL
);
2102 #ifdef USE_INTERNAL_EDIT
2106 if (!mc_args_handle (argc
, argv
, "mc"))
2107 exit (EXIT_FAILURE
);
2109 /* NOTE: This has to be called before tty_init or whatever routine
2110 calls any define_sequence */
2113 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
2114 handle_console (CONSOLE_INIT
);
2116 #ifdef HAVE_SUBSHELL_SUPPORT
2117 /* Don't use subshell when invoked as viewer or editor */
2118 if (mc_run_mode
!= MC_RUN_FULL
)
2122 subshell_get_console_attributes ();
2123 #endif /* HAVE_SUBSHELL_SUPPORT */
2125 /* Install the SIGCHLD handler; must be done before init_subshell() */
2128 /* We need this, since ncurses endwin () doesn't restore the signals */
2129 save_stop_handler ();
2131 /* Must be done before init_subshell, to set up the terminal size: */
2132 /* FIXME: Should be removed and LINES and COLS computed on subshell */
2133 tty_init ((gboolean
) mc_args__slow_terminal
, (gboolean
) mc_args__ugly_line_drawing
);
2137 /* Removing this from the X code let's us type C-c */
2140 load_keymap_defs ();
2142 tty_init_colors (mc_args__disable_colors
, mc_args__force_colors
);
2144 isInitialized
= mc_skin_init (&error
);
2146 mc_filehighlight
= mc_fhl_new (TRUE
);
2148 dlg_set_default_colors ();
2152 message (D_ERROR
, _("Warning"), "%s", error
->message
);
2153 g_error_free (error
);
2157 /* create home directory */
2158 /* do it after the screen library initialization to show the error message */
2159 mc_dir
= concat_dir_and_file (home_dir
, MC_USERCONF_DIR
);
2160 canonicalize_pathname (mc_dir
);
2161 if ((stat (mc_dir
, &s
) != 0) && (errno
== ENOENT
) && mkdir (mc_dir
, 0700) != 0)
2162 message (D_ERROR
, _("Warning"), _("Cannot create %s directory"), mc_dir
);
2165 #ifdef HAVE_SUBSHELL_SUPPORT
2166 /* Done here to ensure that the subshell doesn't */
2167 /* inherit the file descriptors opened below, etc */
2171 #endif /* HAVE_SUBSHELL_SUPPORT */
2173 /* Also done after init_subshell, to save any shell init file messages */
2175 handle_console (CONSOLE_SAVE
);
2177 if (alternate_plus_minus
)
2178 application_keypad_mode ();
2180 #ifdef HAVE_SUBSHELL_SUPPORT
2183 mc_prompt
= strip_ctrl_codes (subshell_prompt
);
2184 if (mc_prompt
== NULL
)
2185 mc_prompt
= (geteuid () == 0) ? "# " : "$ ";
2188 #endif /* HAVE_SUBSHELL_SUPPORT */
2189 mc_prompt
= (geteuid () == 0) ? "# " : "$ ";
2191 /* Program main loop */
2192 if (!midnight_shutdown
)
2195 /* Save the tree store */
2198 free_keymap_defs ();
2200 /* Virtual File System shutdown */
2203 flush_extension_file (); /* does only free memory */
2205 mc_fhl_free (&mc_filehighlight
);
2210 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2211 handle_console (CONSOLE_RESTORE
);
2212 if (alternate_plus_minus
)
2213 numeric_keypad_mode ();
2215 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2218 handle_console (CONSOLE_DONE
);
2219 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2221 if (mc_run_mode
== MC_RUN_FULL
&& mc_args__last_wd_file
&& last_wd_string
&& !print_last_revert
)
2223 int last_wd_fd
= open (mc_args__last_wd_file
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_EXCL
,
2226 if (last_wd_fd
!= -1)
2230 ret1
= write (last_wd_fd
, last_wd_string
, strlen (last_wd_string
));
2231 ret2
= close (last_wd_fd
);
2234 g_free (last_wd_string
);
2236 g_free (mc_home_alt
);
2242 free_codepages_list ();
2243 g_free (autodetect_codeset
);
2245 g_free (clipboard_store_path
);
2246 g_free (clipboard_paste_path
);
2248 str_uninit_strings ();
2250 g_free (mc_run_param0
);
2251 g_free (mc_run_param1
);
2253 #ifdef USE_INTERNAL_EDIT
2260 /* --------------------------------------------------------------------------------------------- */