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 */
59 #include "cons.saver.h"
61 #include "key.h" /* For init_key() and mi_getch() */
62 #include "setup.h" /* save_setup() */
63 #include "profile.h" /* free_profiles() */
66 #include "cmd.h" /* Normal commands */
71 #include "background.h"
72 #include "ext.h" /* For flush_extension_file() */
74 /* Listbox for the command history feature */
78 #include "complete.h" /* For the free_completion */
87 #include "../vfs/vfs.h"
90 #include "../vfs/smbfs.h" /* smbfs_set_debug() */
95 #endif /* HAVE_CHARSET */
101 /* When the modes are active, left_panel, right_panel and tree_panel */
102 /* Point to a proper data structure. You should check with the functions */
103 /* get_current_type and get_other_type the types of the panels before using */
104 /* This pointer variables */
106 /* The structures for the panels */
110 /* The pointer to the tree */
116 /* Pointers to the selected and unselected panel */
117 WPanel
*current_panel
= NULL
;
119 /* Set when main loop should be terminated */
120 volatile int quit
= 0;
122 /* Set if you want the possible completions dialog for the first time */
123 int show_all_if_ambiguous
= 0;
125 /* Set when cd symlink following is desirable (bash mode) */
128 /* If set then dialogs just clean the screen when refreshing, else */
129 /* they do a complete refresh, refreshing all the parts of the program */
130 int fast_refresh
= 0;
132 /* If true, marking a files moves the cursor down */
133 int mark_moves_down
= 1;
135 /* If true, at startup the user-menu is invoked */
138 /* If true, use + and \ keys normally and select/unselect do if M-+ / M-\
139 and M-- and keypad + / - */
140 int alternate_plus_minus
= 0;
142 /* If true, then the +, - and \ keys have their special meaning only if the
143 * command line is emtpy, otherwise they behave like regular letters
145 int only_leading_plus_minus
= 1;
147 /* If true, after executing a command, wait for a keystroke */
148 enum { pause_never
, pause_on_dumb_terminals
, pause_always
};
150 int pause_after_run
= pause_on_dumb_terminals
;
152 /* It true saves the setup when quitting */
153 int auto_save_setup
= 1;
156 /* If true, be eight bit clean */
157 int eight_bit_clean
= 1;
159 /* If true, then display chars 0-255, else iso-8859-1,
160 requires eight_bit_clean */
161 int full_eight_bits
= 1;
162 #endif /* !HAVE_CHARSET */
164 /* If true use the internal viewer */
165 int use_internal_view
= 1;
167 /* Have we shown the fast-reload warning in the past? */
168 int fast_reload_w
= 0;
170 /* Move page/item? When clicking on the top or bottom of a panel */
171 int mouse_move_pages
= 1;
173 /* If true: l&r arrows are used to chdir if the input line is empty */
174 int navigate_with_arrows
= 0;
176 /* If true use +, -, | for line drawing */
177 int force_ugly_line_drawing
= 0;
179 /* If true message "The shell is already running a command" never */
180 int force_subshell_execution
= 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 true, then print on stdout the last directory we were at */
260 static int print_last_wd
= 0;
261 static char *last_wd_string
;
262 static int print_last_revert
= 0;
264 /* Force colors, only used by Slang */
265 int force_colors
= 0;
267 /* colors specified on the command line: they override any other setting */
268 char *command_line_colors
;
270 /* File name to view if argument was supplied */
271 char *view_one_file
= 0;
273 /* File name to edit if argument was supplied */
274 char *edit_one_file
= 0;
275 static int edit_one_file_start_line
= 1;
277 /* Used so that widgets know if they are being destroyed or
279 int midnight_shutdown
= 0;
281 /* to show nice prompts */
282 static int last_paused
= 0;
284 /* Used for keeping track of the original stdout */
287 /* The user's shell */
290 /* mc_home: The home of MC */
293 /* if on, it displays the information that files have been moved to ~/.mc */
294 int show_change_notice
= 0;
298 /* Used during argument processing */
299 int finish_program
= 0;
302 get_current_panel (void)
304 return current_panel
;
308 get_other_panel (void)
310 return (WPanel
*) get_panel_widget (get_other_index ());
314 reload_panelized (WPanel
*panel
)
317 dir_list
*list
= &panel
->dir
;
320 mc_chdir (panel
->cwd
);
322 for (i
= 0, j
= 0; i
< panel
->count
; i
++){
323 if (list
->list
[i
].f
.marked
) {
324 /* Unmark the file in advance. In case the following mc_lstat
325 * fails we are done, else we have to mark the file again
326 * (Note: do_file_mark depends on a valid "list->list [i].buf").
327 * IMO that's the best way to update the panel's summary status
330 do_file_mark (panel
, i
, 0);
332 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].buf
)){
333 g_free (list
->list
[i
].fname
);
336 if (list
->list
[i
].f
.marked
)
337 do_file_mark (panel
, i
, 1);
339 list
->list
[j
] = list
->list
[i
];
343 panel
->count
= set_zero_dir (list
);
348 mc_chdir (cpanel
->cwd
);
352 update_one_panel_widget (WPanel
*panel
, int force_update
, char *current_file
)
356 if (force_update
& UP_RELOAD
){
357 panel
->is_panelized
= 0;
362 /* FIXME: Should supply flushdir method */
363 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
366 /* If current_file == -1 (an invalid pointer) then preserve selection */
367 if (current_file
== UP_KEEPSEL
){
369 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
373 if (panel
->is_panelized
)
374 reload_panelized (panel
);
376 panel_reload (panel
);
378 try_to_select (panel
, current_file
);
382 g_free (current_file
);
386 panel_clean_dir (WPanel
*panel
)
388 int count
= panel
->count
;
394 panel
->dirs_marked
= 0;
396 panel
->searching
= 0;
397 panel
->is_panelized
= 0;
399 clean_dir (&panel
->dir
, count
);
403 update_one_panel (int which
, int force_update
, char *current_file
)
407 if (get_display_type (which
) != view_listing
)
410 panel
= (WPanel
*) get_panel_widget (which
);
411 update_one_panel_widget (panel
, force_update
, current_file
);
414 /* This routine reloads the directory in both panels. It tries to
415 * select current_file in current_panel and other_file in other_panel.
416 * If current_file == -1 then it automatically sets current_file and
417 * other_file to the currently selected files in the panels.
419 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
420 * will not reload the other panel.
423 update_panels (int force_update
, char *current_file
)
425 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
428 update_one_panel (get_current_index (), force_update
, current_file
);
430 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
432 if (get_current_type () == view_listing
)
433 panel
= (WPanel
*) get_panel_widget (get_current_index ());
435 panel
= (WPanel
*) get_panel_widget (get_other_index ());
437 mc_chdir (panel
->cwd
);
440 /* Sets up the terminal before executing a program */
448 /* Save current stat of directories to avoid reloading the panels */
449 /* when no modifications have taken place */
451 save_cwds_stat (void)
454 mc_stat (cpanel
->cwd
, &(cpanel
->dir_stat
));
455 if (get_other_type () == view_listing
)
456 mc_stat (opanel
->cwd
, &(opanel
->dir_stat
));
460 #ifdef HAVE_SUBSHELL_SUPPORT
462 do_possible_cd (char *new_dir
)
464 if (!do_cd (new_dir
, cd_exact
))
465 message (1, _(" Warning "),
466 _(" The Commander can't change to the directory that \n"
467 " the subshell claims you are in. Perhaps you have \n"
468 " deleted your working directory, or given yourself \n"
469 " extra access permissions with the \"su\" command? "));
473 do_update_prompt (void)
476 printf ("%s", subshell_prompt
);
481 #endif /* HAVE_SUBSHELL_SUPPORT */
484 restore_console (void)
486 handle_console (CONSOLE_RESTORE
);
492 do_execute (shell
, 0, 0);
496 do_execute (const char *shell
, const char *command
, int flags
)
498 #ifdef HAVE_SUBSHELL_SUPPORT
499 char *new_dir
= NULL
;
500 #endif /* HAVE_SUBSHELL_SUPPORT */
503 char *old_vfs_dir
= 0;
505 if (!vfs_current_is_local ())
506 old_vfs_dir
= g_strdup (vfs_get_current_dir ());
514 if (!use_subshell
&& !(flags
& EXECUTE_INTERNAL
&& command
)) {
515 printf ("%s%s%s\n", last_paused
? "\r\n":"", prompt
, command
);
519 #ifdef HAVE_SUBSHELL_SUPPORT
520 if (use_subshell
&& !(flags
& EXECUTE_INTERNAL
)){
523 /* We don't care if it died, higher level takes care of this */
525 invoke_subshell (command
, VISIBLY
, old_vfs_dir
? 0 : &new_dir
);
527 invoke_subshell (command
, VISIBLY
, &new_dir
);
528 #endif /* !USE_VFS */
530 #endif /* HAVE_SUBSHELL_SUPPORT */
531 my_system (flags
, shell
, command
);
533 if (!(flags
& EXECUTE_INTERNAL
)) {
534 if ((pause_after_run
== pause_always
||
535 (pause_after_run
== pause_on_dumb_terminals
&&
536 !xterm_flag
&& !console_flag
)) && !quit
537 #ifdef HAVE_SUBSHELL_SUPPORT
538 && subshell_state
!= RUNNING_COMMAND
539 #endif /* HAVE_SUBSHELL_SUPPORT */
541 printf ("%s\r\n", _("Press any key to continue..."));
548 if (output_lines
&& keybar_visible
) {
556 handle_console (CONSOLE_SAVE
);
557 edition_post_exec ();
559 #ifdef HAVE_SUBSHELL_SUPPORT
561 do_possible_cd (new_dir
);
563 #endif /* HAVE_SUBSHELL_SUPPORT */
567 mc_chdir (old_vfs_dir
);
568 g_free (old_vfs_dir
);
572 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
578 /* Executes a command */
580 shell_execute (char *command
, int flags
)
582 #ifdef HAVE_SUBSHELL_SUPPORT
584 if (subshell_state
== INACTIVE
|| force_subshell_execution
)
585 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
587 message (1, MSG_ERROR
, _(" The shell is already running a command "));
589 #endif /* HAVE_SUBSHELL_SUPPORT */
590 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
594 execute (char *command
)
596 shell_execute (command
, 0);
602 free_completions (cmdline
);
603 dlg_one_down (midnight_dlg
);
606 /* Stop MC main dialog and the current dialog if it exists.
607 * Needed to provide fast exit from MC viewer or editor on shell exit */
608 static void stop_dialogs (void)
610 midnight_dlg
->running
= 0;
612 current_dlg
->running
= 0;
617 quit_cmd_internal (int quiet
)
621 if (quiet
|| !confirm_exit
){
624 if (query_dialog (_(" The Midnight Commander "),
625 _(" Do you really want to quit the Midnight Commander? "),
626 0, 2, _("&Yes"), _("&No")) == 0)
630 #ifdef HAVE_SUBSHELL_SUPPORT
634 if ((q
= exit_subshell ()))
645 quit_cmd_internal (0);
649 int quiet_quit_cmd (void)
651 print_last_revert
= 1;
652 quit_cmd_internal (1);
657 * Touch window and refresh window functions
660 /* This routine untouches the first line on both panels in order */
661 /* to avoid the refreshing the menu bar */
670 repaint_screen (void)
676 /* Wrapper for do_subshell_chdir, check for availability of subshell */
678 subshell_chdir (char *directory
)
680 #ifdef HAVE_SUBSHELL_SUPPORT
682 if (vfs_current_is_local ())
683 do_subshell_chdir (directory
, 0, 1);
685 #endif /* HAVE_SUBSHELL_SUPPORT */
689 directory_history_add (WPanel
* panel
, char *s
)
691 if (!panel
->dir_history
) {
692 panel
->dir_history
= g_new0 (Hist
, 1);
693 panel
->dir_history
->text
= g_strdup (s
);
694 strip_password (panel
->dir_history
->text
, 1);
697 if (!strcmp (panel
->dir_history
->text
, s
))
699 if (panel
->dir_history
->next
) {
700 if (panel
->dir_history
->next
->text
) {
701 g_free (panel
->dir_history
->next
->text
);
702 panel
->dir_history
->next
->text
= 0;
705 panel
->dir_history
->next
= g_new0 (Hist
, 1);
706 panel
->dir_history
->next
->prev
= panel
->dir_history
;
708 panel
->dir_history
= panel
->dir_history
->next
;
709 panel
->dir_history
->text
= g_strdup (s
);
710 strip_password (panel
->dir_history
->text
, 1);
714 * If we moved to the parent directory move the selection pointer to
715 * the old directory name; If we leave VFS dir, remove FS specificator.
716 * Warn: This code spoils lwd string.
718 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
721 get_parent_dir_name (char *cwd
, char *lwd
)
724 if (strlen (lwd
) > strlen (cwd
))
725 if((p
=strrchr(lwd
, PATH_SEP
)) && !strncmp(cwd
, lwd
, p
-lwd
)){
731 /* Changes the current panel directory */
733 _do_panel_cd (WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
735 char *directory
, *olddir
;
736 char temp
[MC_MAXPATHLEN
];
737 char *translated_url
;
741 struct vfs_stamping
*parent
;
743 olddir
= g_strdup (panel
->cwd
);
744 translated_url
= new_dir
= vfs_translate_url (new_dir
);
746 /* Convert *new_path to a suitable pathname, handle ~user */
748 if (cd_type
== cd_parse_command
){
749 while (*new_dir
== ' ')
752 if (!strcmp (new_dir
, "-")){
753 strcpy (temp
, panel
->lwd
);
757 directory
= *new_dir
? new_dir
: home_dir
;
759 if (mc_chdir (directory
) == -1){
760 strcpy (panel
->cwd
, olddir
);
762 g_free (translated_url
);
765 g_free (translated_url
);
767 /* Success: save previous directory, shutdown status of previous dir */
768 strcpy (panel
->lwd
, olddir
);
769 free_completions (cmdline
);
771 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
774 oldvfs
= vfs_type (olddir
);
775 oldvfsid
= vfs_ncs_getid (oldvfs
, olddir
, &parent
);
776 vfs_add_noncurrent_stamps (oldvfs
, oldvfsid
, parent
);
777 vfs_rm_parents (parent
);
780 subshell_chdir (panel
->cwd
);
782 /* Reload current panel */
783 panel_clean_dir (panel
);
784 panel
->count
= do_load_dir (&panel
->dir
, panel
->sort_type
,
785 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
786 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
788 panel_update_contents (panel
);
796 do_panel_cd (WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
800 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
802 directory_history_add (cpanel
, cpanel
->cwd
);
807 do_cd (char *new_dir
, enum cd_enum exact
)
809 return (do_panel_cd (cpanel
, new_dir
, exact
));
813 directory_history_next (WPanel
* panel
)
815 if (!panel
->dir_history
->next
)
817 if (_do_panel_cd (panel
, panel
->dir_history
->next
->text
, cd_exact
))
818 panel
->dir_history
= panel
->dir_history
->next
;
822 directory_history_prev (WPanel
* panel
)
824 if (!panel
->dir_history
->prev
)
826 if (_do_panel_cd (panel
, panel
->dir_history
->prev
->text
, cd_exact
))
827 panel
->dir_history
= panel
->dir_history
->prev
;
831 directory_history_list (WPanel
* panel
)
834 /* must be at least two to show a history */
835 if (panel
->dir_history
) {
836 if (panel
->dir_history
->prev
|| panel
->dir_history
->next
) {
837 s
= show_hist (panel
->dir_history
, panel
->widget
.x
, panel
->widget
.y
);
840 r
= _do_panel_cd (panel
, s
, cd_exact
);
842 directory_history_add (panel
, panel
->cwd
);
844 message (1, MSG_ERROR
, _("Could not change directory") );
851 #ifdef HAVE_SUBSHELL_SUPPORT
853 load_prompt (int fd
, void *unused
)
855 if (!read_subshell_prompt ())
858 /* Don't actually change the prompt if it's invisible */
859 if (current_dlg
== midnight_dlg
&& command_prompt
){
862 prompt
= strip_ctrl_codes (subshell_prompt
);
863 prompt_len
= strlen (prompt
);
865 /* Check for prompts too big */
866 if (COLS
> 8 && prompt_len
> COLS
- 8) {
867 prompt
[COLS
- 8 ] = 0;
868 prompt_len
= COLS
- 8;
870 label_set_text (the_prompt
, prompt
);
871 winput_set_origin ((WInput
*)cmdline
, prompt_len
, COLS
-prompt_len
);
873 /* since the prompt has changed, and we are called from one of the
874 * get_event channels, the prompt updating does not take place
875 * automatically: force a cursor update and a screen refresh
877 update_cursor (midnight_dlg
);
883 #endif /* HAVE_SUBSHELL_SUPPORT */
885 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
887 maybe_cd (int char_code
, int move_up_dir
)
889 if (navigate_with_arrows
){
890 if (!cmdline
->buffer
[0]){
892 do_cd ("..", cd_exact
);
895 if (S_ISDIR (selection (cpanel
)->buf
.st_mode
)
896 || link_isdir (selection (cpanel
))){
897 do_cd (selection (cpanel
)->fname
, cd_exact
);
911 if (!SELECTED_IS_PANEL
)
915 sort_order
= sort_box (p
->sort_type
, &p
->reverse
, &p
->case_sensitive
);
917 panel_set_sort_order (p
, sort_order
);
926 sel_dir
= tree_box (selection (cpanel
)->fname
);
928 do_cd(sel_dir
, cd_exact
);
933 #ifdef LISTMODE_EDITOR
938 newmode
= listmode_edit ("half <type,>name,|,size:8,|,perm:4+");
939 message (0, _(" Listing format edit "), _(" New mode is \"%s\" "), newmode
);
942 #endif /* LISTMODE_EDITOR */
944 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
945 static menu_entry PanelMenu
[] = {
946 { ' ', N_("&Listing mode..."), 'L', listing_cmd
},
947 { ' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
948 { ' ', N_("&Info C-x i"), 'I', info_cmd
},
949 { ' ', N_("&Tree"), 'T', tree_cmd
},
951 { ' ', N_("&Sort order..."), 'S', sort_cmd
},
953 { ' ', N_("&Filter..."), 'F', filter_cmd
},
957 { ' ', N_("&Network link..."), 'N', netlink_cmd
},
959 { ' ', N_("FT&P link..."), 'P', ftplink_cmd
},
960 { ' ', N_("S&hell link..."), 'H', fishlink_cmd
},
962 { ' ', N_("SM&B link..."), 'B', smblink_cmd
},
967 { ' ', N_("&Drive... M-d"), 'D', drive_cmd_a
},
969 { ' ', N_("&Rescan C-r"), 'R', reread_cmd
}
972 static menu_entry RightMenu
[] = {
973 { ' ', N_("&Listing mode..."), 'L', listing_cmd
},
974 { ' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
975 { ' ', N_("&Info C-x i"), 'I', info_cmd
},
976 { ' ', N_("&Tree"), 'T', tree_cmd
},
978 { ' ', N_("&Sort order..."), 'S', sort_cmd
},
980 { ' ', N_("&Filter..."), 'F', filter_cmd
},
984 { ' ', N_("&Network link..."), 'N', netlink_cmd
},
986 { ' ', N_("FT&P link..."), 'P', ftplink_cmd
},
987 { ' ', N_("S&hell link..."), 'H', fishlink_cmd
},
989 { ' ', N_("SM&B link..."), 'B', smblink_cmd
},
994 { ' ', N_("&Drive... M-d"), 'D', drive_cmd_b
},
996 { ' ', N_("&Rescan C-r"), 'R', reread_cmd
}
999 static menu_entry FileMenu
[] = {
1000 { ' ', N_("&User menu F2"), 'U', user_file_menu_cmd
},
1001 { ' ', N_("&View F3"), 'V', view_cmd
},
1002 { ' ', N_("Vie&w file... "), 'W', view_file_cmd
},
1003 { ' ', N_("&Filtered view M-!"), 'F', filtered_view_cmd
},
1004 { ' ', N_("&Edit F4"), 'E', edit_cmd
},
1005 { ' ', N_("&Copy F5"), 'C', copy_cmd
},
1006 { ' ', N_("c&Hmod C-x c"), 'H', chmod_cmd
},
1007 #ifndef NATIVE_WIN32
1008 { ' ', N_("&Link C-x l"), 'L', link_cmd
},
1009 { ' ', N_("&SymLink C-x s"), 'S', symlink_cmd
},
1010 { ' ', N_("edit s&Ymlink C-x C-s"), 'Y', edit_symlink_cmd
},
1011 { ' ', N_("ch&Own C-x o"), 'O', chown_cmd
},
1012 { ' ', N_("&Advanced chown "), 'A', chown_advanced_cmd
},
1014 { ' ', N_("&Rename/Move F6"), 'R', ren_cmd
},
1015 { ' ', N_("&Mkdir F7"), 'M', mkdir_cmd
},
1016 { ' ', N_("&Delete F8"), 'D', delete_cmd
},
1017 { ' ', N_("&Quick cd M-c"), 'Q', quick_cd_cmd
},
1018 { ' ', "", ' ', 0 },
1019 { ' ', N_("select &Group M-+"), 'G', select_cmd
},
1020 { ' ', N_("u&Nselect group M-\\"),'N', unselect_cmd
},
1021 { ' ', N_("reverse selec&Tion M-*"), 'T', reverse_selection_cmd
},
1022 { ' ', "", ' ', 0 },
1023 { ' ', N_("e&Xit F10"), 'X', (callfn
) quit_cmd
}
1026 static menu_entry CmdMenu
[] = {
1027 /* I know, I'm lazy, but the tree widget when it's not running
1028 * as a panel still has some problems, I have not yet finished
1029 * the WTree widget port, sorry.
1031 { ' ', N_("&Directory tree"), 'D', treebox_cmd
},
1032 { ' ', N_("&Find file M-?"), 'F', find_cmd
},
1033 { ' ', N_("s&Wap panels C-u"), 'W', swap_cmd
},
1034 { ' ', N_("switch &Panels on/off C-o"), 'P', view_other_cmd
},
1035 { ' ', N_("&Compare directories C-x d"), 'C', compare_dirs_cmd
},
1036 { ' ', N_("e&Xternal panelize C-x !"), 'X', external_panelize
},
1037 { ' ', N_("show directory s&Izes"), 'I', dirsizes_cmd
},
1038 { ' ', "", ' ', 0 },
1039 { ' ', N_("command &History"), 'H', history_cmd
},
1040 { ' ', N_("di&Rectory hotlist C-\\"), 'R', quick_chdir_cmd
},
1042 { ' ', N_("&Active VFS list C-x a"), 'A', reselect_vfs
},
1043 { ' ', N_("Fr&ee VFSs now"), 'E', free_vfs_now
},
1045 #ifdef WITH_BACKGROUND
1046 { ' ', N_("&Background jobs C-x j"), 'B', jobs_cmd
},
1048 { ' ', "", ' ', 0 },
1049 #ifdef USE_EXT2FSLIB
1050 { ' ', N_("&Undelete files (ext2fs only)"), 'U', undelete_cmd
},
1052 #ifdef LISTMODE_EDITOR
1053 { ' ', N_("&Listing format edit"), 'L', listmode_cmd
},
1055 #if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
1056 { ' ', "", ' ', 0 },
1058 { ' ', N_("&Extension file edit"), 'E', ext_cmd
},
1059 { ' ', N_("&Menu file edit"), 'M', menu_edit_cmd
},
1060 #ifdef USE_INTERNAL_EDIT
1061 {' ', N_("Menu edi&Tor edit"), 'T', edit_user_menu_cmd
},
1062 {' ', N_("&Syntax file edit"), 'S', edit_syntax_cmd
}
1063 #endif /* USE_INTERNAL_EDIT */
1066 /* Must keep in sync with the constants in menu_cmd */
1067 static menu_entry OptMenu
[] = {
1068 { ' ', N_("&Configuration..."), 'C', configure_box
},
1069 { ' ', N_("&Layout..."), 'L', layout_cmd
},
1070 { ' ', N_("c&Onfirmation..."), 'O', confirm_box
},
1071 { ' ', N_("&Display bits..."), 'D', display_bits_box
},
1072 #ifndef NATIVE_WIN32
1073 { ' ', N_("learn &Keys..."), 'K', learn_keys
},
1074 #endif /* !NATIVE_WIN32 */
1076 { ' ', N_("&Virtual FS..."), 'V', configure_vfs
},
1077 #endif /* !USE_VFS */
1078 { ' ', "", ' ', 0 },
1079 { ' ', N_("&Save setup"), 'S', save_setup_cmd
}
1082 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
1084 static Menu MenuBar
[5];
1089 MenuBar
[0] = create_menu ( horizontal_split
? _(" &Above ") : _(" &Left "),
1090 PanelMenu
, menu_entries (PanelMenu
),
1091 "[Left and Right Menus]");
1092 MenuBar
[1] = create_menu (_(" &File "), FileMenu
, menu_entries (FileMenu
),
1094 MenuBar
[2] = create_menu (_(" &Command "), CmdMenu
, menu_entries (CmdMenu
),
1096 MenuBar
[3] = create_menu (_(" &Options "), OptMenu
, menu_entries (OptMenu
),
1098 MenuBar
[4] = create_menu (horizontal_split
? _(" &Below ") : _(" &Right "),
1099 RightMenu
, menu_entries (PanelMenu
),
1100 "[Left and Right Menus]");
1108 for (i
= 0; i
< 5; i
++){
1109 destroy_menu (MenuBar
[i
]);
1114 menu_last_selected_cmd (void)
1116 the_menubar
->active
= 1;
1117 the_menubar
->dropped
= drop_menus
;
1118 the_menubar
->previous_selection
= dlg_item_number (midnight_dlg
);
1119 dlg_select_widget (midnight_dlg
, the_menubar
);
1125 if (the_menubar
->active
)
1128 if (get_current_index () == 0)
1129 the_menubar
->selected
= 0;
1131 the_menubar
->selected
= 4;
1132 menu_last_selected_cmd ();
1135 /* Flag toggling functions */
1137 toggle_fast_reload (void)
1139 fast_reload
= !fast_reload
;
1140 if (fast_reload_w
== 0 && fast_reload
){
1141 message (0, _(" Information "),
1142 _(" Using the fast reload option may not reflect the exact \n"
1143 " directory contents. In this cases you'll need to do a \n"
1144 " manual reload of the directory. See the man page for \n"
1151 toggle_mix_all_files (void)
1153 mix_all_files
= !mix_all_files
;
1154 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1158 toggle_show_backup (void)
1160 show_backups
= !show_backups
;
1161 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1165 toggle_show_hidden (void)
1167 show_dot_files
= !show_dot_files
;
1168 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1172 * Just a hack for allowing url-like pathnames to be accepted from the
1176 translated_mc_chdir (char *dir
)
1180 newdir
= vfs_translate_url (dir
);
1186 create_panels (void)
1192 char original_dir
[1024];
1194 original_dir
[0] = 0;
1196 if (boot_current_is_left
){
1199 current_mode
= startup_left_mode
;
1200 other_mode
= startup_right_mode
;
1204 current_mode
= startup_right_mode
;
1205 other_mode
= startup_left_mode
;
1207 /* Creates the left panel */
1210 /* Ok, user has specified two dirs, save the original one,
1211 * since we may not be able to chdir to the proper
1212 * second directory later
1214 mc_get_current_wd (original_dir
, sizeof (original_dir
)-2);
1216 translated_mc_chdir (this_dir
);
1218 set_display_type (current_index
, current_mode
);
1220 /* The other panel */
1222 if (original_dir
[0])
1223 translated_mc_chdir (original_dir
);
1224 translated_mc_chdir (other_dir
);
1226 set_display_type (other_index
, other_mode
);
1228 if (startup_left_mode
== view_listing
){
1229 current_panel
= left_panel
;
1232 current_panel
= right_panel
;
1234 current_panel
= left_panel
;
1237 /* Create the nice widgets */
1238 cmdline
= command_new (0, 0, 0);
1239 the_prompt
= label_new (0, 0, prompt
, NULL
);
1240 the_prompt
->transparent
= 1;
1241 the_bar
= buttonbar_new (keybar_visible
);
1243 the_hint
= label_new (0, 0, 0, NULL
);
1244 the_hint
->transparent
= 1;
1245 the_hint
->auto_adjust_cols
= 0;
1246 the_hint
->widget
.cols
= COLS
;
1248 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
, 5);
1251 static void copy_current_pathname (void)
1253 if (!command_prompt
)
1256 command_insert (cmdline
, cpanel
->cwd
, 0);
1257 if (cpanel
->cwd
[strlen (cpanel
->cwd
) - 1] != PATH_SEP
)
1258 command_insert (cmdline
, PATH_SEP_STR
, 0);
1261 static void copy_other_pathname (void)
1263 if (get_other_type () != view_listing
)
1266 if (!command_prompt
)
1269 command_insert (cmdline
, opanel
->cwd
, 0);
1270 if (cpanel
->cwd
[strlen (opanel
->cwd
) - 1] != PATH_SEP
)
1271 command_insert (cmdline
, PATH_SEP_STR
, 0);
1274 static void copy_readlink (WPanel
*panel
)
1276 if (!command_prompt
)
1278 if (S_ISLNK (selection (panel
)->buf
.st_mode
)) {
1279 char buffer
[MC_MAXPATHLEN
];
1280 char *p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1283 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
);
1287 command_insert (cmdline
, buffer
, 1);
1292 static void copy_current_readlink (void)
1294 copy_readlink (cpanel
);
1297 static void copy_other_readlink (void)
1299 if (get_other_type () != view_listing
)
1301 copy_readlink (opanel
);
1304 /* Inserts the selected file name into the input line */
1305 /* Exported so that the command modules uses it */
1306 void copy_prog_name (void)
1309 if (!command_prompt
)
1312 if (get_current_type () == view_tree
){
1313 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1314 tmp
= tree
->selected_ptr
->name
;
1316 tmp
= selection (cpanel
)->fname
;
1318 command_insert (cmdline
, tmp
, 1);
1322 copy_tagged (WPanel
* panel
)
1326 if (!command_prompt
)
1328 input_disable_update (cmdline
);
1329 if (panel
->marked
) {
1330 for (i
= 0; i
< panel
->count
; i
++) {
1331 if (panel
->dir
.list
[i
].f
.marked
)
1332 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, 1);
1335 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
,
1338 input_enable_update (cmdline
);
1341 static void copy_current_tagged (void)
1343 copy_tagged (cpanel
);
1346 static void copy_other_tagged (void)
1348 if (get_other_type () != view_listing
)
1350 copy_tagged (opanel
);
1353 static void do_suspend_cmd (void)
1357 if (console_flag
&& !use_subshell
)
1362 struct sigaction sigtstp_action
;
1364 /* Make sure that the SIGTSTP below will suspend us directly,
1365 without calling ncurses' SIGTSTP handler; we *don't* want
1366 ncurses to redraw the screen immediately after the SIGCONT */
1367 sigaction (SIGTSTP
, &startup_handler
, &sigtstp_action
);
1369 kill (getpid (), SIGTSTP
);
1371 /* Restore previous SIGTSTP action */
1372 sigaction (SIGTSTP
, &sigtstp_action
, NULL
);
1374 #endif /* SIGTSTP */
1376 if (console_flag
&& !use_subshell
)
1377 handle_console (CONSOLE_SAVE
);
1379 edition_post_exec ();
1387 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1392 init_labels (Widget
*paneletc
)
1394 define_label (midnight_dlg
, paneletc
, 1, _("Help"), help_cmd
);
1395 define_label (midnight_dlg
, paneletc
, 2, _("Menu"), user_file_menu_cmd
);
1396 define_label (midnight_dlg
, paneletc
, 9, _("PullDn"), menu_cmd
);
1397 define_label (midnight_dlg
, paneletc
, 10, _("Quit"), (voidfn
) quit_cmd
);
1400 static const key_map ctl_x_map
[] = {
1401 { XCTRL('c'), (callfn
) quit_cmd
},
1402 { 'd', compare_dirs_cmd
},
1404 { 'a', reselect_vfs
},
1405 #endif /* USE_VFS */
1406 { 'p', copy_current_pathname
},
1407 { XCTRL('p'), copy_other_pathname
},
1408 { 't', copy_current_tagged
},
1409 { XCTRL('t'), copy_other_tagged
},
1411 #ifndef NATIVE_WIN32
1413 { 'r', copy_current_readlink
},
1414 { XCTRL('r'), copy_other_readlink
},
1416 { 's', symlink_cmd
},
1417 { XCTRL('s'), edit_symlink_cmd
},
1418 #endif /* !NATIVE_WIN32 */
1419 { 'i', info_cmd_no_menu
},
1420 { 'q', quick_cmd_no_menu
},
1421 { 'h', add2hotlist_cmd
},
1422 { '!', external_panelize
},
1423 #ifdef WITH_BACKGROUND
1425 #endif /* WITH_BACKGROUND */
1426 #ifdef HAVE_SETSOCKOPT
1427 { '%', source_routing
},
1428 #endif /* HAVE_SETSOCKOPT */
1432 static int ctl_x_map_enabled
= 0;
1434 static void ctl_x_cmd (int ignore
)
1436 ctl_x_map_enabled
= 1;
1439 static void nothing (void)
1443 static const key_map default_map
[] = {
1444 { KEY_F(19), menu_last_selected_cmd
},
1445 { KEY_F(20), (key_callback
) quiet_quit_cmd
},
1447 /* Copy useful information to the command line */
1448 { ALT('\n'), copy_prog_name
},
1449 { ALT('\r'), copy_prog_name
},
1450 { ALT('a'), copy_current_pathname
},
1451 { ALT('A'), copy_other_pathname
},
1453 { ALT('c'), quick_cd_cmd
},
1455 /* To access the directory hotlist */
1456 { XCTRL('\\'), quick_chdir_cmd
},
1459 { XCTRL('z'), suspend_cmd
},
1460 /* The filtered view command */
1461 { ALT('!'), filtered_view_cmd_cpanel
},
1464 { ALT('?'), find_cmd
},
1467 { XCTRL('r'), reread_cmd
},
1469 /* Toggle listing between long, user defined and full formats */
1470 { ALT('t'), toggle_listing_cmd
},
1473 { XCTRL('u'), swap_cmd
},
1476 { XCTRL('o'), view_other_cmd
},
1478 /* Control-X keybindings */
1479 { XCTRL('x'), ctl_x_cmd
},
1481 /* Trap dlg's exit commands */
1482 { ESC_CHAR
, nothing
},
1483 { XCTRL('c'), nothing
},
1484 { XCTRL('g'), nothing
},
1488 static void setup_sigwinch (void)
1490 #if (defined(HAVE_SLANG) || (NCURSES_VERSION_MAJOR >= 4)) && \
1491 !defined(NATIVE_WIN32) && defined(SIGWINCH)
1492 struct sigaction act
, oact
;
1493 act
.sa_handler
= flag_winch
;
1494 sigemptyset (&act
.sa_mask
);
1497 act
.sa_flags
|= SA_RESTART
;
1499 sigaction (SIGWINCH
, &act
, &oact
);
1506 /* Call all the inits */
1509 * Don't restrict the output on the screen manager level,
1510 * the translation tables take care of it.
1512 #define full_eight_bits (1)
1513 #define eight_bit_clean (1)
1514 #endif /* !HAVE_CHARSET */
1517 meta (stdscr
, eight_bit_clean
);
1519 SLsmg_Display_Eight_Bit
= full_eight_bits
? 128 : 160;
1524 init_xterm_support (void)
1531 termvalue
= getenv ("TERM");
1532 if (!termvalue
|| !(*termvalue
)){
1533 fprintf (stderr
, _("The TERM environment variable is unset!\n"));
1537 /* Check mouse capabilities */
1539 term_entry
= SLtt_tigetent (termvalue
);
1540 xmouse_seq
= SLtt_tigetstr ("Km", &term_entry
);
1542 xmouse_seq
= tigetstr ("kmous");
1545 /* -1 means invalid capability, shouldn't happen, but let's make it 0 */
1546 if ((long) xmouse_seq
== -1) {
1550 if (strcmp (termvalue
, "cygwin") == 0) {
1552 use_mouse_p
= MOUSE_DISABLED
;
1556 || strncmp (termvalue
, "xterm", 5) == 0
1557 || strncmp (termvalue
, "rxvt", 4) == 0
1558 || strcmp (termvalue
, "dtterm") == 0) {
1561 /* Default to the standard xterm sequence */
1563 xmouse_seq
= ESC_STR
"[M";
1566 /* Enable mouse unless explicitly disabled by --nomouse */
1567 if (use_mouse_p
!= MOUSE_DISABLED
) {
1568 use_mouse_p
= MOUSE_XTERM
;
1571 #if 0 /* It works on xterm, but not on rxvt */
1572 printf (ESC_STR
"]0;GNU Midnight Commander\7");
1577 static void setup_mc (void)
1584 #ifdef HAVE_SUBSHELL_SUPPORT
1586 add_select_channel (subshell_pty
, load_prompt
, 0);
1587 #endif /* !HAVE_SUBSHELL_SUPPORT */
1591 if (baudrate () < 9600 || slow_terminal
){
1597 static void setup_dummy_mc (const char *file
)
1599 char d
[MC_MAXPATHLEN
];
1601 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1605 /* Create a fake current_panel, this is needed because the
1606 * expand_format routine will use current panel.
1608 strcpy (cpanel
->cwd
, d
);
1609 cpanel
->selected
= 0;
1611 cpanel
->dir
.list
[0].fname
= (char *) file
;
1614 static void done_mc (void)
1622 * We sync the profiles since the hotlist may have changed, while
1623 * we only change the setup data if we have the auto save feature set
1625 if (auto_save_setup
)
1626 save_setup (); /* does also call save_hotlist */
1630 vfs_add_current_stamps ();
1631 if (xterm_flag
&& xterm_hintbar
)
1632 set_hintbar(_("Thank you for using GNU Midnight Commander"));
1635 /* This should be called after destroy_dlg since panel widgets
1636 * save their state on the profiles
1638 static void done_mc_profile (void)
1640 if (!auto_save_setup
)
1641 profile_forget_profile (profile_name
);
1647 /* This routine only handles cpanel, and opanel, it is easy to
1648 * change to use npanels, just loop over the number of panels
1649 * and use get_panel_widget (i) and make the test done below
1652 make_panels_dirty (void)
1655 panel_update_contents (cpanel
);
1657 if ((get_other_type () == view_listing
) && opanel
->dirty
)
1658 panel_update_contents (opanel
);
1661 /* In Windows people want to actually type the '\' key frequently */
1663 # define check_key_backslash(x) 0
1665 # define check_key_backslash(x) ((x) == '\\')
1669 midnight_callback (struct Dlg_head
*h
, int id
, int msg
)
1672 static int first_pre_event
= 1;
1677 make_panels_dirty ();
1678 if (auto_menu
&& first_pre_event
) {
1679 user_file_menu_cmd ();
1681 first_pre_event
= 0;
1685 if (ctl_x_map_enabled
){
1686 ctl_x_map_enabled
= 0;
1687 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1688 if (id
== ctl_x_map
[i
].key_code
){
1689 (*ctl_x_map
[i
].fn
)(id
);
1694 /* FIXME: should handle all menu shortcuts before this point */
1695 if (the_menubar
->active
)
1698 if (id
== KEY_F(10)){
1704 free_completions (cmdline
);
1706 /* On Linux, we can tell the difference */
1707 if (id
== '\n' && ctrl_pressed ()){
1712 if (id
== '\n' && cmdline
->buffer
[0]){
1713 send_message_to (h
, (Widget
*) cmdline
, WIDGET_KEY
, id
);
1717 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
)) &&
1718 !quote
&& !cpanel
->searching
) {
1719 if(!only_leading_plus_minus
) {
1720 /* Special treatement, since the input line will eat them */
1726 if (check_key_backslash (id
) || id
== '-'){
1732 reverse_selection_cmd ();
1735 } else if (command_prompt
&& !strlen (cmdline
->buffer
)) {
1736 /* Special treatement '+', '-', '\', '*' only when this is
1737 * first char on input line
1745 if (check_key_backslash (id
) || id
== '-') {
1751 reverse_selection_cmd ();
1758 case DLG_HOTKEY_HANDLED
:
1759 if (get_current_type () == view_listing
)
1760 cpanel
->searching
= 0;
1763 case DLG_UNHANDLED_KEY
:
1764 if (command_prompt
){
1767 v
= send_message_to (h
, (Widget
*) cmdline
, WIDGET_KEY
, id
);
1771 if (ctl_x_map_enabled
) {
1772 ctl_x_map_enabled
= 0;
1773 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1774 if (id
== ctl_x_map
[i
].key_code
){
1775 (*ctl_x_map
[i
].fn
)(id
);
1780 for (i
= 0; default_map
[i
].key_code
; i
++){
1781 if (id
== default_map
[i
].key_code
){
1782 (*default_map
[i
].fn
)(id
);
1787 return MSG_NOT_HANDLED
;
1789 /* We handle the special case of the output lines */
1791 attrset (SELECTED_COLOR
);
1792 if (console_flag
&& output_lines
)
1793 show_console_contents (output_start_y
,
1794 LINES
-output_lines
-keybar_visible
-1,
1795 LINES
-keybar_visible
-1);
1799 return default_dlg_callback (h
, id
, msg
);
1802 #define xtoolkit_panel_setup()
1809 if (!the_hint
->widget
.parent
)
1812 if (!message_visible
&& (!xterm_flag
|| !xterm_hintbar
)) {
1813 label_set_text (the_hint
, 0);
1817 if ((hint
= get_random_hint ())) {
1822 char text
[BUF_SMALL
];
1824 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"),
1831 setup_panels_and_run_mc (void)
1835 xtoolkit_panel_setup ();
1836 add_widget (midnight_dlg
, the_hint
);
1838 add_widget (midnight_dlg
, cmdline
);
1839 add_widget (midnight_dlg
, the_prompt
);
1840 add_widget (midnight_dlg
, the_bar
);
1842 if (boot_current_is_left
){
1849 add_widget (midnight_dlg
, get_panel_widget (first
));
1850 add_widget (midnight_dlg
, get_panel_widget (second
));
1851 add_widget (midnight_dlg
, the_menubar
);
1853 init_labels (get_panel_widget (0));
1854 init_labels (get_panel_widget (1));
1856 /* Run the Midnight Commander if no file was specified in the command line */
1857 run_dlg (midnight_dlg
);
1860 /* result must be free'd (I think this should go in util.c) */
1862 prepend_cwd_on_local (char *filename
)
1867 if (vfs_file_is_local (filename
)){
1868 if (*filename
== PATH_SEP
) /* an absolute pathname */
1869 return g_strdup (filename
);
1870 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1871 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1874 strcpy (d
+ l
, filename
);
1875 return canonicalize_pathname (d
);
1877 return g_strdup (filename
);
1881 mc_maybe_editor_or_viewer (void)
1885 if (!(view_one_file
|| edit_one_file
))
1888 /* Invoke the internal view/edit routine with:
1889 * the default processing and forcing the internal viewer/editor
1891 if (view_one_file
) {
1892 path
= prepend_cwd_on_local (view_one_file
);
1893 setup_dummy_mc (path
);
1894 view_file (path
, 0, 1);
1896 #ifdef USE_INTERNAL_EDIT
1898 path
= prepend_cwd_on_local ("");
1899 setup_dummy_mc (path
);
1900 edit (edit_one_file
, edit_one_file_start_line
);
1902 #endif /* USE_INTERNAL_EDIT */
1904 midnight_shutdown
= 1;
1909 /* Run the main dialog that occupies the whole screen */
1913 int midnight_colors
[4];
1915 midnight_colors
[0] = NORMAL_COLOR
; /* NORMALC */
1916 midnight_colors
[1] = REVERSE_COLOR
; /* FOCUSC */
1917 midnight_colors
[2] = INPUT_COLOR
; /* HOT_NORMALC */
1918 midnight_colors
[3] = NORMAL_COLOR
; /* HOT_FOCUSC */
1920 midnight_dlg
= create_dlg (0, 0, LINES
, COLS
, midnight_colors
,
1921 midnight_callback
, "[main]", NULL
,
1924 /* Check if we were invoked as an editor or file viewer */
1925 if (mc_maybe_editor_or_viewer ())
1930 setup_panels_and_run_mc ();
1933 midnight_shutdown
= 1;
1935 /* destroy_dlg destroys even cpanel->cwd, so we have to save a copy :) */
1936 if (print_last_wd
) {
1937 if (!vfs_current_is_local ())
1938 last_wd_string
= g_strdup (".");
1940 last_wd_string
= g_strdup (cpanel
->cwd
);
1944 destroy_dlg (midnight_dlg
);
1949 #if defined (NATIVE_WIN32)
1950 /* Windows NT code */
1955 SetConsoleTitle ("GNU Midnight Commander");
1957 shell
= getenv ("COMSPEC");
1958 if (!shell
|| !*shell
)
1959 shell
= get_default_shell ();
1961 /* Default opening mode for files is binary, not text (CR/LF translation) */
1966 mc_home
= get_mc_lib_dir ();
1969 /* Nothing to be done on Windows */
1971 sigchld_handler_no_subshell (int sig
)
1981 init_sigfatals (void)
1993 shell
= getenv ("SHELL");
1994 if (!shell
|| !*shell
)
1995 shell
= g_strdup (getpwuid (geteuid ())->pw_shell
);
1996 if (!shell
|| !*shell
)
1999 /* This is the directory, where MC was installed, on Unix this is DATADIR */
2000 /* and can be overriden by the MC_DATADIR environment variable */
2001 if ((mc_libdir
= getenv ("MC_DATADIR")) != NULL
) {
2002 mc_home
= g_strdup (mc_libdir
);
2004 mc_home
= g_strdup (DATADIR
);
2009 sigchld_handler_no_subshell (int sig
)
2011 #if defined(linux) || defined(__linux__)
2017 /* COMMENT: if it were true that after the call to handle_console(..INIT)
2018 the value of console_flag never changed, we could simply not install
2019 this handler at all if (!console_flag && !use_subshell). */
2021 /* That comment is no longer true. We need to wait() on a sigchld
2022 handler (that's at least what the tarfs code expects currently). */
2024 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
2026 if (pid
== cons_saver_pid
){
2028 if (WIFSTOPPED (status
)) {
2029 /* Someone has stopped cons.saver - restart it */
2030 kill (pid
, SIGCONT
);
2032 /* cons.saver has died - disable console saving */
2033 handle_console (CONSOLE_DONE
);
2037 #endif /* linux || __linux__ */
2039 /* If we get here, some other child exited; ignore it */
2045 struct sigaction sigchld_action
;
2047 sigchld_action
.sa_handler
=
2048 #ifdef HAVE_SUBSHELL_SUPPORT
2049 use_subshell
? sigchld_handler
:
2050 #endif /* HAVE_SUBSHELL_SUPPORT */
2051 sigchld_handler_no_subshell
;
2053 sigemptyset (&sigchld_action
.sa_mask
);
2056 sigchld_action
.sa_flags
= SA_RESTART
;
2058 sigchld_action
.sa_flags
= 0;
2059 #endif /* !SA_RESTART */
2061 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1) {
2062 #ifdef HAVE_SUBSHELL_SUPPORT
2064 * This may happen on QNX Neutrino 6, where SA_RESTART
2065 * is defined but not implemented. Fallback to no subshell.
2068 #endif /* HAVE_SUBSHELL_SUPPORT */
2072 #endif /* NATIVE_WIN32, UNIX */
2075 print_mc_usage (poptContext ctx
, FILE * stream
)
2079 "mc [flags] [this_dir] [other_panel_dir]\n\n"));
2081 /* print help for options */
2082 poptPrintHelp (ctx
, stream
, 0);
2084 fprintf (stream
, " %-19s %s\n", _("+number"),
2085 _("Set initial line number for the internal editor"));
2088 "Please send any bug reports (including the output of `mc -V')\n"
2089 "to mc-devel@gnome.org\n"));
2094 print_color_usage (void)
2096 fputs (_("--colors KEYWORD={FORE},{BACK}\n\n"
2097 "{FORE} and {BACK} can be omitted, and the default will be used\n"
2100 " Global: errors, reverse, gauge, input\n"
2101 " File display: normal, selected, marked, markselect\n"
2102 " Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus\n"
2103 " Menus: menu, menuhot, menusel, menuhotsel\n"
2104 " Help: helpnormal, helpitalic, helplink, helpslink\n"
2105 " File types: directory, execute, link, device, special, core\n"
2108 " black, gray, red, brightred, green, brightgreen, brown,\n"
2109 " yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
2110 " brightcyan, lightgray and white\n\n"), stdout
);
2114 probably_finish_program (void)
2116 if (finish_program
){
2129 process_args (poptContext ctx
, int c
, const char *option_arg
)
2141 #endif /* HAVE_SLANG */
2145 printf ("%s\n", mc_home
);
2151 ftpfs_set_debug (option_arg
);
2153 smbfs_set_debugf (option_arg
);
2154 #endif /* WITH_SMBFS */
2159 smbfs_set_debug (atoi (option_arg
));
2161 #endif /* WITH_SMBFS */
2162 #endif /* USE_NETCODE */
2165 use_mouse_p
= MOUSE_DISABLED
;
2168 #ifdef HAVE_SUBSHELL_SUPPORT
2172 #endif /* HAVE_SUBSHELL_SUPPORT */
2175 print_color_usage ();
2180 print_mc_usage (ctx
, stdout
);
2185 static const struct poptOption argument_table
[] = {
2186 #ifdef WITH_BACKGROUND
2187 {"background", 'B', POPT_ARG_NONE
, &background_wait
, 0,
2188 N_("Use to debug the background code")},
2190 {"color", 'c', POPT_ARG_NONE
, NULL
, 'c',
2191 N_("Request to run in color mode")},
2192 {"colors", 'C', POPT_ARG_STRING
, &command_line_colors
, 0,
2193 N_("Specifies a color configuration")},
2195 #ifdef USE_INTERNAL_EDIT
2196 {"edit", 'e', POPT_ARG_STRING
, &edit_one_file
, 0,
2197 N_("Edits one file")},
2200 {"help", 'h', POPT_ARG_NONE
, NULL
, 'h',
2201 N_("Displays this help message")},
2202 {"help-colors", 'H', POPT_ARG_NONE
, NULL
, 'H',
2203 N_("Displays a help screen on how to change the color scheme")},
2205 {"ftplog", 'l', POPT_ARG_STRING
, NULL
, 'l',
2206 N_("Log ftp dialog to specified file")},
2208 {"debuglevel", 'D', POPT_ARG_STRING
, NULL
, 'D',
2209 N_("Set debug level")},
2212 {"datadir", 'f', POPT_ARG_NONE
, NULL
, 'f',
2213 N_("Print data directory")},
2214 {"nocolor", 'b', POPT_ARG_NONE
, &disable_colors
, 0,
2215 N_("Requests to run in black and white")},
2216 {"nomouse", 'd', POPT_ARG_NONE
, NULL
, 'd',
2217 N_("Disable mouse support in text version")},
2218 #ifdef HAVE_SUBSHELL_SUPPORT
2219 {"nosubshell", 'u', POPT_ARG_NONE
, NULL
, 'u',
2220 N_("Disables subshell support")},
2221 {"forceexec", 'r', POPT_ARG_NONE
, &force_subshell_execution
, 0,
2222 N_("Force subshell execution")},
2224 {"printwd", 'P', POPT_ARG_NONE
, &print_last_wd
, 0,
2225 N_("Prints working directory at program exit")},
2226 {"resetsoft", 'k', POPT_ARG_NONE
, &reset_hp_softkeys
, 0,
2227 N_("Resets soft keys on HP terminals")},
2228 {"slow", 's', POPT_ARG_NONE
, &slow_terminal
, 0,
2229 N_("To run on slow terminals")},
2230 #ifndef NATIVE_WIN32
2231 {"stickchars", 'a', 0, &force_ugly_line_drawing
, 0,
2232 N_("Use stickchars to draw")},
2233 #endif /* !NATIVE_WIN32 */
2234 #ifdef HAVE_SUBSHELL_SUPPORT
2235 {"subshell", 'U', POPT_ARG_NONE
, &use_subshell
, 0,
2236 N_("Enables subshell support (default)")},
2238 #if defined(HAVE_SLANG) && !defined(NATIVE_WIN32)
2239 {"termcap", 't', 0, &SLtt_Try_Termcap
, 0,
2240 N_("Tries to use termcap instead of terminfo")},
2242 {"version", 'V', POPT_ARG_NONE
, NULL
, 'V',
2243 N_("Displays the current version")},
2244 {"view", 'v', POPT_ARG_STRING
, &view_one_file
, 0,
2245 N_("Launches the file viewer on a file")},
2246 {"xterm", 'x', POPT_ARG_NONE
, &force_xterm
, 0,
2247 N_("Forces xterm features")},
2249 {NULL
, 0, 0, NULL
, 0}
2253 handle_args (int argc
, char *argv
[])
2260 ctx
= poptGetContext ("mc", argc
, argv
, argument_table
,
2261 POPT_CONTEXT_NO_EXEC
);
2264 SLtt_Try_Termcap
= 1;
2267 while ((c
= poptGetNextOpt (ctx
)) > 0){
2268 process_args (ctx
, c
, poptGetOptArg (ctx
));
2272 print_mc_usage (ctx
, stderr
);
2273 fprintf(stderr
, "%s: %s\n",
2274 poptBadOption (ctx
, POPT_BADOPTION_NOALIAS
),
2278 probably_finish_program ();
2280 tmp
= poptGetArg (ctx
);
2283 * Check for special invocation names mcedit and mcview,
2284 * if none apply then set the current directory and the other
2285 * directory from the command line arguments
2287 base
= x_basename (argv
[0]);
2288 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP(base
, "vi")) {
2290 edit_one_file_start_line
= 1;
2292 if (*tmp
== '+' && isdigit ((unsigned char) tmp
[1])){
2293 int start_line
= atoi (tmp
);
2294 if (start_line
> 0) {
2295 char *file
= poptGetArg (ctx
);
2298 edit_one_file_start_line
= start_line
;
2302 edit_one_file
= g_strdup (tmp
);
2305 if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP(base
, "view")) {
2307 view_one_file
= g_strdup (tmp
);
2309 fprintf (stderr
, "No arguments given to the viewer\n");
2311 probably_finish_program ();
2314 /* sets the current dir and the other dir */
2316 this_dir
= g_strdup (tmp
);
2317 if ((tmp
= poptGetArg (ctx
)))
2318 other_dir
= g_strdup (tmp
);
2322 poptFreeContext (ctx
);
2326 * The compatibility_move_mc_files routine is intended to
2327 * move all of the hidden .mc files into a private ~/.mc
2328 * directory in the home directory, to avoid cluttering the users.
2330 * Previous versions of the program had all of their files in
2331 * the $HOME, we are now putting them in $HOME/.mc
2334 # define compatibility_move_mc_files()
2338 do_mc_filename_rename (char *mc_dir
, char *o_name
, char *n_name
)
2340 char *full_o_name
= concat_dir_and_file (home_dir
, o_name
);
2341 char *full_n_name
= g_strconcat (home_dir
, MC_BASE
, n_name
, NULL
);
2344 move
= 0 == rename (full_o_name
, full_n_name
);
2345 g_free (full_o_name
);
2346 g_free (full_n_name
);
2351 do_compatibility_move (char *mc_dir
)
2356 if (stat (mc_dir
, &s
) == 0)
2358 if (errno
!= ENOENT
)
2361 if (mkdir (mc_dir
, 0777) == -1)
2364 move
= do_mc_filename_rename (mc_dir
, ".mc.ini", "ini");
2365 move
+= do_mc_filename_rename (mc_dir
, ".mc.hot", "hotlist");
2366 move
+= do_mc_filename_rename (mc_dir
, ".mc.ext", "ext");
2367 move
+= do_mc_filename_rename (mc_dir
, ".mc.menu", "menu");
2368 move
+= do_mc_filename_rename (mc_dir
, ".mc.bashrc", "bashrc");
2369 move
+= do_mc_filename_rename (mc_dir
, ".mc.inputrc", "inputrc");
2370 move
+= do_mc_filename_rename (mc_dir
, ".mc.tcshrc", "tcshrc");
2371 move
+= do_mc_filename_rename (mc_dir
, ".mc.tree", "tree");
2376 show_change_notice
= 1;
2380 compatibility_move_mc_files (void)
2382 char *mc_dir
= concat_dir_and_file (home_dir
, ".mc");
2384 do_compatibility_move (mc_dir
);
2387 #endif /* NATIVE_WIN32 */
2390 main (int argc
, char *argv
[])
2392 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2393 setlocale (LC_ALL
, "");
2394 bindtextdomain ("mc", LOCALEDIR
);
2397 /* Initialize list of all user group for timur_clr_mode */
2400 /* Set up temporary directory */
2405 /* This variable is used by the subshell */
2406 home_dir
= getenv ("HOME");
2408 /* mc_home was computed by OS_Setup */
2415 SLtt_Ignore_Beep
= 1;
2418 /* NOTE: This has to be called before slang_init or whatever routine
2419 calls any define_sequence */
2422 handle_args (argc
, argv
);
2424 /* Used to report the last working directory at program end */
2426 #ifndef NATIVE_WIN32
2427 stdout_fd
= dup (1);
2429 if (open (ttyname (0), O_RDWR
) < 0)
2430 if (open ("/dev/tty", O_RDWR
) < 0) {
2431 /* Try if stderr is not redirected as the last chance */
2432 char *p
= g_strdup (ttyname (0));
2434 if (!strcmp (p
, ttyname (2)))
2438 _("Couldn't open tty line. You have to run mc without the -P flag.\n"
2439 "On some systems you may want to run # `which mc`\n"));
2447 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
2448 handle_console (CONSOLE_INIT
);
2450 # ifdef HAVE_SUBSHELL_SUPPORT
2451 subshell_get_console_attributes ();
2454 /* Install the SIGCHLD handler; must be done before init_subshell() */
2457 compatibility_move_mc_files ();
2459 /* We need this, since ncurses endwin () doesn't restore the signals */
2460 save_stop_handler ();
2462 /* Must be done before init_subshell, to set up the terminal size: */
2463 /* FIXME: Should be removed and LINES and COLS computed on subshell */
2467 /* NOTE: This call has to be after slang_init. It's the small part from
2468 the previous init_key which had to be moved after the call of slang_init */
2469 init_key_input_fd ();
2475 init_xterm_support ();
2477 #ifdef HAVE_SUBSHELL_SUPPORT
2479 /* Don't use subshell when invoked as a viewer or editor */
2480 if (edit_one_file
|| view_one_file
)
2483 /* Done here to ensure that the subshell doesn't */
2484 /* inherit the file descriptors opened below, etc */
2488 #endif /* HAVE_SUBSHELL_SUPPORT */
2490 /* Removing this from the X code let's us type C-c */
2493 /* Also done after init_subshell, to save any shell init file messages */
2495 handle_console (CONSOLE_SAVE
);
2497 if (alternate_plus_minus
)
2498 application_keypad_mode ();
2500 if (show_change_notice
){
2501 message (1, _(" Notice "),
2502 _(" The Midnight Commander configuration files \n"
2503 " are now stored in the ~/.mc directory, the \n"
2504 " files have been moved now\n"));
2507 #ifdef HAVE_SUBSHELL_SUPPORT
2509 prompt
= strip_ctrl_codes (subshell_prompt
);
2513 #endif /* HAVE_SUBSHELL_SUPPORT */
2514 prompt
= (geteuid () == 0) ? "# " : "$ ";
2516 /* Program main loop */
2519 /* Save the tree store */
2522 /* Virtual File System shutdown */
2525 /* Delete list of all user groups */
2528 flush_extension_file (); /* does only free memory */
2535 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2537 if (alternate_plus_minus
)
2538 numeric_keypad_mode ();
2540 #ifndef NATIVE_WIN32
2541 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2545 handle_console (CONSOLE_DONE
);
2546 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2549 /* On NT, home_dir is malloced */
2552 if (print_last_wd
) {
2553 if (print_last_revert
|| edit_one_file
|| view_one_file
)
2554 write (stdout_fd
, ".", 1);
2556 write (stdout_fd
, last_wd_string
, strlen (last_wd_string
));
2557 g_free (last_wd_string
);
2560 #ifndef NATIVE_WIN32
2562 #endif /* (NATIVE_WIN32) */
2565 free_codepages_list ();