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 message "The shell is already running a command" never */
183 int force_subshell_execution
= 0;
185 /* If true program softkeys (HP terminals only) on startup and after every
186 command ran in the subshell to the description found in the termcap/terminfo
188 int reset_hp_softkeys
= 0;
193 /* The widget where we draw the prompt */
202 /* For slow terminals */
203 int slow_terminal
= 0;
205 /* Mouse type: GPM, xterm or none */
206 Mouse_Type use_mouse_p
= MOUSE_NONE
;
208 /* If true, assume we are running on an xterm terminal */
209 static int force_xterm
= 0;
211 /* Controls screen clearing before an exec */
212 int clear_before_exec
= 1;
214 /* Asks for confirmation before deleting a file */
215 int confirm_delete
= 1;
217 /* Asks for confirmation before overwriting a file */
218 int confirm_overwrite
= 1;
220 /* Asks for confirmation before executing a program by pressing enter */
221 int confirm_execute
= 0;
223 /* Asks for confirmation before leaving the program */
224 int confirm_exit
= 1;
226 /* Asks for confirmation when using F3 to view a directory and there
228 int confirm_view_dir
= 0;
230 /* This flag indicates if the pull down menus by default drop down */
233 /* The dialog handle for the main program */
234 Dlg_head
*midnight_dlg
;
236 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
237 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
238 int update_prompt
= 0;
241 /* The name which was used to invoke mc */
245 /* The home directory */
248 /* The value of the other directory, only used when loading the setup */
251 /* Only used at program boot */
252 int boot_current_is_left
= 1;
256 /* If this is true, then when browsing the tree the other window will
257 * automatically reload it's directory with the contents of the currently
258 * selected directory.
262 /* If set, then print to the given file the last directory we were at */
263 static char *last_wd_file
;
264 static char *last_wd_string
;
265 /* Set to 1 to suppress printing the last directory */
266 static int print_last_revert
= 0;
268 /* Force colors, only used by Slang */
269 int force_colors
= 0;
271 /* colors specified on the command line: they override any other setting */
272 char *command_line_colors
;
274 /* File name to view if argument was supplied */
275 char *view_one_file
= 0;
277 /* File name to edit if argument was supplied */
278 char *edit_one_file
= 0;
280 /* Line to start the editor on */
281 static int edit_one_file_start_line
= 0;
283 /* Used so that widgets know if they are being destroyed or
285 int midnight_shutdown
= 0;
287 /* to show nice prompts */
288 static int last_paused
= 0;
290 /* Used for keeping track of the original stdout */
293 /* The user's shell */
296 /* mc_home: The home of MC */
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
,
357 if (force_update
& UP_RELOAD
) {
358 panel
->is_panelized
= 0;
363 /* FIXME: Should supply flushdir method */
364 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
367 /* If current_file == -1 (an invalid pointer) then preserve selection */
368 if (current_file
== UP_KEEPSEL
) {
370 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
374 if (panel
->is_panelized
)
375 reload_panelized (panel
);
377 panel_reload (panel
);
379 try_to_select (panel
, current_file
);
383 g_free (current_file
);
387 panel_clean_dir (WPanel
*panel
)
389 int count
= panel
->count
;
395 panel
->dirs_marked
= 0;
397 panel
->searching
= 0;
398 panel
->is_panelized
= 0;
400 clean_dir (&panel
->dir
, count
);
404 update_one_panel (int which
, int force_update
, char *current_file
)
408 if (get_display_type (which
) != view_listing
)
411 panel
= (WPanel
*) get_panel_widget (which
);
412 update_one_panel_widget (panel
, force_update
, current_file
);
415 /* This routine reloads the directory in both panels. It tries to
416 * select current_file in current_panel and other_file in other_panel.
417 * If current_file == -1 then it automatically sets current_file and
418 * other_file to the currently selected files in the panels.
420 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
421 * will not reload the other panel.
424 update_panels (int force_update
, char *current_file
)
426 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
429 update_one_panel (get_current_index (), force_update
, current_file
);
431 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
433 if (get_current_type () == view_listing
)
434 panel
= (WPanel
*) get_panel_widget (get_current_index ());
436 panel
= (WPanel
*) get_panel_widget (get_other_index ());
438 mc_chdir (panel
->cwd
);
441 /* Sets up the terminal before executing a program */
449 /* Save current stat of directories to avoid reloading the panels */
450 /* when no modifications have taken place */
452 save_cwds_stat (void)
455 mc_stat (cpanel
->cwd
, &(cpanel
->dir_stat
));
456 if (get_other_type () == view_listing
)
457 mc_stat (opanel
->cwd
, &(opanel
->dir_stat
));
461 #ifdef HAVE_SUBSHELL_SUPPORT
463 do_possible_cd (char *new_dir
)
465 if (!do_cd (new_dir
, cd_exact
))
466 message (1, _("Warning"),
467 _(" The Commander can't change to the directory that \n"
468 " the subshell claims you are in. Perhaps you have \n"
469 " deleted your working directory, or given yourself \n"
470 " extra access permissions with the \"su\" command? "));
474 do_update_prompt (void)
477 printf ("%s", subshell_prompt
);
482 #endif /* HAVE_SUBSHELL_SUPPORT */
485 restore_console (void)
487 handle_console (CONSOLE_RESTORE
);
493 do_execute (shell
, 0, 0);
497 do_execute (const char *shell
, const char *command
, int flags
)
499 #ifdef HAVE_SUBSHELL_SUPPORT
500 char *new_dir
= NULL
;
501 #endif /* HAVE_SUBSHELL_SUPPORT */
504 char *old_vfs_dir
= 0;
506 if (!vfs_current_is_local ())
507 old_vfs_dir
= g_strdup (vfs_get_current_dir ());
515 if (!use_subshell
&& !(flags
& EXECUTE_INTERNAL
&& command
)) {
516 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
&& !xterm_flag
536 && !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
);
573 update_xterm_title_path ();
579 /* Executes a command */
581 shell_execute (char *command
, int flags
)
583 #ifdef HAVE_SUBSHELL_SUPPORT
585 if (subshell_state
== INACTIVE
|| force_subshell_execution
)
586 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
588 message (1, MSG_ERROR
,
589 _(" The shell is already running a command "));
591 #endif /* HAVE_SUBSHELL_SUPPORT */
592 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
596 execute (char *command
)
598 shell_execute (command
, 0);
604 free_completions (cmdline
);
605 dlg_one_down (midnight_dlg
);
608 /* Stop MC main dialog and the current dialog if it exists.
609 * Needed to provide fast exit from MC viewer or editor on shell exit */
613 midnight_dlg
->running
= 0;
615 current_dlg
->running
= 0;
620 quit_cmd_internal (int quiet
)
624 if (quiet
|| !confirm_exit
) {
628 (_(" The Midnight Commander "),
629 _(" Do you really want to quit the Midnight Commander? "), 0,
630 2, _("&Yes"), _("&No")) == 0)
634 #ifdef HAVE_SUBSHELL_SUPPORT
637 else if ((q
= exit_subshell ()))
649 quit_cmd_internal (0);
653 quiet_quit_cmd (void)
655 print_last_revert
= 1;
656 quit_cmd_internal (1);
661 * Touch window and refresh window functions
664 /* This routine untouches the first line on both panels in order */
665 /* to avoid the refreshing the menu bar */
674 repaint_screen (void)
680 /* Wrapper for do_subshell_chdir, check for availability of subshell */
682 subshell_chdir (char *directory
)
684 #ifdef HAVE_SUBSHELL_SUPPORT
686 if (vfs_current_is_local ())
687 do_subshell_chdir (directory
, 0, 1);
689 #endif /* HAVE_SUBSHELL_SUPPORT */
693 directory_history_add (struct WPanel
*panel
, char *s
)
698 strip_password (s
, 1);
700 panel
->dir_history
= list_append_unique (panel
->dir_history
, text
);
704 * If we moved to the parent directory move the selection pointer to
705 * the old directory name; If we leave VFS dir, remove FS specificator.
706 * Warn: This code spoils lwd string.
708 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
711 get_parent_dir_name (char *cwd
, char *lwd
)
714 if (strlen (lwd
) > strlen (cwd
))
715 if ((p
= strrchr (lwd
, PATH_SEP
)) && !strncmp (cwd
, lwd
, p
- lwd
)) {
722 * Changes the current directory of the panel.
723 * Don't record change in the directory history.
726 _do_panel_cd (WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
728 char *directory
, *olddir
;
729 char temp
[MC_MAXPATHLEN
];
730 char *translated_url
;
734 struct vfs_stamping
*parent
;
736 olddir
= g_strdup (panel
->cwd
);
737 translated_url
= new_dir
= vfs_translate_url (new_dir
);
739 /* Convert *new_path to a suitable pathname, handle ~user */
741 if (cd_type
== cd_parse_command
) {
742 while (*new_dir
== ' ')
745 if (!strcmp (new_dir
, "-")) {
746 strcpy (temp
, panel
->lwd
);
750 directory
= *new_dir
? new_dir
: home_dir
;
752 if (mc_chdir (directory
) == -1) {
753 strcpy (panel
->cwd
, olddir
);
755 g_free (translated_url
);
758 g_free (translated_url
);
760 /* Success: save previous directory, shutdown status of previous dir */
761 strcpy (panel
->lwd
, olddir
);
762 free_completions (cmdline
);
764 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
767 oldvfs
= vfs_type (olddir
);
768 oldvfsid
= vfs_ncs_getid (oldvfs
, olddir
, &parent
);
769 vfs_add_noncurrent_stamps (oldvfs
, oldvfsid
, parent
);
770 vfs_rm_parents (parent
);
773 subshell_chdir (panel
->cwd
);
775 /* Reload current panel */
776 panel_clean_dir (panel
);
778 do_load_dir (&panel
->dir
, panel
->sort_type
, panel
->reverse
,
779 panel
->case_sensitive
, panel
->filter
);
780 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
782 panel_update_contents (panel
);
783 update_xterm_title_path ();
791 * Changes the current directory of the panel.
792 * Record change in the directory history.
795 do_panel_cd (struct WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
799 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
801 directory_history_add (panel
, panel
->cwd
);
806 do_cd (char *new_dir
, enum cd_enum exact
)
808 return (do_panel_cd (cpanel
, new_dir
, exact
));
812 directory_history_next (WPanel
*panel
)
816 nextdir
= g_list_next (panel
->dir_history
);
821 if (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
))
822 panel
->dir_history
= nextdir
;
826 directory_history_prev (WPanel
*panel
)
830 prevdir
= g_list_previous (panel
->dir_history
);
835 if (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
))
836 panel
->dir_history
= prevdir
;
840 directory_history_list (WPanel
*panel
)
844 if (!panel
->dir_history
)
847 s
= show_hist (panel
->dir_history
, panel
->widget
.x
, panel
->widget
.y
);
852 if (_do_panel_cd (panel
, s
, cd_exact
))
853 directory_history_add (panel
, panel
->cwd
);
855 message (1, MSG_ERROR
, _("Cannot change directory"));
859 #ifdef HAVE_SUBSHELL_SUPPORT
861 load_prompt (int fd
, void *unused
)
863 if (!read_subshell_prompt ())
866 /* Don't actually change the prompt if it's invisible */
867 if (current_dlg
== midnight_dlg
&& command_prompt
) {
870 prompt
= strip_ctrl_codes (subshell_prompt
);
871 prompt_len
= strlen (prompt
);
873 /* Check for prompts too big */
874 if (COLS
> 8 && prompt_len
> COLS
- 8) {
875 prompt
[COLS
- 8] = 0;
876 prompt_len
= COLS
- 8;
878 label_set_text (the_prompt
, prompt
);
879 winput_set_origin ((WInput
*) cmdline
, prompt_len
,
882 /* since the prompt has changed, and we are called from one of the
883 * get_event channels, the prompt updating does not take place
884 * automatically: force a cursor update and a screen refresh
886 update_cursor (midnight_dlg
);
892 #endif /* HAVE_SUBSHELL_SUPPORT */
894 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
896 maybe_cd (int char_code
, int move_up_dir
)
898 if (navigate_with_arrows
) {
899 if (!cmdline
->buffer
[0]) {
901 do_cd ("..", cd_exact
);
904 if (S_ISDIR (selection (cpanel
)->buf
.st_mode
)
905 || link_isdir (selection (cpanel
))) {
906 do_cd (selection (cpanel
)->fname
, cd_exact
);
920 if (!SELECTED_IS_PANEL
)
924 sort_order
= sort_box (p
->sort_type
, &p
->reverse
, &p
->case_sensitive
);
926 panel_set_sort_order (p
, sort_order
);
935 sel_dir
= tree_box (selection (cpanel
)->fname
);
937 do_cd (sel_dir
, cd_exact
);
942 #ifdef LISTMODE_EDITOR
947 newmode
= listmode_edit ("half <type,>name,|,size:8,|,perm:4+");
948 message (0, _(" Listing format edit "), _(" New mode is \"%s\" "),
952 #endif /* LISTMODE_EDITOR */
954 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
955 static menu_entry PanelMenu
[] = {
956 {' ', N_("&Listing mode..."), 'L', listing_cmd
},
957 {' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
958 {' ', N_("&Info C-x i"), 'I', info_cmd
},
959 {' ', N_("&Tree"), 'T', tree_cmd
},
961 {' ', N_("&Sort order..."), 'S', sort_cmd
},
963 {' ', N_("&Filter..."), 'F', filter_cmd
},
967 {' ', N_("&Network link..."), 'N', netlink_cmd
},
969 {' ', N_("FT&P link..."), 'P', ftplink_cmd
},
970 {' ', N_("S&hell link..."), 'H', fishlink_cmd
},
972 {' ', N_("SM&B link..."), 'B', smblink_cmd
},
977 {' ', N_("&Drive... M-d"), 'D', drive_cmd_a
},
979 {' ', N_("&Rescan C-r"), 'R', reread_cmd
}
982 static menu_entry RightMenu
[] = {
983 {' ', N_("&Listing mode..."), 'L', listing_cmd
},
984 {' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
985 {' ', N_("&Info C-x i"), 'I', info_cmd
},
986 {' ', N_("&Tree"), 'T', tree_cmd
},
988 {' ', N_("&Sort order..."), 'S', sort_cmd
},
990 {' ', N_("&Filter..."), 'F', filter_cmd
},
994 {' ', N_("&Network link..."), 'N', netlink_cmd
},
996 {' ', N_("FT&P link..."), 'P', ftplink_cmd
},
997 {' ', N_("S&hell link..."), 'H', fishlink_cmd
},
999 {' ', N_("SM&B link..."), 'B', smblink_cmd
},
1004 {' ', N_("&Drive... M-d"), 'D', drive_cmd_b
},
1006 {' ', N_("&Rescan C-r"), 'R', reread_cmd
}
1009 static menu_entry FileMenu
[] = {
1010 {' ', N_("&User menu F2"), 'U', user_file_menu_cmd
},
1011 {' ', N_("&View F3"), 'V', view_cmd
},
1012 {' ', N_("Vie&w file... "), 'W', view_file_cmd
},
1013 {' ', N_("&Filtered view M-!"), 'F', filtered_view_cmd
},
1014 {' ', N_("&Edit F4"), 'E', edit_cmd
},
1015 {' ', N_("&Copy F5"), 'C', copy_cmd
},
1016 {' ', N_("c&Hmod C-x c"), 'H', chmod_cmd
},
1017 #ifndef NATIVE_WIN32
1018 {' ', N_("&Link C-x l"), 'L', link_cmd
},
1019 {' ', N_("&SymLink C-x s"), 'S', symlink_cmd
},
1020 {' ', N_("edit s&Ymlink C-x C-s"), 'Y', edit_symlink_cmd
},
1021 {' ', N_("ch&Own C-x o"), 'O', chown_cmd
},
1022 {' ', N_("&Advanced chown "), 'A', chown_advanced_cmd
},
1024 {' ', N_("&Rename/Move F6"), 'R', ren_cmd
},
1025 {' ', N_("&Mkdir F7"), 'M', mkdir_cmd
},
1026 {' ', N_("&Delete F8"), 'D', delete_cmd
},
1027 {' ', N_("&Quick cd M-c"), 'Q', quick_cd_cmd
},
1029 {' ', N_("select &Group M-+"), 'G', select_cmd
},
1030 {' ', N_("u&Nselect group M-\\"), 'N', unselect_cmd
},
1031 {' ', N_("reverse selec&Tion M-*"), 'T', reverse_selection_cmd
},
1033 {' ', N_("e&Xit F10"), 'X', quit_cmd
}
1036 static menu_entry CmdMenu
[] = {
1037 /* I know, I'm lazy, but the tree widget when it's not running
1038 * as a panel still has some problems, I have not yet finished
1039 * the WTree widget port, sorry.
1041 {' ', N_("&Directory tree"), 'D', treebox_cmd
},
1042 {' ', N_("&Find file M-?"), 'F', find_cmd
},
1043 {' ', N_("s&Wap panels C-u"), 'W', swap_cmd
},
1044 {' ', N_("switch &Panels on/off C-o"), 'P', view_other_cmd
},
1045 {' ', N_("&Compare directories C-x d"), 'C', compare_dirs_cmd
},
1046 {' ', N_("e&Xternal panelize C-x !"), 'X', external_panelize
},
1047 {' ', N_("show directory s&Izes"), 'I', dirsizes_cmd
},
1049 {' ', N_("command &History"), 'H', history_cmd
},
1050 {' ', N_("di&Rectory hotlist C-\\"), 'R', quick_chdir_cmd
},
1052 {' ', N_("&Active VFS list C-x a"), 'A', reselect_vfs
},
1053 {' ', N_("Fr&ee VFSs now"), 'E', free_vfs_now
},
1055 #ifdef WITH_BACKGROUND
1056 {' ', N_("&Background jobs C-x j"), 'B', jobs_cmd
},
1059 #ifdef USE_EXT2FSLIB
1060 {' ', N_("&Undelete files (ext2fs only)"), 'U', undelete_cmd
},
1062 #ifdef LISTMODE_EDITOR
1063 {' ', N_("&Listing format edit"), 'L', listmode_cmd
},
1065 #if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
1068 {' ', N_("Edit &extension file"), 'E', ext_cmd
},
1069 {' ', N_("Edit &menu file"), 'M', edit_mc_menu_cmd
},
1070 #ifdef USE_INTERNAL_EDIT
1071 {' ', N_("Edit edi&tor menu file"), 'T', edit_user_menu_cmd
},
1072 {' ', N_("Edit &syntax file"), 'S', edit_syntax_cmd
}
1073 #endif /* USE_INTERNAL_EDIT */
1076 /* Must keep in sync with the constants in menu_cmd */
1077 static menu_entry OptMenu
[] = {
1078 {' ', N_("&Configuration..."), 'C', configure_box
},
1079 {' ', N_("&Layout..."), 'L', layout_cmd
},
1080 {' ', N_("c&Onfirmation..."), 'O', confirm_box
},
1081 {' ', N_("&Display bits..."), 'D', display_bits_box
},
1082 #ifndef NATIVE_WIN32
1083 {' ', N_("learn &Keys..."), 'K', learn_keys
},
1084 #endif /* !NATIVE_WIN32 */
1086 {' ', N_("&Virtual FS..."), 'V', configure_vfs
},
1087 #endif /* !USE_VFS */
1089 {' ', N_("&Save setup"), 'S', save_setup_cmd
}
1092 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
1094 static Menu
*MenuBar
[5];
1100 create_menu (horizontal_split
? _(" &Above ") : _(" &Left "),
1101 PanelMenu
, menu_entries (PanelMenu
),
1102 "[Left and Right Menus]");
1104 create_menu (_(" &File "), FileMenu
, menu_entries (FileMenu
),
1107 create_menu (_(" &Command "), CmdMenu
, menu_entries (CmdMenu
),
1110 create_menu (_(" &Options "), OptMenu
, menu_entries (OptMenu
),
1113 create_menu (horizontal_split
? _(" &Below ") : _(" &Right "),
1114 RightMenu
, menu_entries (PanelMenu
),
1115 "[Left and Right Menus]");
1123 for (i
= 0; i
< 5; i
++) {
1124 destroy_menu (MenuBar
[i
]);
1129 menu_last_selected_cmd (void)
1131 the_menubar
->active
= 1;
1132 the_menubar
->dropped
= drop_menus
;
1133 the_menubar
->previous_selection
= dlg_item_number (midnight_dlg
);
1134 dlg_select_widget (midnight_dlg
, the_menubar
);
1140 if (the_menubar
->active
)
1143 if (get_current_index () == 0)
1144 the_menubar
->selected
= 0;
1146 the_menubar
->selected
= 4;
1147 menu_last_selected_cmd ();
1150 /* Flag toggling functions */
1152 toggle_fast_reload (void)
1154 fast_reload
= !fast_reload
;
1155 if (fast_reload_w
== 0 && fast_reload
) {
1156 message (0, _(" Information "),
1158 (" Using the fast reload option may not reflect the exact \n"
1159 " directory contents. In this cases you'll need to do a \n"
1160 " manual reload of the directory. See the man page for \n"
1167 toggle_mix_all_files (void)
1169 mix_all_files
= !mix_all_files
;
1170 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1174 toggle_show_backup (void)
1176 show_backups
= !show_backups
;
1177 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1181 toggle_show_hidden (void)
1183 show_dot_files
= !show_dot_files
;
1184 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1188 * Just a hack for allowing url-like pathnames to be accepted from the
1192 translated_mc_chdir (char *dir
)
1196 newdir
= vfs_translate_url (dir
);
1202 create_panels (void)
1208 char original_dir
[1024];
1210 original_dir
[0] = 0;
1212 if (boot_current_is_left
) {
1215 current_mode
= startup_left_mode
;
1216 other_mode
= startup_right_mode
;
1220 current_mode
= startup_right_mode
;
1221 other_mode
= startup_left_mode
;
1223 /* Creates the left panel */
1226 /* Ok, user has specified two dirs, save the original one,
1227 * since we may not be able to chdir to the proper
1228 * second directory later
1230 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
1232 translated_mc_chdir (this_dir
);
1234 set_display_type (current_index
, current_mode
);
1236 /* The other panel */
1238 if (original_dir
[0])
1239 translated_mc_chdir (original_dir
);
1240 translated_mc_chdir (other_dir
);
1242 set_display_type (other_index
, other_mode
);
1244 if (startup_left_mode
== view_listing
) {
1245 current_panel
= left_panel
;
1248 current_panel
= right_panel
;
1250 current_panel
= left_panel
;
1253 /* Create the nice widgets */
1254 cmdline
= command_new (0, 0, 0);
1255 the_prompt
= label_new (0, 0, prompt
, NULL
);
1256 the_prompt
->transparent
= 1;
1257 the_bar
= buttonbar_new (keybar_visible
);
1259 the_hint
= label_new (0, 0, 0, NULL
);
1260 the_hint
->transparent
= 1;
1261 the_hint
->auto_adjust_cols
= 0;
1262 the_hint
->widget
.cols
= COLS
;
1264 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
, 5);
1268 copy_current_pathname (void)
1270 if (!command_prompt
)
1273 command_insert (cmdline
, cpanel
->cwd
, 0);
1274 if (cpanel
->cwd
[strlen (cpanel
->cwd
) - 1] != PATH_SEP
)
1275 command_insert (cmdline
, PATH_SEP_STR
, 0);
1279 copy_other_pathname (void)
1281 if (get_other_type () != view_listing
)
1284 if (!command_prompt
)
1287 command_insert (cmdline
, opanel
->cwd
, 0);
1288 if (cpanel
->cwd
[strlen (opanel
->cwd
) - 1] != PATH_SEP
)
1289 command_insert (cmdline
, PATH_SEP_STR
, 0);
1293 copy_readlink (WPanel
*panel
)
1295 if (!command_prompt
)
1297 if (S_ISLNK (selection (panel
)->buf
.st_mode
)) {
1298 char buffer
[MC_MAXPATHLEN
];
1300 concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1303 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
);
1307 command_insert (cmdline
, buffer
, 1);
1313 copy_current_readlink (void)
1315 copy_readlink (cpanel
);
1319 copy_other_readlink (void)
1321 if (get_other_type () != view_listing
)
1323 copy_readlink (opanel
);
1326 /* Insert the selected file name into the input line */
1328 copy_prog_name (void)
1331 if (!command_prompt
)
1334 if (get_current_type () == view_tree
) {
1335 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1336 tmp
= tree_selected_name (tree
);
1338 tmp
= selection (cpanel
)->fname
;
1340 command_insert (cmdline
, tmp
, 1);
1344 copy_tagged (WPanel
*panel
)
1348 if (!command_prompt
)
1350 input_disable_update (cmdline
);
1351 if (panel
->marked
) {
1352 for (i
= 0; i
< panel
->count
; i
++) {
1353 if (panel
->dir
.list
[i
].f
.marked
)
1354 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, 1);
1357 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
,
1360 input_enable_update (cmdline
);
1364 copy_current_tagged (void)
1366 copy_tagged (cpanel
);
1370 copy_other_tagged (void)
1372 if (get_other_type () != view_listing
)
1374 copy_tagged (opanel
);
1378 do_suspend_cmd (void)
1382 if (console_flag
&& !use_subshell
)
1387 struct sigaction sigtstp_action
;
1389 /* Make sure that the SIGTSTP below will suspend us directly,
1390 without calling ncurses' SIGTSTP handler; we *don't* want
1391 ncurses to redraw the screen immediately after the SIGCONT */
1392 sigaction (SIGTSTP
, &startup_handler
, &sigtstp_action
);
1394 kill (getpid (), SIGTSTP
);
1396 /* Restore previous SIGTSTP action */
1397 sigaction (SIGTSTP
, &sigtstp_action
, NULL
);
1399 #endif /* SIGTSTP */
1401 if (console_flag
&& !use_subshell
)
1402 handle_console (CONSOLE_SAVE
);
1404 edition_post_exec ();
1412 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1419 define_label (midnight_dlg
, 1, _("Help"), help_cmd
);
1420 define_label (midnight_dlg
, 2, _("Menu"), user_file_menu_cmd
);
1421 define_label (midnight_dlg
, 9, _("PullDn"), menu_cmd
);
1422 define_label (midnight_dlg
, 10, _("Quit"), quit_cmd
);
1425 static const key_map ctl_x_map
[] = {
1426 {XCTRL ('c'), quit_cmd
},
1427 {'d', compare_dirs_cmd
},
1429 {'a', reselect_vfs
},
1430 #endif /* USE_VFS */
1431 {'p', copy_current_pathname
},
1432 {XCTRL ('p'), copy_other_pathname
},
1433 {'t', copy_current_tagged
},
1434 {XCTRL ('t'), copy_other_tagged
},
1436 #ifndef NATIVE_WIN32
1438 {'r', copy_current_readlink
},
1439 {XCTRL ('r'), copy_other_readlink
},
1442 {XCTRL ('s'), edit_symlink_cmd
},
1443 #endif /* !NATIVE_WIN32 */
1444 {'i', info_cmd_no_menu
},
1445 {'q', quick_cmd_no_menu
},
1446 {'h', add2hotlist_cmd
},
1447 {'!', external_panelize
},
1448 #ifdef WITH_BACKGROUND
1450 #endif /* WITH_BACKGROUND */
1451 #ifdef HAVE_SETSOCKOPT
1452 {'%', source_routing
},
1453 #endif /* HAVE_SETSOCKOPT */
1457 static int ctl_x_map_enabled
= 0;
1460 ctl_x_cmd (int ignore
)
1462 ctl_x_map_enabled
= 1;
1470 static const key_map default_map
[] = {
1471 {KEY_F (19), menu_last_selected_cmd
},
1472 {KEY_F (20), (key_callback
) quiet_quit_cmd
},
1474 /* Copy useful information to the command line */
1475 {ALT ('a'), copy_current_pathname
},
1476 {ALT ('A'), copy_other_pathname
},
1478 {ALT ('c'), quick_cd_cmd
},
1480 /* To access the directory hotlist */
1481 {XCTRL ('\\'), quick_chdir_cmd
},
1484 {XCTRL ('z'), suspend_cmd
},
1486 /* The filtered view command */
1487 {ALT ('!'), filtered_view_cmd
},
1490 {ALT ('?'), find_cmd
},
1493 {XCTRL ('r'), reread_cmd
},
1495 /* Toggle listing between long, user defined and full formats */
1496 {ALT ('t'), toggle_listing_cmd
},
1499 {XCTRL ('u'), swap_cmd
},
1502 {XCTRL ('o'), view_other_cmd
},
1504 /* Control-X keybindings */
1505 {XCTRL ('x'), ctl_x_cmd
},
1507 /* Trap dlg's exit commands */
1508 {ESC_CHAR
, nothing
},
1509 {XCTRL ('c'), nothing
},
1510 {XCTRL ('g'), nothing
},
1515 setup_sigwinch (void)
1517 #if (defined(HAVE_SLANG) || (NCURSES_VERSION_MAJOR >= 4)) && \
1518 !defined(NATIVE_WIN32) && defined(SIGWINCH)
1519 struct sigaction act
, oact
;
1520 act
.sa_handler
= flag_winch
;
1521 sigemptyset (&act
.sa_mask
);
1524 act
.sa_flags
|= SA_RESTART
;
1526 sigaction (SIGWINCH
, &act
, &oact
);
1533 /* Call all the inits */
1536 * Don't restrict the output on the screen manager level,
1537 * the translation tables take care of it.
1539 #define full_eight_bits (1)
1540 #define eight_bit_clean (1)
1541 #endif /* !HAVE_CHARSET */
1544 meta (stdscr
, eight_bit_clean
);
1546 SLsmg_Display_Eight_Bit
= full_eight_bits
? 128 : 160;
1551 init_xterm_support (void)
1558 termvalue
= getenv ("TERM");
1559 if (!termvalue
|| !(*termvalue
)) {
1560 fputs (_("The TERM environment variable is unset!\n"), stderr
);
1564 /* Check mouse capabilities */
1566 term_entry
= SLtt_tigetent (termvalue
);
1567 xmouse_seq
= SLtt_tigetstr ("Km", &term_entry
);
1569 xmouse_seq
= tigetstr ("kmous");
1572 /* -1 means invalid capability, shouldn't happen, but let's make it 0 */
1573 if ((long) xmouse_seq
== -1) {
1577 if (strcmp (termvalue
, "cygwin") == 0) {
1579 use_mouse_p
= MOUSE_DISABLED
;
1582 if (force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
1583 || strncmp (termvalue
, "rxvt", 4) == 0
1584 || strcmp (termvalue
, "dtterm") == 0) {
1587 /* Default to the standard xterm sequence */
1589 xmouse_seq
= ESC_STR
"[M";
1592 /* Enable mouse unless explicitly disabled by --nomouse */
1593 if (use_mouse_p
!= MOUSE_DISABLED
) {
1594 use_mouse_p
= MOUSE_XTERM
;
1607 #ifdef HAVE_SUBSHELL_SUPPORT
1609 add_select_channel (subshell_pty
, load_prompt
, 0);
1610 #endif /* !HAVE_SUBSHELL_SUPPORT */
1614 if (baudrate () < 9600 || slow_terminal
) {
1621 setup_dummy_mc (const char *file
)
1623 char d
[MC_MAXPATHLEN
];
1625 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1629 /* Create a fake current_panel, this is needed because the
1630 * expand_format routine will use current panel.
1632 strcpy (cpanel
->cwd
, d
);
1633 cpanel
->selected
= 0;
1635 cpanel
->dir
.list
[0].fname
= (char *) file
;
1647 * We sync the profiles since the hotlist may have changed, while
1648 * we only change the setup data if we have the auto save feature set
1650 if (auto_save_setup
)
1651 save_setup (); /* does also call save_hotlist */
1655 vfs_add_current_stamps ();
1658 /* This should be called after destroy_dlg since panel widgets
1659 * save their state on the profiles
1662 done_mc_profile (void)
1664 if (!auto_save_setup
)
1665 profile_forget_profile (profile_name
);
1672 * Partly repaint the contents of the panels.
1673 * Ideally, all painting should be done in the panel's callback.
1674 * Since we are bypassing the standard widget library by forcing
1675 * the repaint, the cursor position needs to be preserved.
1678 make_panels_dirty (void)
1682 /* Preserve current cursor position */
1683 getyx (stdscr
, row
, col
);
1686 panel_update_contents (cpanel
);
1688 if ((get_other_type () == view_listing
) && opanel
->dirty
)
1689 panel_update_contents (opanel
);
1691 /* Restore cursor position */
1695 /* In Windows people want to actually type the '\' key frequently */
1697 # define check_key_backslash(x) 0
1699 # define check_key_backslash(x) ((x) == '\\')
1703 midnight_callback (struct Dlg_head
*h
, int id
, int msg
)
1706 static int first_pre_event
= 1;
1711 make_panels_dirty ();
1712 if (auto_menu
&& first_pre_event
) {
1713 user_file_menu_cmd ();
1715 first_pre_event
= 0;
1719 if (ctl_x_map_enabled
) {
1720 ctl_x_map_enabled
= 0;
1721 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1722 if (id
== ctl_x_map
[i
].key_code
) {
1723 (*ctl_x_map
[i
].fn
) (id
);
1728 /* FIXME: should handle all menu shortcuts before this point */
1729 if (the_menubar
->active
)
1732 if (id
== KEY_F (10)) {
1738 free_completions (cmdline
);
1740 if (id
== '\n' && cmdline
->buffer
[0]) {
1741 send_message ((Widget
*) cmdline
, WIDGET_KEY
, id
);
1745 /* Ctrl-Enter and Alt-Enter */
1746 if (((id
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n')
1747 && (id
& (KEY_M_CTRL
| KEY_M_ALT
))) {
1752 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1753 && !quote
&& !cpanel
->searching
) {
1754 if (!only_leading_plus_minus
) {
1755 /* Special treatement, since the input line will eat them */
1761 if (check_key_backslash (id
) || id
== '-') {
1767 reverse_selection_cmd ();
1770 } else if (command_prompt
&& !strlen (cmdline
->buffer
)) {
1771 /* Special treatement '+', '-', '\', '*' only when this is
1772 * first char on input line
1780 if (check_key_backslash (id
) || id
== '-') {
1786 reverse_selection_cmd ();
1793 case DLG_HOTKEY_HANDLED
:
1794 if (get_current_type () == view_listing
)
1795 cpanel
->searching
= 0;
1798 case DLG_UNHANDLED_KEY
:
1799 if (command_prompt
) {
1802 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, id
);
1806 if (ctl_x_map_enabled
) {
1807 ctl_x_map_enabled
= 0;
1808 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1809 if (id
== ctl_x_map
[i
].key_code
) {
1810 (*ctl_x_map
[i
].fn
) (id
);
1814 for (i
= 0; default_map
[i
].key_code
; i
++) {
1815 if (id
== default_map
[i
].key_code
) {
1816 (*default_map
[i
].fn
) (id
);
1821 return MSG_NOT_HANDLED
;
1823 /* We handle the special case of the output lines */
1825 attrset (SELECTED_COLOR
);
1826 if (console_flag
&& output_lines
)
1827 show_console_contents (output_start_y
,
1828 LINES
- output_lines
- keybar_visible
-
1829 1, LINES
- keybar_visible
- 1);
1833 return default_dlg_callback (h
, id
, msg
);
1836 #define xtoolkit_panel_setup()
1838 /* Show current directory in the xterm title */
1840 update_xterm_title_path (void)
1842 unsigned char *p
, *s
;
1844 if (xterm_flag
&& xterm_title
) {
1845 p
= s
= g_strdup (strip_home_and_password (cpanel
->cwd
));
1847 if (!is_printable (*s
))
1850 fprintf (stdout
, "\33]0;mc - %s\7", p
);
1857 * Load new hint and display it.
1858 * IF force is not 0, ignore the timeout.
1861 load_hint (int force
)
1865 if (!the_hint
->widget
.parent
)
1868 if (!message_visible
) {
1869 label_set_text (the_hint
, 0);
1873 if ((hint
= get_random_hint (force
))) {
1878 char text
[BUF_SMALL
];
1880 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"),
1887 setup_panels_and_run_mc (void)
1891 xtoolkit_panel_setup ();
1892 add_widget (midnight_dlg
, the_hint
);
1894 add_widget (midnight_dlg
, cmdline
);
1895 add_widget (midnight_dlg
, the_prompt
);
1896 add_widget (midnight_dlg
, the_bar
);
1898 if (boot_current_is_left
) {
1905 add_widget (midnight_dlg
, get_panel_widget (first
));
1906 add_widget (midnight_dlg
, get_panel_widget (second
));
1907 add_widget (midnight_dlg
, the_menubar
);
1911 /* Run the Midnight Commander if no file was specified in the command line */
1912 run_dlg (midnight_dlg
);
1915 /* result must be free'd (I think this should go in util.c) */
1917 prepend_cwd_on_local (char *filename
)
1922 if (vfs_file_is_local (filename
)) {
1923 if (*filename
== PATH_SEP
) /* an absolute pathname */
1924 return g_strdup (filename
);
1925 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1926 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1929 strcpy (d
+ l
, filename
);
1930 return canonicalize_pathname (d
);
1932 return g_strdup (filename
);
1936 mc_maybe_editor_or_viewer (void)
1940 if (!(view_one_file
|| edit_one_file
))
1943 /* Invoke the internal view/edit routine with:
1944 * the default processing and forcing the internal viewer/editor
1946 if (view_one_file
) {
1947 path
= prepend_cwd_on_local (view_one_file
);
1948 setup_dummy_mc (path
);
1949 view_file (path
, 0, 1);
1951 #ifdef USE_INTERNAL_EDIT
1953 path
= prepend_cwd_on_local ("");
1954 setup_dummy_mc (path
);
1955 edit (edit_one_file
, edit_one_file_start_line
);
1957 #endif /* USE_INTERNAL_EDIT */
1959 midnight_shutdown
= 1;
1964 /* Run the main dialog that occupies the whole screen */
1968 int midnight_colors
[4];
1970 midnight_colors
[0] = NORMAL_COLOR
; /* NORMALC */
1971 midnight_colors
[1] = REVERSE_COLOR
; /* FOCUSC */
1972 midnight_colors
[2] = INPUT_COLOR
; /* HOT_NORMALC */
1973 midnight_colors
[3] = NORMAL_COLOR
; /* HOT_FOCUSC */
1976 create_dlg (0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1977 "[main]", NULL
, DLG_HAS_MENUBAR
);
1979 /* Check if we were invoked as an editor or file viewer */
1980 if (mc_maybe_editor_or_viewer ())
1985 setup_panels_and_run_mc ();
1988 midnight_shutdown
= 1;
1990 /* destroy_dlg destroys even cpanel->cwd, so we have to save a copy :) */
1991 if (last_wd_file
&& vfs_current_is_local ()) {
1992 last_wd_string
= g_strdup (cpanel
->cwd
);
1996 destroy_dlg (midnight_dlg
);
2001 #if defined (NATIVE_WIN32)
2002 /* Windows NT code */
2007 SetConsoleTitle ("GNU Midnight Commander");
2009 shell
= getenv ("COMSPEC");
2010 if (!shell
|| !*shell
)
2011 shell
= get_default_shell ();
2013 /* Default opening mode for files is binary, not text (CR/LF translation) */
2018 mc_home
= get_mc_lib_dir ();
2021 /* Nothing to be done on Windows */
2023 sigchld_handler_no_subshell (int sig
)
2033 init_sigfatals (void)
2045 shell
= getenv ("SHELL");
2046 if (!shell
|| !*shell
)
2047 shell
= g_strdup (getpwuid (geteuid ())->pw_shell
);
2048 if (!shell
|| !*shell
)
2051 /* This is the directory, where MC was installed, on Unix this is DATADIR */
2052 /* and can be overriden by the MC_DATADIR environment variable */
2053 if ((mc_libdir
= getenv ("MC_DATADIR")) != NULL
) {
2054 mc_home
= g_strdup (mc_libdir
);
2056 mc_home
= g_strdup (DATADIR
);
2061 sigchld_handler_no_subshell (int sig
)
2063 #if defined(linux) || defined(__linux__)
2069 /* COMMENT: if it were true that after the call to handle_console(..INIT)
2070 the value of console_flag never changed, we could simply not install
2071 this handler at all if (!console_flag && !use_subshell). */
2073 /* That comment is no longer true. We need to wait() on a sigchld
2074 handler (that's at least what the tarfs code expects currently). */
2076 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
2078 if (pid
== cons_saver_pid
) {
2080 if (WIFSTOPPED (status
)) {
2081 /* Someone has stopped cons.saver - restart it */
2082 kill (pid
, SIGCONT
);
2084 /* cons.saver has died - disable console saving */
2085 handle_console (CONSOLE_DONE
);
2089 #endif /* linux || __linux__ */
2091 /* If we get here, some other child exited; ignore it */
2097 struct sigaction sigchld_action
;
2099 sigchld_action
.sa_handler
=
2100 #ifdef HAVE_SUBSHELL_SUPPORT
2101 use_subshell
? sigchld_handler
:
2102 #endif /* HAVE_SUBSHELL_SUPPORT */
2103 sigchld_handler_no_subshell
;
2105 sigemptyset (&sigchld_action
.sa_mask
);
2108 sigchld_action
.sa_flags
= SA_RESTART
;
2110 sigchld_action
.sa_flags
= 0;
2111 #endif /* !SA_RESTART */
2113 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1) {
2114 #ifdef HAVE_SUBSHELL_SUPPORT
2116 * This may happen on QNX Neutrino 6, where SA_RESTART
2117 * is defined but not implemented. Fallback to no subshell.
2120 #endif /* HAVE_SUBSHELL_SUPPORT */
2124 #endif /* NATIVE_WIN32, UNIX */
2127 print_mc_usage (poptContext ctx
, FILE *stream
)
2131 poptSetOtherOptionHelp (ctx
,
2132 _("[flags] [this_dir] [other_panel_dir]\n"));
2134 /* print help for options */
2135 leftColWidth
= poptPrintHelp (ctx
, stream
, 0);
2136 fprintf (stream
, " %-*s %s\n", leftColWidth
, _("+number"),
2137 _("Set initial line number for the internal editor"));
2140 "Please send any bug reports (including the output of `mc -V')\n"
2141 "to mc-devel@gnome.org\n"), stream
);
2146 print_color_usage (void)
2149 * FIXME: undocumented keywords: viewunderline, editnormal, editbold,
2150 * and editmarked. To preserve translations, lines should be split.
2152 /* TRANSLATORS: don't translate keywords and names of colors */
2154 ("--colors KEYWORD={FORE},{BACK}\n\n"
2155 "{FORE} and {BACK} can be omitted, and the default will be used\n"
2157 " Global: errors, reverse, gauge, input\n"
2158 " File display: normal, selected, marked, markselect\n"
2159 " Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus\n"
2160 " Menus: menu, menuhot, menusel, menuhotsel\n"
2161 " Help: helpnormal, helpitalic, helplink, helpslink\n"
2162 " File types: directory, executable, link, stalelink, device, special, core\n"
2164 " black, gray, red, brightred, green, brightgreen, brown,\n"
2165 " yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
2166 " brightcyan, lightgray and white\n\n"), stdout
);
2170 process_args (poptContext ctx
, int c
, const char *option_arg
)
2182 #endif /* HAVE_SLANG */
2186 printf ("%s\n", mc_home
);
2192 ftpfs_set_debug (option_arg
);
2194 smbfs_set_debugf (option_arg
);
2195 #endif /* WITH_SMBFS */
2200 smbfs_set_debug (atoi (option_arg
));
2202 #endif /* WITH_SMBFS */
2203 #endif /* USE_NETCODE */
2206 use_mouse_p
= MOUSE_DISABLED
;
2209 #ifdef HAVE_SUBSHELL_SUPPORT
2213 #endif /* HAVE_SUBSHELL_SUPPORT */
2216 print_color_usage ();
2221 print_mc_usage (ctx
, stdout
);
2226 static const struct poptOption argument_table
[] = {
2227 #ifdef WITH_BACKGROUND
2228 {"background", 'B', POPT_ARG_NONE
, &background_wait
, 0,
2229 N_("Use to debug the background code")},
2231 {"color", 'c', POPT_ARG_NONE
, NULL
, 'c',
2232 N_("Request to run in color mode")},
2233 {"colors", 'C', POPT_ARG_STRING
, &command_line_colors
, 0,
2234 N_("Specifies a color configuration")},
2236 #ifdef USE_INTERNAL_EDIT
2237 {"edit", 'e', POPT_ARG_STRING
, &edit_one_file
, 0,
2238 N_("Edits one file")},
2241 {"help", 'h', POPT_ARG_NONE
, NULL
, 'h',
2242 N_("Displays this help message")},
2243 {"help-colors", 'H', POPT_ARG_NONE
, NULL
, 'H',
2244 N_("Displays a help screen on how to change the color scheme")},
2246 {"ftplog", 'l', POPT_ARG_STRING
, NULL
, 'l',
2247 N_("Log ftp dialog to specified file")},
2249 {"debuglevel", 'D', POPT_ARG_STRING
, NULL
, 'D',
2250 N_("Set debug level")},
2253 {"datadir", 'f', POPT_ARG_NONE
, NULL
, 'f',
2254 N_("Print data directory")},
2255 {"nocolor", 'b', POPT_ARG_NONE
, &disable_colors
, 0,
2256 N_("Requests to run in black and white")},
2257 {"nomouse", 'd', POPT_ARG_NONE
, NULL
, 'd',
2258 N_("Disable mouse support in text version")},
2259 #ifdef HAVE_SUBSHELL_SUPPORT
2260 {"nosubshell", 'u', POPT_ARG_NONE
, NULL
, 'u',
2261 N_("Disables subshell support")},
2262 {"forceexec", 'r', POPT_ARG_NONE
, &force_subshell_execution
, 0,
2263 N_("Force subshell execution")},
2265 {"printwd", 'P', POPT_ARG_STRING
, &last_wd_file
, 0,
2266 N_("Print last working directory to specified file")},
2267 {"resetsoft", 'k', POPT_ARG_NONE
, &reset_hp_softkeys
, 0,
2268 N_("Resets soft keys on HP terminals")},
2269 {"slow", 's', POPT_ARG_NONE
, &slow_terminal
, 0,
2270 N_("To run on slow terminals")},
2271 #ifndef NATIVE_WIN32
2272 {"stickchars", 'a', 0, &force_ugly_line_drawing
, 0,
2273 N_("Use stickchars to draw")},
2274 #endif /* !NATIVE_WIN32 */
2275 #ifdef HAVE_SUBSHELL_SUPPORT
2276 {"subshell", 'U', POPT_ARG_NONE
, &use_subshell
, 0,
2277 N_("Enables subshell support (default)")},
2279 #if defined(HAVE_SLANG) && !defined(NATIVE_WIN32)
2280 {"termcap", 't', 0, &SLtt_Try_Termcap
, 0,
2281 N_("Tries to use termcap instead of terminfo")},
2283 {"version", 'V', POPT_ARG_NONE
, NULL
, 'V',
2284 N_("Displays the current version")},
2285 {"view", 'v', POPT_ARG_STRING
, &view_one_file
, 0,
2286 N_("Launches the file viewer on a file")},
2287 {"xterm", 'x', POPT_ARG_NONE
, &force_xterm
, 0,
2288 N_("Forces xterm features")},
2290 {NULL
, 0, 0, NULL
, 0}
2294 handle_args (int argc
, char *argv
[])
2302 poptGetContext ("mc", argc
, argv
, argument_table
,
2303 POPT_CONTEXT_NO_EXEC
);
2306 SLtt_Try_Termcap
= 1;
2309 while ((c
= poptGetNextOpt (ctx
)) > 0) {
2310 process_args (ctx
, c
, poptGetOptArg (ctx
));
2314 print_mc_usage (ctx
, stderr
);
2315 fprintf (stderr
, "%s: %s\n",
2316 poptBadOption (ctx
, POPT_BADOPTION_NOALIAS
),
2321 tmp
= poptGetArg (ctx
);
2324 * Check for special invocation names mcedit and mcview,
2325 * if none apply then set the current directory and the other
2326 * directory from the command line arguments
2328 base
= x_basename (argv
[0]);
2329 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP (base
, "vi")) {
2332 if (*tmp
== '+' && isdigit ((unsigned char) tmp
[1])) {
2333 int start_line
= atoi (tmp
);
2334 if (start_line
> 0) {
2335 char *file
= poptGetArg (ctx
);
2338 edit_one_file_start_line
= start_line
;
2342 edit_one_file
= g_strdup (tmp
);
2344 } else if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP (base
, "view")) {
2346 view_one_file
= g_strdup (tmp
);
2348 fputs ("No arguments given to the viewer\n", stderr
);
2352 /* sets the current dir and the other dir */
2354 this_dir
= g_strdup (tmp
);
2355 if ((tmp
= poptGetArg (ctx
)))
2356 other_dir
= g_strdup (tmp
);
2360 poptFreeContext (ctx
);
2364 * The compatibility_move_mc_files routine is intended to
2365 * move all of the hidden .mc files into a private ~/.mc
2366 * directory in the home directory, to avoid cluttering the users.
2368 * Previous versions of the program had all of their files in
2369 * the $HOME, we are now putting them in $HOME/.mc
2372 # define compatibility_move_mc_files() 0
2376 do_mc_filename_rename (char *mc_dir
, char *o_name
, char *n_name
)
2378 char *full_o_name
= concat_dir_and_file (home_dir
, o_name
);
2379 char *full_n_name
= g_strconcat (home_dir
, MC_BASE
, n_name
, NULL
);
2382 move
= 0 == rename (full_o_name
, full_n_name
);
2383 g_free (full_o_name
);
2384 g_free (full_n_name
);
2389 compatibility_move_mc_files (void)
2393 char *mc_dir
= concat_dir_and_file (home_dir
, ".mc");
2395 if (stat (mc_dir
, &s
) && (errno
== ENOENT
)
2396 && (mkdir (mc_dir
, 0777) != -1)) {
2398 move
= do_mc_filename_rename (mc_dir
, ".mc.ini", "ini");
2399 move
+= do_mc_filename_rename (mc_dir
, ".mc.hot", "hotlist");
2400 move
+= do_mc_filename_rename (mc_dir
, ".mc.ext", "bindings");
2401 move
+= do_mc_filename_rename (mc_dir
, ".mc.menu", "menu");
2402 move
+= do_mc_filename_rename (mc_dir
, ".mc.bashrc", "bashrc");
2403 move
+= do_mc_filename_rename (mc_dir
, ".mc.inputrc", "inputrc");
2404 move
+= do_mc_filename_rename (mc_dir
, ".mc.tcshrc", "tcshrc");
2405 move
+= do_mc_filename_rename (mc_dir
, ".mc.tree", "Tree");
2410 #endif /* NATIVE_WIN32 */
2413 main (int argc
, char *argv
[])
2415 /* if on, it displays the information that files have been moved to ~/.mc */
2416 int show_change_notice
= 0;
2418 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2419 setlocale (LC_ALL
, "");
2420 bindtextdomain ("mc", LOCALEDIR
);
2423 /* Initialize list of all user group for timur_clr_mode */
2426 /* Set up temporary directory */
2431 /* This variable is used by the subshell */
2432 home_dir
= getenv ("HOME");
2434 /* mc_home was computed by OS_Setup */
2441 SLtt_Ignore_Beep
= 1;
2444 /* NOTE: This has to be called before slang_init or whatever routine
2445 calls any define_sequence */
2448 handle_args (argc
, argv
);
2450 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
2451 handle_console (CONSOLE_INIT
);
2453 #ifdef HAVE_SUBSHELL_SUPPORT
2454 /* Don't use subshell when invoked as viewer or editor */
2455 if (edit_one_file
|| view_one_file
)
2459 subshell_get_console_attributes ();
2460 #endif /* HAVE_SUBSHELL_SUPPORT */
2462 /* Install the SIGCHLD handler; must be done before init_subshell() */
2465 show_change_notice
= compatibility_move_mc_files ();
2467 /* We need this, since ncurses endwin () doesn't restore the signals */
2468 save_stop_handler ();
2470 /* Must be done before init_subshell, to set up the terminal size: */
2471 /* FIXME: Should be removed and LINES and COLS computed on subshell */
2475 /* NOTE: This call has to be after slang_init. It's the small part from
2476 the previous init_key which had to be moved after the call of slang_init */
2477 init_key_input_fd ();
2483 init_xterm_support ();
2485 #ifdef HAVE_SUBSHELL_SUPPORT
2487 /* Done here to ensure that the subshell doesn't */
2488 /* inherit the file descriptors opened below, etc */
2492 #endif /* HAVE_SUBSHELL_SUPPORT */
2494 /* Removing this from the X code let's us type C-c */
2497 /* Also done after init_subshell, to save any shell init file messages */
2499 handle_console (CONSOLE_SAVE
);
2501 if (alternate_plus_minus
)
2502 application_keypad_mode ();
2504 if (show_change_notice
) {
2505 message (1, _(" Notice "),
2506 _(" The Midnight Commander configuration files \n"
2507 " are now stored in the ~/.mc directory, the \n"
2508 " files have been moved now\n"));
2510 #ifdef HAVE_SUBSHELL_SUPPORT
2512 prompt
= strip_ctrl_codes (subshell_prompt
);
2516 #endif /* HAVE_SUBSHELL_SUPPORT */
2517 prompt
= (geteuid () == 0) ? "# " : "$ ";
2519 /* Program main loop */
2522 /* Save the tree store */
2525 /* Virtual File System shutdown */
2528 /* Delete list of all user groups */
2531 flush_extension_file (); /* does only free memory */
2538 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2540 if (alternate_plus_minus
)
2541 numeric_keypad_mode ();
2543 #ifndef NATIVE_WIN32
2544 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2548 handle_console (CONSOLE_DONE
);
2549 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2552 /* On NT, home_dir is malloced */
2555 if (last_wd_file
&& last_wd_string
&& !print_last_revert
2556 && !edit_one_file
&& !view_one_file
) {
2558 open (last_wd_file
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_EXCL
,
2561 if (last_wd_fd
!= -1) {
2562 write (last_wd_fd
, last_wd_string
, strlen (last_wd_string
));
2566 g_free (last_wd_string
);
2568 #ifndef NATIVE_WIN32
2570 #endif /* NATIVE_WIN32 */
2573 free_codepages_list ();