1 /* Main program for the Midnight Commander
2 Copyright (C) 1994, 1995, 1996, 1997 The Free Software Foundation
4 Written by: 1994, 1995, 1996, 1997 Miguel de Icaza
5 1994, 1995 Janne Kukonlehto
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
32 #include <sys/types.h>
44 /* Program include files */
57 #include "cons.saver.h"
59 #include "key.h" /* For init_key() and mi_getch() */
60 #include "setup.h" /* save_setup() */
61 #include "profile.h" /* free_profiles() */
62 #include "boxes.h" /* sort_box() */
64 #include "cmd.h" /* Normal commands */
67 #include "learn.h" /* learn_keys() */
69 #include "background.h"
70 #include "ext.h" /* For flush_extension_file() */
72 /* Listbox for the command history feature */
76 #include "complete.h" /* For the free_completion */
86 #include "../vfs/smbfs.h" /* smbfs_set_debug() */
89 #ifdef USE_INTERNAL_EDIT
90 # include "../edit/edit.h"
95 #endif /* HAVE_CHARSET */
99 /* When the modes are active, left_panel, right_panel and tree_panel */
100 /* Point to a proper data structure. You should check with the functions */
101 /* get_current_type and get_other_type the types of the panels before using */
102 /* This pointer variables */
104 /* The structures for the panels */
108 /* The pointer to the tree */
112 struct WMenu
*the_menubar
;
114 /* Pointers to the selected and unselected panel */
115 WPanel
*current_panel
= NULL
;
117 /* Set if the command is being run from the "Right" menu */
120 /* Set when main loop should be terminated */
121 volatile int quit
= 0;
123 /* Set if you want the possible completions dialog for the first time */
124 int show_all_if_ambiguous
= 0;
126 /* Set when cd symlink following is desirable (bash mode) */
129 /* If set then dialogs just clean the screen when refreshing, else */
130 /* they do a complete refresh, refreshing all the parts of the program */
131 int fast_refresh
= 0;
133 /* If true, marking a files moves the cursor down */
134 int mark_moves_down
= 1;
136 /* If true, at startup the user-menu is invoked */
139 /* If true, use + and \ keys normally and select/unselect do if M-+ / M-\
140 and M-- and keypad + / - */
141 int alternate_plus_minus
= 0;
143 /* If true, then the +, - and \ keys have their special meaning only if the
144 * command line is emtpy, otherwise they behave like regular letters
146 int only_leading_plus_minus
= 1;
148 /* If true, after executing a command, wait for a keystroke */
149 enum { pause_never
, pause_on_dumb_terminals
, pause_always
};
151 int pause_after_run
= pause_on_dumb_terminals
;
153 /* It true saves the setup when quitting */
154 int auto_save_setup
= 1;
157 /* If true, allow characters in the range 160-255 */
158 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 */
167 /* If true use the internal viewer */
168 int use_internal_view
= 1;
170 /* Have we shown the fast-reload warning in the past? */
171 int fast_reload_w
= 0;
173 /* Move page/item? When clicking on the top or bottom of a panel */
174 int mouse_move_pages
= 1;
176 /* If true: l&r arrows are used to chdir if the input line is empty */
177 int navigate_with_arrows
= 0;
179 /* If true use +, -, | for line drawing */
180 int force_ugly_line_drawing
= 0;
182 /* If true program softkeys (HP terminals only) on startup and after every
183 command ran in the subshell to the description found in the termcap/terminfo
185 int reset_hp_softkeys
= 0;
190 /* The widget where we draw the prompt */
199 /* For slow terminals */
200 int slow_terminal
= 0;
202 /* Mouse type: GPM, xterm or none */
203 Mouse_Type use_mouse_p
= MOUSE_NONE
;
205 /* If true, assume we are running on an xterm terminal */
206 static int force_xterm
= 0;
208 /* Controls screen clearing before an exec */
209 int clear_before_exec
= 1;
211 /* Asks for confirmation before deleting a file */
212 int confirm_delete
= 1;
214 /* Asks for confirmation before overwriting a file */
215 int confirm_overwrite
= 1;
217 /* Asks for confirmation before executing a program by pressing enter */
218 int confirm_execute
= 0;
220 /* Asks for confirmation before leaving the program */
221 int confirm_exit
= 1;
223 /* Asks for confirmation when using F3 to view a directory and there
225 int confirm_view_dir
= 0;
227 /* This flag indicates if the pull down menus by default drop down */
230 /* The dialog handle for the main program */
231 Dlg_head
*midnight_dlg
;
233 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
234 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
235 int update_prompt
= 0;
238 /* The name which was used to invoke mc */
242 /* The home directory */
245 /* The value of the other directory, only used when loading the setup */
248 /* Only used at program boot */
249 int boot_current_is_left
= 1;
253 /* If this is true, then when browsing the tree the other window will
254 * automatically reload it's directory with the contents of the currently
255 * selected directory.
259 /* If set, then print to the given file the last directory we were at */
260 static char *last_wd_file
;
261 static char *last_wd_string
;
262 /* Set to 1 to suppress printing the last directory */
263 static int print_last_revert
= 0;
265 /* Force colors, only used by Slang */
266 int force_colors
= 0;
268 /* colors specified on the command line: they override any other setting */
269 char *command_line_colors
;
271 /* File name to view if argument was supplied */
272 char *view_one_file
= 0;
274 /* File name to edit if argument was supplied */
275 char *edit_one_file
= 0;
277 /* Line to start the editor on */
278 static int edit_one_file_start_line
= 0;
280 /* Used so that widgets know if they are being destroyed or
282 int midnight_shutdown
= 0;
284 /* to show nice prompts */
285 static int last_paused
= 0;
287 /* Used for keeping track of the original stdout */
290 /* The user's shell */
293 /* mc_home: The home of MC */
299 get_current_panel (void)
301 return current_panel
;
305 get_other_panel (void)
307 return (WPanel
*) get_panel_widget (get_other_index ());
311 reload_panelized (WPanel
*panel
)
314 dir_list
*list
= &panel
->dir
;
317 mc_chdir (panel
->cwd
);
319 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
320 if (list
->list
[i
].f
.marked
) {
321 /* Unmark the file in advance. In case the following mc_lstat
322 * fails we are done, else we have to mark the file again
323 * (Note: do_file_mark depends on a valid "list->list [i].buf").
324 * IMO that's the best way to update the panel's summary status
327 do_file_mark (panel
, i
, 0);
329 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].buf
)) {
330 g_free (list
->list
[i
].fname
);
333 if (list
->list
[i
].f
.marked
)
334 do_file_mark (panel
, i
, 1);
336 list
->list
[j
] = list
->list
[i
];
340 panel
->count
= set_zero_dir (list
);
345 mc_chdir (cpanel
->cwd
);
349 update_one_panel_widget (WPanel
*panel
, int force_update
,
354 if (force_update
& UP_RELOAD
) {
355 panel
->is_panelized
= 0;
360 /* FIXME: Should supply flushdir method */
361 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
364 /* If current_file == -1 (an invalid pointer) then preserve selection */
365 if (current_file
== UP_KEEPSEL
) {
367 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
371 if (panel
->is_panelized
)
372 reload_panelized (panel
);
374 panel_reload (panel
);
376 try_to_select (panel
, current_file
);
380 g_free (current_file
);
384 panel_clean_dir (WPanel
*panel
)
386 int count
= panel
->count
;
392 panel
->dirs_marked
= 0;
394 panel
->searching
= 0;
395 panel
->is_panelized
= 0;
397 clean_dir (&panel
->dir
, count
);
401 update_one_panel (int which
, int force_update
, char *current_file
)
405 if (get_display_type (which
) != view_listing
)
408 panel
= (WPanel
*) get_panel_widget (which
);
409 update_one_panel_widget (panel
, force_update
, current_file
);
412 /* This routine reloads the directory in both panels. It tries to
413 * select current_file in current_panel and other_file in other_panel.
414 * If current_file == -1 then it automatically sets current_file and
415 * other_file to the currently selected files in the panels.
417 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
418 * will not reload the other panel.
421 update_panels (int force_update
, char *current_file
)
423 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
426 update_one_panel (get_current_index (), force_update
, current_file
);
428 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
430 if (get_current_type () == view_listing
)
431 panel
= (WPanel
*) get_panel_widget (get_current_index ());
433 panel
= (WPanel
*) get_panel_widget (get_other_index ());
435 mc_chdir (panel
->cwd
);
438 /* Sets up the terminal before executing a program */
446 /* Save current stat of directories to avoid reloading the panels */
447 /* when no modifications have taken place */
449 save_cwds_stat (void)
452 mc_stat (cpanel
->cwd
, &(cpanel
->dir_stat
));
453 if (get_other_type () == view_listing
)
454 mc_stat (opanel
->cwd
, &(opanel
->dir_stat
));
458 #ifdef HAVE_SUBSHELL_SUPPORT
460 do_possible_cd (char *new_dir
)
462 if (!do_cd (new_dir
, cd_exact
))
463 message (1, _("Warning"),
464 _(" The Commander can't change to the directory that \n"
465 " the subshell claims you are in. Perhaps you have \n"
466 " deleted your working directory, or given yourself \n"
467 " extra access permissions with the \"su\" command? "));
471 do_update_prompt (void)
474 printf ("%s", subshell_prompt
);
479 #endif /* HAVE_SUBSHELL_SUPPORT */
482 restore_console (void)
484 handle_console (CONSOLE_RESTORE
);
490 do_execute (shell
, 0, 0);
494 do_execute (const char *shell
, const char *command
, int flags
)
496 #ifdef HAVE_SUBSHELL_SUPPORT
497 char *new_dir
= NULL
;
498 #endif /* HAVE_SUBSHELL_SUPPORT */
501 char *old_vfs_dir
= 0;
503 if (!vfs_current_is_local ())
504 old_vfs_dir
= g_strdup (vfs_get_current_dir ());
512 if (!use_subshell
&& !(flags
& EXECUTE_INTERNAL
&& command
)) {
513 printf ("%s%s%s\n", last_paused
? "\r\n" : "", prompt
, command
);
516 #ifdef HAVE_SUBSHELL_SUPPORT
517 if (use_subshell
&& !(flags
& EXECUTE_INTERNAL
)) {
520 /* We don't care if it died, higher level takes care of this */
522 invoke_subshell (command
, VISIBLY
, old_vfs_dir
? 0 : &new_dir
);
524 invoke_subshell (command
, VISIBLY
, &new_dir
);
525 #endif /* !USE_VFS */
527 #endif /* HAVE_SUBSHELL_SUPPORT */
528 my_system (flags
, shell
, command
);
530 if (!(flags
& EXECUTE_INTERNAL
)) {
531 if ((pause_after_run
== pause_always
532 || (pause_after_run
== pause_on_dumb_terminals
&& !xterm_flag
533 && !console_flag
)) && !quit
534 #ifdef HAVE_SUBSHELL_SUPPORT
535 && subshell_state
!= RUNNING_COMMAND
536 #endif /* HAVE_SUBSHELL_SUPPORT */
538 printf ("%s\r\n", _("Press any key to continue..."));
545 if (output_lines
&& keybar_visible
) {
553 handle_console (CONSOLE_SAVE
);
554 edition_post_exec ();
556 #ifdef HAVE_SUBSHELL_SUPPORT
558 do_possible_cd (new_dir
);
560 #endif /* HAVE_SUBSHELL_SUPPORT */
564 mc_chdir (old_vfs_dir
);
565 g_free (old_vfs_dir
);
569 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
570 update_xterm_title_path ();
576 /* Executes a command */
578 shell_execute (char *command
, int flags
)
580 #ifdef HAVE_SUBSHELL_SUPPORT
582 if (subshell_state
== INACTIVE
)
583 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
585 message (1, MSG_ERROR
,
586 _(" The shell is already running a command "));
588 #endif /* HAVE_SUBSHELL_SUPPORT */
589 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
593 execute (char *command
)
595 shell_execute (command
, 0);
601 free_completions (cmdline
);
602 dlg_one_down (midnight_dlg
);
605 /* Stop MC main dialog and the current dialog if it exists.
606 * Needed to provide fast exit from MC viewer or editor on shell exit */
610 midnight_dlg
->running
= 0;
612 current_dlg
->running
= 0;
617 quit_cmd_internal (int quiet
)
621 if (quiet
|| !confirm_exit
) {
625 (_(" The Midnight Commander "),
626 _(" Do you really want to quit the Midnight Commander? "), 0,
627 2, _("&Yes"), _("&No")) == 0)
631 #ifdef HAVE_SUBSHELL_SUPPORT
634 else if ((q
= exit_subshell ()))
646 quit_cmd_internal (0);
650 quiet_quit_cmd (void)
652 print_last_revert
= 1;
653 quit_cmd_internal (1);
658 * Touch window and refresh window functions
661 /* This routine untouches the first line on both panels in order */
662 /* to avoid the refreshing the menu bar */
671 repaint_screen (void)
677 /* Wrapper for do_subshell_chdir, check for availability of subshell */
679 subshell_chdir (char *directory
)
681 #ifdef HAVE_SUBSHELL_SUPPORT
683 if (vfs_current_is_local ())
684 do_subshell_chdir (directory
, 0, 1);
686 #endif /* HAVE_SUBSHELL_SUPPORT */
690 directory_history_add (struct WPanel
*panel
, char *s
)
695 strip_password (s
, 1);
697 panel
->dir_history
= list_append_unique (panel
->dir_history
, text
);
701 * If we moved to the parent directory move the selection pointer to
702 * the old directory name; If we leave VFS dir, remove FS specificator.
703 * Warn: This code spoils lwd string.
705 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
708 get_parent_dir_name (char *cwd
, char *lwd
)
711 if (strlen (lwd
) > strlen (cwd
))
712 if ((p
= strrchr (lwd
, PATH_SEP
)) && !strncmp (cwd
, lwd
, p
- lwd
)) {
719 * Changes the current directory of the panel.
720 * Don't record change in the directory history.
723 _do_panel_cd (WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
725 char *directory
, *olddir
;
726 char temp
[MC_MAXPATHLEN
];
727 char *translated_url
;
731 struct vfs_stamping
*parent
;
733 olddir
= g_strdup (panel
->cwd
);
734 translated_url
= new_dir
= vfs_translate_url (new_dir
);
736 /* Convert *new_path to a suitable pathname, handle ~user */
738 if (cd_type
== cd_parse_command
) {
739 while (*new_dir
== ' ')
742 if (!strcmp (new_dir
, "-")) {
743 strcpy (temp
, panel
->lwd
);
747 directory
= *new_dir
? new_dir
: home_dir
;
749 if (mc_chdir (directory
) == -1) {
750 strcpy (panel
->cwd
, olddir
);
752 g_free (translated_url
);
755 g_free (translated_url
);
757 /* Success: save previous directory, shutdown status of previous dir */
758 strcpy (panel
->lwd
, olddir
);
759 free_completions (cmdline
);
761 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
764 oldvfs
= vfs_type (olddir
);
765 oldvfsid
= vfs_ncs_getid (oldvfs
, olddir
, &parent
);
766 vfs_add_noncurrent_stamps (oldvfs
, oldvfsid
, parent
);
767 vfs_rm_parents (parent
);
770 subshell_chdir (panel
->cwd
);
772 /* Reload current panel */
773 panel_clean_dir (panel
);
775 do_load_dir (&panel
->dir
, panel
->sort_type
, panel
->reverse
,
776 panel
->case_sensitive
, panel
->filter
);
777 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
779 panel_update_contents (panel
);
780 update_xterm_title_path ();
788 * Changes the current directory of the panel.
789 * Record change in the directory history.
792 do_panel_cd (struct WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
796 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
798 directory_history_add (panel
, panel
->cwd
);
803 do_cd (char *new_dir
, enum cd_enum exact
)
805 return (do_panel_cd (cpanel
, new_dir
, exact
));
809 directory_history_next (WPanel
*panel
)
813 nextdir
= g_list_next (panel
->dir_history
);
818 if (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
))
819 panel
->dir_history
= nextdir
;
823 directory_history_prev (WPanel
*panel
)
827 prevdir
= g_list_previous (panel
->dir_history
);
832 if (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
))
833 panel
->dir_history
= prevdir
;
837 directory_history_list (WPanel
*panel
)
841 if (!panel
->dir_history
)
844 s
= show_hist (panel
->dir_history
, panel
->widget
.x
, panel
->widget
.y
);
849 if (_do_panel_cd (panel
, s
, cd_exact
))
850 directory_history_add (panel
, panel
->cwd
);
852 message (1, MSG_ERROR
, _("Cannot change directory"));
856 #ifdef HAVE_SUBSHELL_SUPPORT
858 load_prompt (int fd
, void *unused
)
860 if (!read_subshell_prompt ())
863 /* Don't actually change the prompt if it's invisible */
864 if (current_dlg
== midnight_dlg
&& command_prompt
) {
867 prompt
= strip_ctrl_codes (subshell_prompt
);
868 prompt_len
= strlen (prompt
);
870 /* Check for prompts too big */
871 if (COLS
> 8 && prompt_len
> COLS
- 8) {
872 prompt
[COLS
- 8] = 0;
873 prompt_len
= COLS
- 8;
875 label_set_text (the_prompt
, prompt
);
876 winput_set_origin ((WInput
*) cmdline
, prompt_len
,
879 /* since the prompt has changed, and we are called from one of the
880 * get_event channels, the prompt updating does not take place
881 * automatically: force a cursor update and a screen refresh
883 update_cursor (midnight_dlg
);
889 #endif /* HAVE_SUBSHELL_SUPPORT */
891 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
893 maybe_cd (int char_code
, int move_up_dir
)
895 if (navigate_with_arrows
) {
896 if (!cmdline
->buffer
[0]) {
898 do_cd ("..", cd_exact
);
901 if (S_ISDIR (selection (cpanel
)->buf
.st_mode
)
902 || link_isdir (selection (cpanel
))) {
903 do_cd (selection (cpanel
)->fname
, cd_exact
);
917 if (!SELECTED_IS_PANEL
)
921 sort_order
= sort_box (p
->sort_type
, &p
->reverse
, &p
->case_sensitive
);
923 panel_set_sort_order (p
, sort_order
);
932 sel_dir
= tree_box (selection (cpanel
)->fname
);
934 do_cd (sel_dir
, cd_exact
);
939 #ifdef LISTMODE_EDITOR
944 newmode
= listmode_edit ("half <type,>name,|,size:8,|,perm:4+");
945 message (0, _(" Listing format edit "), _(" New mode is \"%s\" "),
949 #endif /* LISTMODE_EDITOR */
951 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
952 static menu_entry PanelMenu
[] = {
953 {' ', N_("&Listing mode..."), 'L', listing_cmd
},
954 {' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
955 {' ', N_("&Info C-x i"), 'I', info_cmd
},
956 {' ', N_("&Tree"), 'T', tree_cmd
},
958 {' ', N_("&Sort order..."), 'S', sort_cmd
},
960 {' ', N_("&Filter..."), 'F', filter_cmd
},
964 {' ', N_("&Network link..."), 'N', netlink_cmd
},
966 {' ', N_("FT&P link..."), 'P', ftplink_cmd
},
967 {' ', N_("S&hell link..."), 'H', fishlink_cmd
},
969 {' ', N_("SM&B link..."), 'B', smblink_cmd
},
974 {' ', N_("&Drive... M-d"), 'D', drive_cmd_a
},
976 {' ', N_("&Rescan C-r"), 'R', reread_cmd
}
979 static menu_entry RightMenu
[] = {
980 {' ', N_("&Listing mode..."), 'L', listing_cmd
},
981 {' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
982 {' ', N_("&Info C-x i"), 'I', info_cmd
},
983 {' ', N_("&Tree"), 'T', tree_cmd
},
985 {' ', N_("&Sort order..."), 'S', sort_cmd
},
987 {' ', N_("&Filter..."), 'F', filter_cmd
},
991 {' ', N_("&Network link..."), 'N', netlink_cmd
},
993 {' ', N_("FT&P link..."), 'P', ftplink_cmd
},
994 {' ', N_("S&hell link..."), 'H', fishlink_cmd
},
996 {' ', N_("SM&B link..."), 'B', smblink_cmd
},
1001 {' ', N_("&Drive... M-d"), 'D', drive_cmd_b
},
1003 {' ', N_("&Rescan C-r"), 'R', reread_cmd
}
1006 static menu_entry FileMenu
[] = {
1007 {' ', N_("&User menu F2"), 'U', user_file_menu_cmd
},
1008 {' ', N_("&View F3"), 'V', view_cmd
},
1009 {' ', N_("Vie&w file... "), 'W', view_file_cmd
},
1010 {' ', N_("&Filtered view M-!"), 'F', filtered_view_cmd
},
1011 {' ', N_("&Edit F4"), 'E', edit_cmd
},
1012 {' ', N_("&Copy F5"), 'C', copy_cmd
},
1013 {' ', N_("c&Hmod C-x c"), 'H', chmod_cmd
},
1014 #ifndef NATIVE_WIN32
1015 {' ', N_("&Link C-x l"), 'L', link_cmd
},
1016 {' ', N_("&SymLink C-x s"), 'S', symlink_cmd
},
1017 {' ', N_("edit s&Ymlink C-x C-s"), 'Y', edit_symlink_cmd
},
1018 {' ', N_("ch&Own C-x o"), 'O', chown_cmd
},
1019 {' ', N_("&Advanced chown "), 'A', chown_advanced_cmd
},
1021 {' ', N_("&Rename/Move F6"), 'R', ren_cmd
},
1022 {' ', N_("&Mkdir F7"), 'M', mkdir_cmd
},
1023 {' ', N_("&Delete F8"), 'D', delete_cmd
},
1024 {' ', N_("&Quick cd M-c"), 'Q', quick_cd_cmd
},
1026 {' ', N_("select &Group M-+"), 'G', select_cmd
},
1027 {' ', N_("u&Nselect group M-\\"), 'N', unselect_cmd
},
1028 {' ', N_("reverse selec&Tion M-*"), 'T', reverse_selection_cmd
},
1030 {' ', N_("e&Xit F10"), 'X', quit_cmd
}
1033 static menu_entry CmdMenu
[] = {
1034 /* I know, I'm lazy, but the tree widget when it's not running
1035 * as a panel still has some problems, I have not yet finished
1036 * the WTree widget port, sorry.
1038 {' ', N_("&Directory tree"), 'D', treebox_cmd
},
1039 {' ', N_("&Find file M-?"), 'F', find_cmd
},
1040 {' ', N_("s&Wap panels C-u"), 'W', swap_cmd
},
1041 {' ', N_("switch &Panels on/off C-o"), 'P', view_other_cmd
},
1042 {' ', N_("&Compare directories C-x d"), 'C', compare_dirs_cmd
},
1043 {' ', N_("e&Xternal panelize C-x !"), 'X', external_panelize
},
1044 {' ', N_("show directory s&Izes"), 'I', dirsizes_cmd
},
1046 {' ', N_("command &History"), 'H', history_cmd
},
1047 {' ', N_("di&Rectory hotlist C-\\"), 'R', quick_chdir_cmd
},
1049 {' ', N_("&Active VFS list C-x a"), 'A', reselect_vfs
},
1050 {' ', N_("Fr&ee VFSs now"), 'E', free_vfs_now
},
1052 #ifdef WITH_BACKGROUND
1053 {' ', N_("&Background jobs C-x j"), 'B', jobs_cmd
},
1056 #ifdef USE_EXT2FSLIB
1057 {' ', N_("&Undelete files (ext2fs only)"), 'U', undelete_cmd
},
1059 #ifdef LISTMODE_EDITOR
1060 {' ', N_("&Listing format edit"), 'L', listmode_cmd
},
1062 #if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
1065 {' ', N_("Edit &extension file"), 'E', ext_cmd
},
1066 {' ', N_("Edit &menu file"), 'M', edit_mc_menu_cmd
},
1067 #ifdef USE_INTERNAL_EDIT
1068 {' ', N_("Edit edi&tor menu file"), 'T', edit_user_menu_cmd
},
1069 {' ', N_("Edit &syntax file"), 'S', edit_syntax_cmd
}
1070 #endif /* USE_INTERNAL_EDIT */
1073 /* Must keep in sync with the constants in menu_cmd */
1074 static menu_entry OptMenu
[] = {
1075 {' ', N_("&Configuration..."), 'C', configure_box
},
1076 {' ', N_("&Layout..."), 'L', layout_cmd
},
1077 {' ', N_("c&Onfirmation..."), 'O', confirm_box
},
1078 {' ', N_("&Display bits..."), 'D', display_bits_box
},
1079 #ifndef NATIVE_WIN32
1080 {' ', N_("learn &Keys..."), 'K', learn_keys
},
1081 #endif /* !NATIVE_WIN32 */
1083 {' ', N_("&Virtual FS..."), 'V', configure_vfs
},
1084 #endif /* !USE_VFS */
1086 {' ', N_("&Save setup"), 'S', save_setup_cmd
}
1089 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
1091 static Menu
*MenuBar
[5];
1097 create_menu (horizontal_split
? _(" &Above ") : _(" &Left "),
1098 PanelMenu
, menu_entries (PanelMenu
),
1099 "[Left and Right Menus]");
1101 create_menu (_(" &File "), FileMenu
, menu_entries (FileMenu
),
1104 create_menu (_(" &Command "), CmdMenu
, menu_entries (CmdMenu
),
1107 create_menu (_(" &Options "), OptMenu
, menu_entries (OptMenu
),
1110 create_menu (horizontal_split
? _(" &Below ") : _(" &Right "),
1111 RightMenu
, menu_entries (PanelMenu
),
1112 "[Left and Right Menus]");
1120 for (i
= 0; i
< 5; i
++) {
1121 destroy_menu (MenuBar
[i
]);
1126 menu_last_selected_cmd (void)
1128 the_menubar
->active
= 1;
1129 the_menubar
->dropped
= drop_menus
;
1130 the_menubar
->previous_selection
= dlg_item_number (midnight_dlg
);
1131 dlg_select_widget (midnight_dlg
, the_menubar
);
1137 if (the_menubar
->active
)
1140 if (get_current_index () == 0)
1141 the_menubar
->selected
= 0;
1143 the_menubar
->selected
= 4;
1144 menu_last_selected_cmd ();
1147 /* Flag toggling functions */
1149 toggle_fast_reload (void)
1151 fast_reload
= !fast_reload
;
1152 if (fast_reload_w
== 0 && fast_reload
) {
1153 message (0, _(" Information "),
1155 (" Using the fast reload option may not reflect the exact \n"
1156 " directory contents. In this cases you'll need to do a \n"
1157 " manual reload of the directory. See the man page for \n"
1164 toggle_mix_all_files (void)
1166 mix_all_files
= !mix_all_files
;
1167 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1171 toggle_show_backup (void)
1173 show_backups
= !show_backups
;
1174 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1178 toggle_show_hidden (void)
1180 show_dot_files
= !show_dot_files
;
1181 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1185 * Just a hack for allowing url-like pathnames to be accepted from the
1189 translated_mc_chdir (char *dir
)
1193 newdir
= vfs_translate_url (dir
);
1199 create_panels (void)
1205 char original_dir
[1024];
1207 original_dir
[0] = 0;
1209 if (boot_current_is_left
) {
1212 current_mode
= startup_left_mode
;
1213 other_mode
= startup_right_mode
;
1217 current_mode
= startup_right_mode
;
1218 other_mode
= startup_left_mode
;
1220 /* Creates the left panel */
1223 /* Ok, user has specified two dirs, save the original one,
1224 * since we may not be able to chdir to the proper
1225 * second directory later
1227 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
1229 translated_mc_chdir (this_dir
);
1231 set_display_type (current_index
, current_mode
);
1233 /* The other panel */
1235 if (original_dir
[0])
1236 translated_mc_chdir (original_dir
);
1237 translated_mc_chdir (other_dir
);
1239 set_display_type (other_index
, other_mode
);
1241 if (startup_left_mode
== view_listing
) {
1242 current_panel
= left_panel
;
1245 current_panel
= right_panel
;
1247 current_panel
= left_panel
;
1250 /* Create the nice widgets */
1251 cmdline
= command_new (0, 0, 0);
1252 the_prompt
= label_new (0, 0, prompt
, NULL
);
1253 the_prompt
->transparent
= 1;
1254 the_bar
= buttonbar_new (keybar_visible
);
1256 the_hint
= label_new (0, 0, 0, NULL
);
1257 the_hint
->transparent
= 1;
1258 the_hint
->auto_adjust_cols
= 0;
1259 the_hint
->widget
.cols
= COLS
;
1261 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
, 5);
1265 copy_current_pathname (void)
1267 if (!command_prompt
)
1270 command_insert (cmdline
, cpanel
->cwd
, 0);
1271 if (cpanel
->cwd
[strlen (cpanel
->cwd
) - 1] != PATH_SEP
)
1272 command_insert (cmdline
, PATH_SEP_STR
, 0);
1276 copy_other_pathname (void)
1278 if (get_other_type () != view_listing
)
1281 if (!command_prompt
)
1284 command_insert (cmdline
, opanel
->cwd
, 0);
1285 if (cpanel
->cwd
[strlen (opanel
->cwd
) - 1] != PATH_SEP
)
1286 command_insert (cmdline
, PATH_SEP_STR
, 0);
1290 copy_readlink (WPanel
*panel
)
1292 if (!command_prompt
)
1294 if (S_ISLNK (selection (panel
)->buf
.st_mode
)) {
1295 char buffer
[MC_MAXPATHLEN
];
1297 concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1300 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
);
1304 command_insert (cmdline
, buffer
, 1);
1310 copy_current_readlink (void)
1312 copy_readlink (cpanel
);
1316 copy_other_readlink (void)
1318 if (get_other_type () != view_listing
)
1320 copy_readlink (opanel
);
1323 /* Insert the selected file name into the input line */
1325 copy_prog_name (void)
1328 if (!command_prompt
)
1331 if (get_current_type () == view_tree
) {
1332 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1333 tmp
= tree_selected_name (tree
);
1335 tmp
= selection (cpanel
)->fname
;
1337 command_insert (cmdline
, tmp
, 1);
1341 copy_tagged (WPanel
*panel
)
1345 if (!command_prompt
)
1347 input_disable_update (cmdline
);
1348 if (panel
->marked
) {
1349 for (i
= 0; i
< panel
->count
; i
++) {
1350 if (panel
->dir
.list
[i
].f
.marked
)
1351 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, 1);
1354 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
,
1357 input_enable_update (cmdline
);
1361 copy_current_tagged (void)
1363 copy_tagged (cpanel
);
1367 copy_other_tagged (void)
1369 if (get_other_type () != view_listing
)
1371 copy_tagged (opanel
);
1375 do_suspend_cmd (void)
1379 if (console_flag
&& !use_subshell
)
1384 struct sigaction sigtstp_action
;
1386 /* Make sure that the SIGTSTP below will suspend us directly,
1387 without calling ncurses' SIGTSTP handler; we *don't* want
1388 ncurses to redraw the screen immediately after the SIGCONT */
1389 sigaction (SIGTSTP
, &startup_handler
, &sigtstp_action
);
1391 kill (getpid (), SIGTSTP
);
1393 /* Restore previous SIGTSTP action */
1394 sigaction (SIGTSTP
, &sigtstp_action
, NULL
);
1396 #endif /* SIGTSTP */
1398 if (console_flag
&& !use_subshell
)
1399 handle_console (CONSOLE_SAVE
);
1401 edition_post_exec ();
1409 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1416 define_label (midnight_dlg
, 1, _("Help"), help_cmd
);
1417 define_label (midnight_dlg
, 2, _("Menu"), user_file_menu_cmd
);
1418 define_label (midnight_dlg
, 9, _("PullDn"), menu_cmd
);
1419 define_label (midnight_dlg
, 10, _("Quit"), quit_cmd
);
1422 static const key_map ctl_x_map
[] = {
1423 {XCTRL ('c'), quit_cmd
},
1424 {'d', compare_dirs_cmd
},
1426 {'a', reselect_vfs
},
1427 #endif /* USE_VFS */
1428 {'p', copy_current_pathname
},
1429 {XCTRL ('p'), copy_other_pathname
},
1430 {'t', copy_current_tagged
},
1431 {XCTRL ('t'), copy_other_tagged
},
1433 #ifndef NATIVE_WIN32
1435 {'r', copy_current_readlink
},
1436 {XCTRL ('r'), copy_other_readlink
},
1439 {XCTRL ('s'), edit_symlink_cmd
},
1440 #endif /* !NATIVE_WIN32 */
1441 {'i', info_cmd_no_menu
},
1442 {'q', quick_cmd_no_menu
},
1443 {'h', add2hotlist_cmd
},
1444 {'!', external_panelize
},
1445 #ifdef WITH_BACKGROUND
1447 #endif /* WITH_BACKGROUND */
1448 #ifdef HAVE_SETSOCKOPT
1449 {'%', source_routing
},
1450 #endif /* HAVE_SETSOCKOPT */
1454 static int ctl_x_map_enabled
= 0;
1457 ctl_x_cmd (int ignore
)
1459 ctl_x_map_enabled
= 1;
1467 static const key_map default_map
[] = {
1468 {KEY_F (19), menu_last_selected_cmd
},
1469 {KEY_F (20), (key_callback
) quiet_quit_cmd
},
1471 /* Copy useful information to the command line */
1472 {ALT ('a'), copy_current_pathname
},
1473 {ALT ('A'), copy_other_pathname
},
1475 {ALT ('c'), quick_cd_cmd
},
1477 /* To access the directory hotlist */
1478 {XCTRL ('\\'), quick_chdir_cmd
},
1481 {XCTRL ('z'), suspend_cmd
},
1483 /* The filtered view command */
1484 {ALT ('!'), filtered_view_cmd
},
1487 {ALT ('?'), find_cmd
},
1490 {XCTRL ('r'), reread_cmd
},
1492 /* Toggle listing between long, user defined and full formats */
1493 {ALT ('t'), toggle_listing_cmd
},
1496 {XCTRL ('u'), swap_cmd
},
1499 {XCTRL ('o'), view_other_cmd
},
1501 /* Control-X keybindings */
1502 {XCTRL ('x'), ctl_x_cmd
},
1504 /* Trap dlg's exit commands */
1505 {ESC_CHAR
, nothing
},
1506 {XCTRL ('c'), nothing
},
1507 {XCTRL ('g'), nothing
},
1512 setup_sigwinch (void)
1514 #if (defined(HAVE_SLANG) || (NCURSES_VERSION_MAJOR >= 4)) && \
1515 !defined(NATIVE_WIN32) && defined(SIGWINCH)
1516 struct sigaction act
, oact
;
1517 act
.sa_handler
= flag_winch
;
1518 sigemptyset (&act
.sa_mask
);
1521 act
.sa_flags
|= SA_RESTART
;
1523 sigaction (SIGWINCH
, &act
, &oact
);
1530 /* Call all the inits */
1533 * Don't restrict the output on the screen manager level,
1534 * the translation tables take care of it.
1536 #define full_eight_bits (1)
1537 #define eight_bit_clean (1)
1538 #endif /* !HAVE_CHARSET */
1541 meta (stdscr
, eight_bit_clean
);
1543 SLsmg_Display_Eight_Bit
= full_eight_bits
? 128 : 160;
1548 init_xterm_support (void)
1555 termvalue
= getenv ("TERM");
1556 if (!termvalue
|| !(*termvalue
)) {
1557 fputs (_("The TERM environment variable is unset!\n"), stderr
);
1561 /* Check mouse capabilities */
1563 term_entry
= SLtt_tigetent (termvalue
);
1564 xmouse_seq
= SLtt_tigetstr ("Km", &term_entry
);
1566 xmouse_seq
= tigetstr ("kmous");
1569 /* -1 means invalid capability, shouldn't happen, but let's make it 0 */
1570 if ((long) xmouse_seq
== -1) {
1574 if (strcmp (termvalue
, "cygwin") == 0) {
1576 use_mouse_p
= MOUSE_DISABLED
;
1579 if (force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
1580 || strncmp (termvalue
, "rxvt", 4) == 0
1581 || strcmp (termvalue
, "dtterm") == 0) {
1584 /* Default to the standard xterm sequence */
1586 xmouse_seq
= ESC_STR
"[M";
1589 /* Enable mouse unless explicitly disabled by --nomouse */
1590 if (use_mouse_p
!= MOUSE_DISABLED
) {
1591 use_mouse_p
= MOUSE_XTERM
;
1604 #ifdef HAVE_SUBSHELL_SUPPORT
1606 add_select_channel (subshell_pty
, load_prompt
, 0);
1607 #endif /* !HAVE_SUBSHELL_SUPPORT */
1611 if (baudrate () < 9600 || slow_terminal
) {
1618 setup_dummy_mc (const char *file
)
1620 char d
[MC_MAXPATHLEN
];
1622 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1626 /* Create a fake current_panel, this is needed because the
1627 * expand_format routine will use current panel.
1629 strcpy (cpanel
->cwd
, d
);
1630 cpanel
->selected
= 0;
1632 cpanel
->dir
.list
[0].fname
= (char *) file
;
1644 * We sync the profiles since the hotlist may have changed, while
1645 * we only change the setup data if we have the auto save feature set
1647 if (auto_save_setup
)
1648 save_setup (); /* does also call save_hotlist */
1652 vfs_add_current_stamps ();
1655 /* This should be called after destroy_dlg since panel widgets
1656 * save their state on the profiles
1659 done_mc_profile (void)
1661 if (!auto_save_setup
)
1662 profile_forget_profile (profile_name
);
1669 * Partly repaint the contents of the panels.
1670 * Ideally, all painting should be done in the panel's callback.
1671 * Since we are bypassing the standard widget library by forcing
1672 * the repaint, the cursor position needs to be preserved.
1675 make_panels_dirty (void)
1679 /* Preserve current cursor position */
1680 getyx (stdscr
, row
, col
);
1683 panel_update_contents (cpanel
);
1685 if ((get_other_type () == view_listing
) && opanel
->dirty
)
1686 panel_update_contents (opanel
);
1688 /* Restore cursor position */
1692 /* In Windows people want to actually type the '\' key frequently */
1694 # define check_key_backslash(x) 0
1696 # define check_key_backslash(x) ((x) == '\\')
1700 midnight_callback (struct Dlg_head
*h
, int id
, int msg
)
1703 static int first_pre_event
= 1;
1708 make_panels_dirty ();
1709 if (auto_menu
&& first_pre_event
) {
1710 user_file_menu_cmd ();
1712 first_pre_event
= 0;
1716 if (ctl_x_map_enabled
) {
1717 ctl_x_map_enabled
= 0;
1718 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1719 if (id
== ctl_x_map
[i
].key_code
) {
1720 (*ctl_x_map
[i
].fn
) (id
);
1725 /* FIXME: should handle all menu shortcuts before this point */
1726 if (the_menubar
->active
)
1729 if (id
== KEY_F (10)) {
1735 free_completions (cmdline
);
1737 if (id
== '\n' && cmdline
->buffer
[0]) {
1738 send_message ((Widget
*) cmdline
, WIDGET_KEY
, id
);
1742 /* Ctrl-Enter and Alt-Enter */
1743 if (((id
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n')
1744 && (id
& (KEY_M_CTRL
| KEY_M_ALT
))) {
1749 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1750 && !quote
&& !cpanel
->searching
) {
1751 if (!only_leading_plus_minus
) {
1752 /* Special treatement, since the input line will eat them */
1758 if (check_key_backslash (id
) || id
== '-') {
1764 reverse_selection_cmd ();
1767 } else if (command_prompt
&& !strlen (cmdline
->buffer
)) {
1768 /* Special treatement '+', '-', '\', '*' only when this is
1769 * first char on input line
1777 if (check_key_backslash (id
) || id
== '-') {
1783 reverse_selection_cmd ();
1790 case DLG_HOTKEY_HANDLED
:
1791 if (get_current_type () == view_listing
)
1792 cpanel
->searching
= 0;
1795 case DLG_UNHANDLED_KEY
:
1796 if (command_prompt
) {
1799 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, id
);
1803 if (ctl_x_map_enabled
) {
1804 ctl_x_map_enabled
= 0;
1805 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1806 if (id
== ctl_x_map
[i
].key_code
) {
1807 (*ctl_x_map
[i
].fn
) (id
);
1811 for (i
= 0; default_map
[i
].key_code
; i
++) {
1812 if (id
== default_map
[i
].key_code
) {
1813 (*default_map
[i
].fn
) (id
);
1818 return MSG_NOT_HANDLED
;
1820 /* We handle the special case of the output lines */
1822 attrset (SELECTED_COLOR
);
1823 if (console_flag
&& output_lines
)
1824 show_console_contents (output_start_y
,
1825 LINES
- output_lines
- keybar_visible
-
1826 1, LINES
- keybar_visible
- 1);
1830 return default_dlg_callback (h
, id
, msg
);
1833 #define xtoolkit_panel_setup()
1835 /* Show current directory in the xterm title */
1837 update_xterm_title_path (void)
1839 unsigned char *p
, *s
;
1841 if (xterm_flag
&& xterm_title
) {
1842 p
= s
= g_strdup (strip_home_and_password (cpanel
->cwd
));
1844 if (!is_printable (*s
))
1847 fprintf (stdout
, "\33]0;mc - %s\7", p
);
1854 * Load new hint and display it.
1855 * IF force is not 0, ignore the timeout.
1858 load_hint (int force
)
1862 if (!the_hint
->widget
.parent
)
1865 if (!message_visible
) {
1866 label_set_text (the_hint
, 0);
1870 if ((hint
= get_random_hint (force
))) {
1875 char text
[BUF_SMALL
];
1877 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"),
1884 setup_panels_and_run_mc (void)
1888 xtoolkit_panel_setup ();
1889 add_widget (midnight_dlg
, the_hint
);
1891 add_widget (midnight_dlg
, cmdline
);
1892 add_widget (midnight_dlg
, the_prompt
);
1893 add_widget (midnight_dlg
, the_bar
);
1895 if (boot_current_is_left
) {
1902 add_widget (midnight_dlg
, get_panel_widget (first
));
1903 add_widget (midnight_dlg
, get_panel_widget (second
));
1904 add_widget (midnight_dlg
, the_menubar
);
1908 /* Run the Midnight Commander if no file was specified in the command line */
1909 run_dlg (midnight_dlg
);
1912 /* result must be free'd (I think this should go in util.c) */
1914 prepend_cwd_on_local (char *filename
)
1919 if (vfs_file_is_local (filename
)) {
1920 if (*filename
== PATH_SEP
) /* an absolute pathname */
1921 return g_strdup (filename
);
1922 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1923 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1926 strcpy (d
+ l
, filename
);
1927 return canonicalize_pathname (d
);
1929 return g_strdup (filename
);
1933 mc_maybe_editor_or_viewer (void)
1937 if (!(view_one_file
|| edit_one_file
))
1940 /* Invoke the internal view/edit routine with:
1941 * the default processing and forcing the internal viewer/editor
1943 if (view_one_file
) {
1944 path
= prepend_cwd_on_local (view_one_file
);
1945 setup_dummy_mc (path
);
1946 view_file (path
, 0, 1);
1948 #ifdef USE_INTERNAL_EDIT
1950 path
= prepend_cwd_on_local ("");
1951 setup_dummy_mc (path
);
1952 edit (edit_one_file
, edit_one_file_start_line
);
1954 #endif /* USE_INTERNAL_EDIT */
1956 midnight_shutdown
= 1;
1961 /* Run the main dialog that occupies the whole screen */
1965 int midnight_colors
[4];
1967 midnight_colors
[0] = NORMAL_COLOR
; /* NORMALC */
1968 midnight_colors
[1] = REVERSE_COLOR
; /* FOCUSC */
1969 midnight_colors
[2] = INPUT_COLOR
; /* HOT_NORMALC */
1970 midnight_colors
[3] = NORMAL_COLOR
; /* HOT_FOCUSC */
1973 create_dlg (0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1974 "[main]", NULL
, DLG_HAS_MENUBAR
);
1976 /* Check if we were invoked as an editor or file viewer */
1977 if (mc_maybe_editor_or_viewer ())
1982 setup_panels_and_run_mc ();
1985 midnight_shutdown
= 1;
1987 /* destroy_dlg destroys even cpanel->cwd, so we have to save a copy :) */
1988 if (last_wd_file
&& vfs_current_is_local ()) {
1989 last_wd_string
= g_strdup (cpanel
->cwd
);
1993 destroy_dlg (midnight_dlg
);
1998 #if defined (NATIVE_WIN32)
1999 /* Windows NT code */
2004 SetConsoleTitle ("GNU Midnight Commander");
2006 shell
= getenv ("COMSPEC");
2007 if (!shell
|| !*shell
)
2008 shell
= get_default_shell ();
2010 /* Default opening mode for files is binary, not text (CR/LF translation) */
2015 mc_home
= get_mc_lib_dir ();
2018 /* Nothing to be done on Windows */
2020 sigchld_handler_no_subshell (int sig
)
2030 init_sigfatals (void)
2042 shell
= getenv ("SHELL");
2043 if (!shell
|| !*shell
)
2044 shell
= g_strdup (getpwuid (geteuid ())->pw_shell
);
2045 if (!shell
|| !*shell
)
2048 /* This is the directory, where MC was installed, on Unix this is DATADIR */
2049 /* and can be overriden by the MC_DATADIR environment variable */
2050 if ((mc_libdir
= getenv ("MC_DATADIR")) != NULL
) {
2051 mc_home
= g_strdup (mc_libdir
);
2053 mc_home
= g_strdup (DATADIR
);
2058 sigchld_handler_no_subshell (int sig
)
2066 /* COMMENT: if it were true that after the call to handle_console(..INIT)
2067 the value of console_flag never changed, we could simply not install
2068 this handler at all if (!console_flag && !use_subshell). */
2070 /* That comment is no longer true. We need to wait() on a sigchld
2071 handler (that's at least what the tarfs code expects currently). */
2073 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
2075 if (pid
== cons_saver_pid
) {
2077 if (WIFSTOPPED (status
)) {
2078 /* Someone has stopped cons.saver - restart it */
2079 kill (pid
, SIGCONT
);
2081 /* cons.saver has died - disable console saving */
2082 handle_console (CONSOLE_DONE
);
2086 #endif /* __linux__ */
2088 /* If we got here, some other child exited; ignore it */
2094 struct sigaction sigchld_action
;
2096 sigchld_action
.sa_handler
=
2097 #ifdef HAVE_SUBSHELL_SUPPORT
2098 use_subshell
? sigchld_handler
:
2099 #endif /* HAVE_SUBSHELL_SUPPORT */
2100 sigchld_handler_no_subshell
;
2102 sigemptyset (&sigchld_action
.sa_mask
);
2105 sigchld_action
.sa_flags
= SA_RESTART
;
2107 sigchld_action
.sa_flags
= 0;
2108 #endif /* !SA_RESTART */
2110 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1) {
2111 #ifdef HAVE_SUBSHELL_SUPPORT
2113 * This may happen on QNX Neutrino 6, where SA_RESTART
2114 * is defined but not implemented. Fallback to no subshell.
2117 #endif /* HAVE_SUBSHELL_SUPPORT */
2121 #endif /* NATIVE_WIN32, UNIX */
2124 print_mc_usage (poptContext ctx
, FILE *stream
)
2128 poptSetOtherOptionHelp (ctx
,
2129 _("[flags] [this_dir] [other_panel_dir]\n"));
2131 /* print help for options */
2132 leftColWidth
= poptPrintHelp (ctx
, stream
, 0);
2133 fprintf (stream
, " %-*s %s\n", leftColWidth
, _("+number"),
2134 _("Set initial line number for the internal editor"));
2137 "Please send any bug reports (including the output of `mc -V')\n"
2138 "to mc-devel@gnome.org\n"), stream
);
2143 print_color_usage (void)
2146 * FIXME: undocumented keywords: viewunderline, editnormal, editbold,
2147 * and editmarked. To preserve translations, lines should be split.
2149 /* TRANSLATORS: don't translate keywords and names of colors */
2151 ("--colors KEYWORD={FORE},{BACK}\n\n"
2152 "{FORE} and {BACK} can be omitted, and the default will be used\n"
2154 " Global: errors, reverse, gauge, input\n"
2155 " File display: normal, selected, marked, markselect\n"
2156 " Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus\n"
2157 " Menus: menu, menuhot, menusel, menuhotsel\n"
2158 " Help: helpnormal, helpitalic, helplink, helpslink\n"
2159 " File types: directory, executable, link, stalelink, device, special, core\n"
2161 " black, gray, red, brightred, green, brightgreen, brown,\n"
2162 " yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
2163 " brightcyan, lightgray and white\n\n"), stdout
);
2167 process_args (poptContext ctx
, int c
, const char *option_arg
)
2179 #endif /* HAVE_SLANG */
2183 printf ("%s\n", mc_home
);
2189 ftpfs_set_debug (option_arg
);
2191 smbfs_set_debugf (option_arg
);
2192 #endif /* WITH_SMBFS */
2197 smbfs_set_debug (atoi (option_arg
));
2199 #endif /* WITH_SMBFS */
2200 #endif /* USE_NETCODE */
2203 use_mouse_p
= MOUSE_DISABLED
;
2206 #ifdef HAVE_SUBSHELL_SUPPORT
2210 #endif /* HAVE_SUBSHELL_SUPPORT */
2213 print_color_usage ();
2218 print_mc_usage (ctx
, stdout
);
2223 static const struct poptOption argument_table
[] = {
2224 #ifdef WITH_BACKGROUND
2225 {"background", 'B', POPT_ARG_NONE
, &background_wait
, 0,
2226 N_("Use to debug the background code")},
2228 {"color", 'c', POPT_ARG_NONE
, NULL
, 'c',
2229 N_("Request to run in color mode")},
2230 {"colors", 'C', POPT_ARG_STRING
, &command_line_colors
, 0,
2231 N_("Specifies a color configuration")},
2233 #ifdef USE_INTERNAL_EDIT
2234 {"edit", 'e', POPT_ARG_STRING
, &edit_one_file
, 0,
2235 N_("Edits one file")},
2238 {"help", 'h', POPT_ARG_NONE
, NULL
, 'h',
2239 N_("Displays this help message")},
2240 {"help-colors", 'H', POPT_ARG_NONE
, NULL
, 'H',
2241 N_("Displays a help screen on how to change the color scheme")},
2243 {"ftplog", 'l', POPT_ARG_STRING
, NULL
, 'l',
2244 N_("Log ftp dialog to specified file")},
2246 {"debuglevel", 'D', POPT_ARG_STRING
, NULL
, 'D',
2247 N_("Set debug level")},
2250 {"datadir", 'f', POPT_ARG_NONE
, NULL
, 'f',
2251 N_("Print data directory")},
2252 {"nocolor", 'b', POPT_ARG_NONE
, &disable_colors
, 0,
2253 N_("Requests to run in black and white")},
2254 {"nomouse", 'd', POPT_ARG_NONE
, NULL
, 'd',
2255 N_("Disable mouse support in text version")},
2256 #ifdef HAVE_SUBSHELL_SUPPORT
2257 {"nosubshell", 'u', POPT_ARG_NONE
, NULL
, 'u',
2258 N_("Disables subshell support")},
2260 {"printwd", 'P', POPT_ARG_STRING
, &last_wd_file
, 0,
2261 N_("Print last working directory to specified file")},
2262 {"resetsoft", 'k', POPT_ARG_NONE
, &reset_hp_softkeys
, 0,
2263 N_("Resets soft keys on HP terminals")},
2264 {"slow", 's', POPT_ARG_NONE
, &slow_terminal
, 0,
2265 N_("To run on slow terminals")},
2266 #ifndef NATIVE_WIN32
2267 {"stickchars", 'a', 0, &force_ugly_line_drawing
, 0,
2268 N_("Use stickchars to draw")},
2269 #endif /* !NATIVE_WIN32 */
2270 #ifdef HAVE_SUBSHELL_SUPPORT
2271 {"subshell", 'U', POPT_ARG_NONE
, &use_subshell
, 0,
2272 N_("Enables subshell support (default)")},
2274 #if defined(HAVE_SLANG) && !defined(NATIVE_WIN32)
2275 {"termcap", 't', 0, &SLtt_Try_Termcap
, 0,
2276 N_("Tries to use termcap instead of terminfo")},
2278 {"version", 'V', POPT_ARG_NONE
, NULL
, 'V',
2279 N_("Displays the current version")},
2280 {"view", 'v', POPT_ARG_STRING
, &view_one_file
, 0,
2281 N_("Launches the file viewer on a file")},
2282 {"xterm", 'x', POPT_ARG_NONE
, &force_xterm
, 0,
2283 N_("Forces xterm features")},
2285 {NULL
, 0, 0, NULL
, 0}
2289 handle_args (int argc
, char *argv
[])
2297 poptGetContext ("mc", argc
, argv
, argument_table
,
2298 POPT_CONTEXT_NO_EXEC
);
2301 SLtt_Try_Termcap
= 1;
2304 while ((c
= poptGetNextOpt (ctx
)) > 0) {
2305 process_args (ctx
, c
, poptGetOptArg (ctx
));
2309 print_mc_usage (ctx
, stderr
);
2310 fprintf (stderr
, "%s: %s\n",
2311 poptBadOption (ctx
, POPT_BADOPTION_NOALIAS
),
2316 tmp
= poptGetArg (ctx
);
2319 * Check for special invocation names mcedit and mcview,
2320 * if none apply then set the current directory and the other
2321 * directory from the command line arguments
2323 base
= x_basename (argv
[0]);
2324 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP (base
, "vi")) {
2327 if (*tmp
== '+' && isdigit ((unsigned char) tmp
[1])) {
2328 int start_line
= atoi (tmp
);
2329 if (start_line
> 0) {
2330 char *file
= poptGetArg (ctx
);
2333 edit_one_file_start_line
= start_line
;
2337 edit_one_file
= g_strdup (tmp
);
2339 } else if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP (base
, "view")) {
2341 view_one_file
= g_strdup (tmp
);
2343 fputs ("No arguments given to the viewer\n", stderr
);
2347 /* sets the current dir and the other dir */
2349 this_dir
= g_strdup (tmp
);
2350 if ((tmp
= poptGetArg (ctx
)))
2351 other_dir
= g_strdup (tmp
);
2355 poptFreeContext (ctx
);
2359 * The compatibility_move_mc_files routine is intended to
2360 * move all of the hidden .mc files into a private ~/.mc
2361 * directory in the home directory, to avoid cluttering the users.
2363 * Previous versions of the program had all of their files in
2364 * the $HOME, we are now putting them in $HOME/.mc
2367 # define compatibility_move_mc_files() 0
2371 do_mc_filename_rename (char *mc_dir
, char *o_name
, char *n_name
)
2373 char *full_o_name
= concat_dir_and_file (home_dir
, o_name
);
2374 char *full_n_name
= g_strconcat (home_dir
, MC_BASE
, n_name
, NULL
);
2377 move
= 0 == rename (full_o_name
, full_n_name
);
2378 g_free (full_o_name
);
2379 g_free (full_n_name
);
2384 compatibility_move_mc_files (void)
2388 char *mc_dir
= concat_dir_and_file (home_dir
, ".mc");
2390 if (stat (mc_dir
, &s
) && (errno
== ENOENT
)
2391 && (mkdir (mc_dir
, 0777) != -1)) {
2393 move
= do_mc_filename_rename (mc_dir
, ".mc.ini", "ini");
2394 move
+= do_mc_filename_rename (mc_dir
, ".mc.hot", "hotlist");
2395 move
+= do_mc_filename_rename (mc_dir
, ".mc.ext", "bindings");
2396 move
+= do_mc_filename_rename (mc_dir
, ".mc.menu", "menu");
2397 move
+= do_mc_filename_rename (mc_dir
, ".mc.bashrc", "bashrc");
2398 move
+= do_mc_filename_rename (mc_dir
, ".mc.inputrc", "inputrc");
2399 move
+= do_mc_filename_rename (mc_dir
, ".mc.tcshrc", "tcshrc");
2400 move
+= do_mc_filename_rename (mc_dir
, ".mc.tree", "Tree");
2405 #endif /* NATIVE_WIN32 */
2408 main (int argc
, char *argv
[])
2410 /* if on, it displays the information that files have been moved to ~/.mc */
2411 int show_change_notice
= 0;
2413 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2414 setlocale (LC_ALL
, "");
2415 bindtextdomain ("mc", LOCALEDIR
);
2418 /* Initialize list of all user group for timur_clr_mode */
2421 /* Set up temporary directory */
2426 /* This variable is used by the subshell */
2427 home_dir
= getenv ("HOME");
2429 /* mc_home was computed by OS_Setup */
2436 SLtt_Ignore_Beep
= 1;
2439 /* NOTE: This has to be called before slang_init or whatever routine
2440 calls any define_sequence */
2443 handle_args (argc
, argv
);
2445 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
2446 handle_console (CONSOLE_INIT
);
2448 #ifdef HAVE_SUBSHELL_SUPPORT
2449 /* Don't use subshell when invoked as viewer or editor */
2450 if (edit_one_file
|| view_one_file
)
2454 subshell_get_console_attributes ();
2455 #endif /* HAVE_SUBSHELL_SUPPORT */
2457 /* Install the SIGCHLD handler; must be done before init_subshell() */
2460 show_change_notice
= compatibility_move_mc_files ();
2462 /* We need this, since ncurses endwin () doesn't restore the signals */
2463 save_stop_handler ();
2465 /* Must be done before init_subshell, to set up the terminal size: */
2466 /* FIXME: Should be removed and LINES and COLS computed on subshell */
2470 /* NOTE: This call has to be after slang_init. It's the small part from
2471 the previous init_key which had to be moved after the call of slang_init */
2472 init_key_input_fd ();
2478 init_xterm_support ();
2480 #ifdef HAVE_SUBSHELL_SUPPORT
2482 /* Done here to ensure that the subshell doesn't */
2483 /* inherit the file descriptors opened below, etc */
2487 #endif /* HAVE_SUBSHELL_SUPPORT */
2489 /* Removing this from the X code let's us type C-c */
2492 /* Also done after init_subshell, to save any shell init file messages */
2494 handle_console (CONSOLE_SAVE
);
2496 if (alternate_plus_minus
)
2497 application_keypad_mode ();
2499 if (show_change_notice
) {
2500 message (1, _(" Notice "),
2501 _(" The Midnight Commander configuration files \n"
2502 " are now stored in the ~/.mc directory, the \n"
2503 " files have been moved now\n"));
2505 #ifdef HAVE_SUBSHELL_SUPPORT
2507 prompt
= strip_ctrl_codes (subshell_prompt
);
2511 #endif /* HAVE_SUBSHELL_SUPPORT */
2512 prompt
= (geteuid () == 0) ? "# " : "$ ";
2514 /* Program main loop */
2515 if (!midnight_shutdown
)
2518 /* Save the tree store */
2521 /* Virtual File System shutdown */
2524 /* Delete list of all user groups */
2527 flush_extension_file (); /* does only free memory */
2534 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2536 if (alternate_plus_minus
)
2537 numeric_keypad_mode ();
2539 #ifndef NATIVE_WIN32
2540 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2544 handle_console (CONSOLE_DONE
);
2545 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2548 /* On NT, home_dir is malloced */
2551 if (last_wd_file
&& last_wd_string
&& !print_last_revert
2552 && !edit_one_file
&& !view_one_file
) {
2554 open (last_wd_file
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_EXCL
,
2557 if (last_wd_fd
!= -1) {
2558 write (last_wd_fd
, last_wd_string
, strlen (last_wd_string
));
2562 g_free (last_wd_string
);
2564 #ifndef NATIVE_WIN32
2566 #endif /* NATIVE_WIN32 */
2569 free_codepages_list ();