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., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 # define INCL_DOSFILEMGR
32 # define INCL_DOSERRORS
40 #include <sys/types.h>
41 #include <sys/param.h>
49 /* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
50 #if defined(HAVE_DIRENT_H) || defined(_POSIX_VERSION)
52 # define NLENGTH(dirent) (strlen ((dirent)->d_name))
54 # define dirent direct
55 # define NLENGTH(dirent) ((dirent)->d_namlen)
57 # ifdef HAVE_SYS_NDIR_H
58 # include <sys/ndir.h>
59 # endif /* HAVE_SYS_NDIR_H */
61 # ifdef HAVE_SYS_DIR_H
63 # endif /* HAVE_SYS_DIR_H */
67 # endif /* HAVE_NDIR_H */
68 #endif /* not (HAVE_DIRENT_H or _POSIX_VERSION) */
71 # include <sys/wait.h> /* For waitpid() */
79 #include <fcntl.h> /* For O_RDWR */
82 /* Program include files */
100 #include "cons.saver.h"
101 #include "subshell.h"
102 #include "key.h" /* For init_key() and mi_getch() */
103 #include "setup.h" /* save_setup() */
104 #include "profile.h" /* free_profiles() */
107 #include "cmd.h" /* Normal commands */
109 #include "panelize.h"
113 #include "listmode.h"
114 #include "background.h"
115 #include "ext.h" /* For flush_extension_file() */
117 /* Listbox for the command history feature */
121 #include "complete.h" /* For the free_completion */
131 #include "../vfs/vfs.h"
132 #include "../vfs/extfs.h"
139 /* When the modes are active, left_panel, right_panel and tree_panel */
140 /* Point to a proper data structure. You should check with the functions */
141 /* get_current_type and get_other_type the types of the panels before using */
142 /* This pointer variables */
144 /* The structures for the panels */
148 /* The pointer to the tree */
154 /* Pointers to the selected and unselected panel */
155 WPanel
*current_panel
= NULL
;
157 /* Set when we want use advanced chmod command instead of chmod and/or chown */
158 int advanced_chfns
= 0;
160 /* Set when main loop should be terminated */
161 volatile int quit
= 0;
163 /* Set if you want the possible completions dialog for the first time */
164 int show_all_if_ambiguous
= 0;
166 /* Set when cd symlink following is desirable (bash mode) */
169 /* If set then dialogs just clean the screen when refreshing, else */
170 /* they do a complete refresh, refreshing all the parts of the program */
171 int fast_refresh
= 0;
173 /* If true, marking a files moves the cursor down */
174 int mark_moves_down
= 1;
176 /* If true, at startup the user-menu is invoked */
179 /* If true, use + and \ keys normally and select/unselect do if M-+ / M-\ and M--
181 int alternate_plus_minus
= 0;
183 /* If true, then the +, - and \ keys have their special meaning only if the
184 * command line is emtpy, otherwise they behave like regular letters
186 int only_leading_plus_minus
= 1;
188 /* If true, after executing a command, wait for a keystroke */
189 enum { pause_never
, pause_on_dumb_terminals
, pause_always
};
191 int pause_after_run
= pause_on_dumb_terminals
;
193 /* It true saves the setup when quitting */
194 int auto_save_setup
= 1;
196 /* If true, be eight bit clean */
197 int eight_bit_clean
= 0;
199 /* If true, then display chars 0-255, else iso-8859-1,
200 requires eight_bit_clean */
201 int full_eight_bits
= 0;
203 /* If true use the internal viewer */
204 int use_internal_view
= 1;
206 /* Have we shown the fast-reload warning in the past? */
207 int fast_reload_w
= 0;
209 /* Move page/item? When clicking on the top or bottom of a panel */
210 int mouse_move_pages
= 1;
212 /* If true: l&r arrows are used to chdir if the input line is empty */
213 int navigate_with_arrows
= 0;
215 /* If it is set, the commander will iconify itself when executing a program */
216 int iconify_on_exec
= 1;
218 /* If true use +, -, | for line drawing */
219 int force_ugly_line_drawing
= 0;
221 /* If true message "The shell is already running a command" never */
222 int force_subshell_execution
= 0;
224 /* If true program softkeys (HP terminals only) on startup and after every
225 command ran in the subshell to the description found in the termcap/terminfo
227 int reset_hp_softkeys
= 0;
232 /* The widget where we draw the prompt */
242 WButtonBar
*the_bar2
;
245 /* For slow terminals */
246 int slow_terminal
= 0;
249 int use_mouse_p
= GPM_MOUSE
;
251 /* If true, assume we are running on an xterm terminal */
252 static int force_xterm
= 0;
254 /* Controls screen clearing before an exec */
255 int clear_before_exec
= 1;
257 /* Asks for confirmation before deleting a file */
258 int confirm_delete
= 1;
260 /* Asks for confirmation before overwriting a file */
261 int confirm_overwrite
= 1;
263 /* Asks for confirmation before executing a program by pressing enter */
264 int confirm_execute
= 0;
266 /* Asks for confirmation before leaving the program */
267 int confirm_exit
= 1;
269 /* Asks for confirmation when using F3 to view a directory and there
271 int confirm_view_dir
= 0;
273 /* This flag indicates if the pull down menus by default drop down */
276 /* The dialog handle for the main program */
277 Dlg_head
*midnight_dlg
;
279 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
280 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
281 int update_prompt
= 0;
283 /* The name which was used to invoke mc */
286 /* The home directory */
289 /* The value of the other directory, only used when loading the setup */
293 /* If true, then print on stdout the last directory we were at */
294 static int print_last_wd
= 0;
295 static char *last_wd_string
;
296 static int print_last_revert
= 0;
298 /* On OS/2 and on Windows NT, we need a batch file to do the -P magic */
300 static char *batch_file_name
= 0;
303 /* widget colors for the midnight commander */
304 int midnight_colors
[4];
306 /* Force colors, only used by Slang */
307 int force_colors
= 0;
309 /* colors specified on the command line: they override any other setting */
310 char *command_line_colors
;
312 /* File name to view if argument was supplied */
313 char *view_one_file
= 0;
315 /* File name to view if argument was supplied */
316 char *edit_one_file
= 0;
318 /* Used so that widgets know if they are being destroyed or
320 int midnight_shutdown
= 0;
322 /* to show nice prompts */
323 static int last_paused
= 0;
325 /* Only used at program boot */
326 int boot_current_is_left
= 1;
328 /* Used for keeping track of the original stdout */
331 /* The user's shell */
334 /* mc_home: The home of MC */
337 /* if on, it displays the information that files have been moved to ~/.mc */
338 int show_change_notice
= 0;
342 /* Used during argument processing */
343 int finish_program
= 0;
345 /* Forward declarations */
346 char *get_mc_lib_dir ();
347 int panel_event (Gpm_Event
*event
, WPanel
*panel
);
348 int menu_bar_event (Gpm_Event
*event
, void *);
349 static void menu_cmd (void);
355 return current_panel
;
361 return (WPanel
*) get_panel_widget (get_other_index ());
366 try_to_select (WPanel
*panel
, char *name
)
368 Xtry_to_select (panel
, name
);
370 display_mini_info (panel
);
376 * If we moved to the parent directory move the selection pointer to
377 * the old directory name
380 cd_try_to_select (WPanel
*panel
)
385 if (strlen (panel
->lwd
) > strlen (panel
->cwd
)
386 && strncmp (panel
->cwd
, panel
->lwd
, strlen (panel
->cwd
)) == 0
387 && strchr (panel
->lwd
+ strlen (panel
->cwd
) + 1, PATH_SEP
) == 0)
388 try_to_select (panel
, panel
->lwd
);
391 if ((!strncmp (panel
->lwd
, "tar:", 4) &&
392 !strncmp (panel
->lwd
+ 4, panel
->cwd
, strlen (panel
->cwd
))) ||
393 ((i
= extfs_prefix_to_type (panel
->lwd
)) != -1 &&
394 !strncmp (panel
->lwd
+ (j
= strlen (extfs_get_prefix (i
)) + 1),
395 panel
->cwd
, strlen (panel
->cwd
)))) {
396 p
= strdup (panel
->lwd
+ j
+ strlen (panel
->cwd
));
397 q
= strchr (p
, PATH_SEP
);
398 if (q
!= NULL
&& (q
!= p
|| (q
= strchr (q
+ 1, PATH_SEP
)) != NULL
))
400 try_to_select (panel
, p
);
404 try_to_select (panel
, NULL
);
408 reload_panelized (WPanel
*panel
)
411 dir_list
*list
= &panel
->dir
;
414 mc_chdir (panel
->cwd
);
416 for (i
= 0, j
= 0; i
< panel
->count
; i
++){
417 if (list
->list
[i
].f
.marked
) {
418 /* Unmark the file in advance. In case the following mc_lstat
419 * fails we are done, else we have to mark the file again
420 * (Note: do_file_mark depends on a valid "list->list [i].buf").
421 * IMO that's the best way to update the panel's summary status
424 do_file_mark (panel
, i
, 0);
426 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].buf
)){
427 free (list
->list
[i
].fname
);
430 if (list
->list
[i
].f
.marked
)
431 do_file_mark (panel
, i
, 1);
433 list
->list
[j
] = list
->list
[i
];
437 panel
->count
= set_zero_dir (list
);
442 mc_chdir (cpanel
->cwd
);
446 update_one_panel_widget (WPanel
*panel
, int force_update
, char *current_file
)
450 if (force_update
& UP_RELOAD
){
451 panel
->is_panelized
= 0;
454 bzero (&(panel
->dir_stat
), sizeof (panel
->dir_stat
));
457 /* If current_file == -1 (an invalid pointer) then preserve selection */
458 if (current_file
== UP_KEEPSEL
){
460 current_file
= strdup (panel
->dir
.list
[panel
->selected
].fname
);
464 if (panel
->is_panelized
)
465 reload_panelized (panel
);
467 panel_reload (panel
);
469 try_to_select (panel
, current_file
);
476 #ifndef PORT_HAS_UPDATE_PANELS
478 update_one_panel (int which
, int force_update
, char *current_file
)
482 if (get_display_type (which
) != view_listing
)
485 panel
= (WPanel
*) get_panel_widget (which
);
486 update_one_panel_widget (panel
, force_update
, current_file
);
489 /* This routine reloads the directory in both panels. It tries to
490 * select current_file in current_panel and other_file in other_panel.
491 * If current_file == -1 then it automatically sets current_file and
492 * other_file to the currently selected files in the panels.
494 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
495 * will not reload the other panel.
498 update_panels (int force_update
, char *current_file
)
500 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
503 update_one_panel (get_current_index (), force_update
, current_file
);
505 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
507 if (get_current_type () == view_listing
)
508 panel
= (WPanel
*) get_panel_widget (get_current_index ());
510 panel
= (WPanel
*) get_panel_widget (get_other_index ());
512 mc_chdir (panel
->cwd
);
517 static void select_by_index (WPanel
*panel
, int i
);
519 /* Called by parse_control_file */
520 static int index_by_name (file_entry
*list
, int count
)
525 name
= strtok (NULL
, " \t\n");
528 for (i
= 0; i
< count
; i
++){
529 if (strcmp (name
, list
[i
].fname
) == 0)
535 /* Called by parse_control_file */
536 static void select_by_index (WPanel
*panel
, int i
)
538 if (i
>= panel
->count
)
541 unselect_item (panel
);
545 while (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
546 /* Scroll window half screen */
547 panel
->top_file
+= ITEMS (panel
)/2;
551 while (panel
->selected
< panel
->top_file
){
552 /* Scroll window half screen */
553 panel
->top_file
-= ITEMS (panel
)/2;
554 if (panel
->top_file
< 0) panel
->top_file
= 0;
561 /* Called by my_system
562 No error reporting, just exits on the first sign of trouble */
563 static void parse_control_file (void)
565 char *data
, *current
;
572 if ((file
= fopen (control_file
, "r")) == NULL
){
575 /* Use of fstat prevents race conditions */
576 if (fstat (fileno (file
), &s
) != 0){
581 /* Security: Check that the user owns the control file to prevent
582 other users from playing tricks on him/her. */
583 if (s
.st_uid
!= getuid ()){
588 data
= (char *) xmalloc (s
.st_size
+1, "main, parse_control_file");
593 if (s
.st_size
!= fread (data
, 1, s
.st_size
, file
)){
598 data
[s
.st_size
] = 0;
601 /* The Control file has now been loaded to memory -> start parsing. */
602 current
= strtok (data
, " \t\n");
603 while (current
&& *current
){
604 if (isupper (*current
)){
605 if (get_other_type () != view_listing
)
612 list
= panel
->dir
.list
;
613 *current
= tolower (*current
);
615 if (strcmp (current
, "clear_tags") == 0){
616 unmark_files (panel
);
617 } else if (strcmp (current
, "tag") == 0){
618 i
= index_by_name (list
, panel
->count
);
620 do_file_mark (panel
, i
, 1);
622 } else if (strcmp (current
, "untag") == 0){
623 i
= index_by_name (list
, panel
->count
);
625 do_file_mark (panel
, i
, 0);
627 } else if (strcmp (current
, "select") == 0){
628 i
= index_by_name (list
, panel
->count
);
630 select_by_index (panel
, i
);
632 } else if (strcmp (current
, "change_panel") == 0){
634 } else if (strcmp (current
, "cd") == 0){
636 current
= strtok (NULL
, " \t\n");
638 if (cpanel
!= panel
){
642 do_cd (current
, cd_parse_command
);
646 /* Unknown command -> let's give up */
649 current
= strtok (NULL
, " \t\n");
653 paint_panel (cpanel
);
654 paint_panel (opanel
);
657 #define parse_control_file()
658 #endif /* WANT_PARSE */
660 /* Sets up the terminal before executing a program */
668 /* Save current stat of directories to avoid reloading the panels */
669 /* when no modifications have taken place */
671 save_cwds_stat (void)
674 mc_stat (cpanel
->cwd
, &(cpanel
->dir_stat
));
675 if (get_other_type () == view_listing
)
676 mc_stat (opanel
->cwd
, &(opanel
->dir_stat
));
680 #ifdef HAVE_SUBSHELL_SUPPORT
682 do_possible_cd (char *new_dir
)
684 if (!do_cd (new_dir
, cd_exact
))
685 message (1, _(" Warning "),
686 _(" The Commander can't change to the directory that \n"
687 " the subshell claims you are in. Perhaps you have \n"
688 " deleted your working directory, or given yourself \n"
689 " extra access permissions with the \"su\" command? "));
696 printf ("%s", subshell_prompt
);
704 restore_console (void)
706 handle_console (CONSOLE_RESTORE
);
712 do_execute (shell
, 0, 0);
716 do_execute (const char *shell
, const char *command
, int flags
)
718 #ifdef HAVE_SUBSHELL_SUPPORT
719 char *new_dir
= NULL
;
723 char *old_vfs_dir
= 0;
725 if (!vfs_current_is_local ())
726 old_vfs_dir
= strdup (vfs_get_current_dir ());
735 unlink (control_file
);
737 if (!use_subshell
&& !(flags
& EXECUTE_INTERNAL
)){
738 printf ("%s%s%s\n", last_paused
? "\r\n":"", prompt
, command
);
742 #ifdef HAVE_SUBSHELL_SUPPORT
743 if (use_subshell
&& !(flags
& EXECUTE_INTERNAL
)){
746 /* We don't care if it died, higher level takes care of this */
748 invoke_subshell (command
, VISIBLY
, old_vfs_dir
? 0 : &new_dir
);
750 invoke_subshell (command
, VISIBLY
, &new_dir
);
754 my_system (flags
, shell
, command
);
757 if (!(flags
& EXECUTE_INTERNAL
)){
758 if ((pause_after_run
== pause_always
||
759 (pause_after_run
== pause_on_dumb_terminals
&&
760 !xterm_flag
&& !console_flag
)) && !quit
){
761 printf (_("Press any key to continue..."));
768 if (output_lines
&& keybar_visible
) {
777 handle_console (CONSOLE_SAVE
);
778 edition_post_exec ();
780 #ifdef HAVE_SUBSHELL_SUPPORT
782 do_possible_cd (new_dir
);
787 mc_chdir (old_vfs_dir
);
792 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
794 parse_control_file ();
796 unlink (control_file
);
802 /* Executes a command */
804 shell_execute (char *command
, int flags
)
806 #ifdef HAVE_SUBSHELL_SUPPORT
808 if (subshell_state
== INACTIVE
|| force_subshell_execution
)
809 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
811 message (1, MSG_ERROR
, _(" The shell is already running a command "));
814 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
818 execute (char *command
)
820 shell_execute (command
, 0);
826 free_completions (input_w (cmdline
));
827 dlg_one_down (midnight_dlg
);
831 quit_cmd_internal (int quiet
)
835 if (quiet
|| !confirm_exit
){
838 if (query_dialog (_(" The Midnight Commander "),
839 _(" Do you really want to quit the Midnight Commander? "),
840 0, 2, _("&Yes"), _("&No")) == 0)
844 #ifdef HAVE_SUBSHELL_SUPPORT
846 midnight_dlg
->running
= 0;
848 if ((q
= exit_subshell ()))
850 midnight_dlg
->running
= 0;
859 quit_cmd_internal (0);
863 int quiet_quit_cmd (void)
865 print_last_revert
= 1;
866 quit_cmd_internal (1);
871 * Touch window and refresh window functions
874 /* This routine untouches the first line on both panels in order */
875 /* to avoid the refreshing the menu bar */
884 repaint_screen (void)
897 repaint_screen (void)
904 /* Wrapper for do_subshell_chdir, check for availability of subshell */
906 subshell_chdir (char *directory
)
908 #ifdef HAVE_SUBSHELL_SUPPORT
910 if (vfs_current_is_local ())
911 do_subshell_chdir (directory
, 0, 1);
917 directory_history_add (WPanel
* panel
, char *s
)
919 if (!panel
->dir_history
) {
920 panel
->dir_history
= malloc (sizeof (Hist
));
921 memset (panel
->dir_history
, 0, sizeof (Hist
));
922 panel
->dir_history
->text
= strdup (s
);
925 if (!strcmp (panel
->dir_history
->text
, s
))
927 if (panel
->dir_history
->next
) {
928 if (panel
->dir_history
->next
->text
) {
929 free (panel
->dir_history
->next
->text
);
930 panel
->dir_history
->next
->text
= 0;
933 panel
->dir_history
->next
= malloc (sizeof (Hist
));
934 memset (panel
->dir_history
->next
, 0, sizeof (Hist
));
935 panel
->dir_history
->next
->prev
= panel
->dir_history
;
937 panel
->dir_history
= panel
->dir_history
->next
;
938 panel
->dir_history
->text
= strdup (s
);
940 panel_update_marks (panel
);
943 /* Changes the current panel directory */
945 _do_panel_cd (WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
947 char *directory
, *olddir
;
948 char temp
[MC_MAXPATHLEN
];
952 struct vfs_stamping
*parent
;
954 olddir
= strdup (panel
->cwd
);
956 /* Convert *new_path to a suitable pathname, handle ~user */
958 if (cd_type
== cd_parse_command
){
959 while (*new_dir
== ' ')
962 if (!strcmp (new_dir
, "-")){
963 strcpy (temp
, panel
->lwd
);
967 directory
= *new_dir
? new_dir
: home_dir
;
969 if (mc_chdir (directory
) == -1){
970 strcpy (panel
->cwd
, olddir
);
975 /* Success: save previous directory, shutdown status of previous dir */
976 strcpy (panel
->lwd
, olddir
);
977 free_completions (input_w (cmdline
));
979 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
982 oldvfs
= vfs_type (olddir
);
983 oldvfsid
= vfs_ncs_getid (oldvfs
, olddir
, &parent
);
984 vfs_add_noncurrent_stamps (oldvfs
, oldvfsid
, parent
);
985 vfs_rm_parents (parent
);
989 subshell_chdir (panel
->cwd
);
991 /* Reload current panel */
992 clean_dir (&panel
->dir
, panel
->count
);
993 panel
->count
= do_load_dir (&panel
->dir
, panel
->sort_type
,
994 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
998 panel
->dirs_marked
= 0;
1000 panel
->searching
= 0;
1001 cd_try_to_select (panel
);
1003 panel_update_contents (panel
);
1008 do_panel_cd (WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
1012 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
1014 directory_history_add (cpanel
, cpanel
->cwd
);
1019 do_cd (char *new_dir
, enum cd_enum exact
)
1021 return (do_panel_cd (cpanel
, new_dir
, exact
));
1025 directory_history_next (WPanel
* panel
)
1027 if (!panel
->dir_history
->next
)
1029 if (_do_panel_cd (panel
, panel
->dir_history
->next
->text
, cd_exact
))
1030 panel
->dir_history
= panel
->dir_history
->next
;
1031 panel_update_marks (panel
);
1035 directory_history_prev (WPanel
* panel
)
1037 if (!panel
->dir_history
->prev
)
1039 if (_do_panel_cd (panel
, panel
->dir_history
->prev
->text
, cd_exact
))
1040 panel
->dir_history
= panel
->dir_history
->prev
;
1041 panel_update_marks (panel
);
1045 directory_history_list (WPanel
* panel
)
1048 /* must be at least two to show a history */
1049 if (panel
->dir_history
) {
1050 if (panel
->dir_history
->prev
|| panel
->dir_history
->next
) {
1051 s
= show_hist (panel
->dir_history
, panel
->widget
.x
, panel
->widget
.y
);
1054 r
= _do_panel_cd (panel
, s
, cd_exact
);
1056 directory_history_add (panel
, panel
->cwd
);
1063 #ifdef HAVE_SUBSHELL_SUPPORT
1065 load_prompt (int fd
, void *unused
)
1067 if (!read_subshell_prompt (QUIETLY
))
1070 if (command_prompt
){
1073 prompt
= strip_ctrl_codes (subshell_prompt
);
1074 prompt_len
= strlen (prompt
);
1076 /* Check for prompts too big */
1077 if (prompt_len
> COLS
- 8) {
1078 prompt
[COLS
- 8 ] = 0;
1079 prompt_len
= COLS
- 8;
1081 label_set_text (the_prompt
, prompt
);
1082 winput_set_origin ((WInput
*)cmdline
, prompt_len
, COLS
-prompt_len
);
1084 /* since the prompt has changed, and we are called from one of the
1085 * get_event channels, the prompt updating does not take place
1086 * automatically: force a cursor update and a screen refresh
1088 if (current_dlg
== midnight_dlg
){
1089 update_cursor (midnight_dlg
);
1098 /* The user pressed the enter key */
1100 menu_bar_event (Gpm_Event
*event
, void *x
)
1102 if (event
->type
!= GPM_DOWN
)
1108 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1110 maybe_cd (int char_code
, int move_up_dir
)
1112 if (navigate_with_arrows
){
1113 if (!input_w (cmdline
)->buffer
[0]){
1115 do_cd ("..", cd_exact
);
1118 if (S_ISDIR (selection (cpanel
)->buf
.st_mode
)
1119 || link_isdir (selection (cpanel
))){
1120 do_cd (selection (cpanel
)->fname
, cd_exact
);
1129 set_sort_to (WPanel
*p
, sortfn
*sort_order
)
1131 p
->sort_type
= sort_order
;
1133 /* The directory is already sorted, we have to load the unsorted stuff */
1134 if (sort_order
== (sortfn
*) unsorted
){
1137 current_file
= strdup (cpanel
->dir
.list
[cpanel
->selected
].fname
);
1138 panel_reload (cpanel
);
1139 try_to_select (cpanel
, current_file
);
1140 free (current_file
);
1151 if (!SELECTED_IS_PANEL
)
1155 sort_order
= sort_box (p
->sort_type
, &p
->reverse
, &p
->case_sensitive
);
1157 if (sort_order
== 0)
1160 p
->sort_type
= sort_order
;
1162 /* The directory is already sorted, we have to load the unsorted stuff */
1163 if (sort_order
== (sortfn
*) unsorted
){
1166 current_file
= strdup (cpanel
->dir
.list
[cpanel
->selected
].fname
);
1167 panel_reload (cpanel
);
1168 try_to_select (cpanel
, current_file
);
1169 free (current_file
);
1179 sel_dir
= tree (selection (cpanel
)->fname
);
1181 do_cd(sel_dir
, cd_exact
);
1186 #if SOMEDAY_WE_WILL_FINISH_THIS_CODE
1191 newmode
= listmode_edit ("half <type,>name,|,size:8,|,perm:4+");
1192 message (0, " Listing format edit ", " New mode is \"%s\" ", newmode
);
1198 void init_menu () {};
1199 void done_menu () {};
1201 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
1202 static menu_entry PanelMenu
[] = {
1203 { ' ', N_("&Listing mode..."), 'L', listing_cmd
},
1204 { ' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
1205 { ' ', N_("&Info C-x i"), 'I', info_cmd
},
1206 { ' ', N_("&Tree"), 'T', tree_cmd
},
1207 { ' ', "", ' ', 0 },
1208 { ' ', N_("&Sort order..."), 'S', sort_cmd
},
1209 { ' ', "", ' ', 0 },
1210 { ' ', N_("&Filter..."), 'F', filter_cmd
},
1212 { ' ', "", ' ', 0 },
1213 { ' ', N_("&Network link..."), 'N', netlink_cmd
},
1214 { ' ', N_("FT&P link..."), 'P', ftplink_cmd
},
1216 { ' ', "", ' ', 0 },
1218 { ' ', N_("&Drive... M-d"), 'D', drive_cmd_a
},
1220 { ' ', N_("&Rescan C-r"), 'R', reread_cmd
}
1223 static menu_entry RightMenu
[] = {
1224 { ' ', N_("&Listing mode..."), 'L', listing_cmd
},
1225 { ' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
1226 { ' ', N_("&Info C-x i"), 'I', info_cmd
},
1227 { ' ', N_("&Tree"), 'T', tree_cmd
},
1228 { ' ', "", ' ', 0 },
1229 { ' ', N_("&Sort order..."), 'S', sort_cmd
},
1230 { ' ', "", ' ', 0 },
1231 { ' ', N_("&Filter..."), 'F', filter_cmd
},
1233 { ' ', "", ' ', 0 },
1234 { ' ', N_("&Network link..."), 'N', netlink_cmd
},
1235 { ' ', N_("FT&P link..."), 'P', ftplink_cmd
},
1237 { ' ', "", ' ', 0 },
1239 { ' ', N_("&Drive... M-d"), 'D', drive_cmd_b
},
1241 { ' ', N_("&Rescan C-r"), 'R', reread_cmd
}
1244 static menu_entry FileMenu
[] = {
1245 { ' ', N_("&User menu F2"), 'U', user_menu_cmd
},
1246 { ' ', N_("&View F3"), 'V', view_cmd
},
1247 { ' ', N_("&Filtered view M-!"), 'F', filtered_view_cmd
},
1248 { ' ', N_("&Edit F4"), 'E', edit_cmd
},
1249 { ' ', N_("&Copy F5"), 'C', copy_cmd
},
1250 { ' ', N_("c&Hmod C-x c"), 'H', chmod_cmd
},
1252 { ' ', N_("&Link C-x l"), 'L', link_cmd
},
1253 { ' ', N_("&SymLink C-x s"), 'S', symlink_cmd
},
1254 { ' ', N_("edit s&Ymlink C-x C-s"), 'Y', edit_symlink_cmd
},
1255 { ' ', N_("ch&Own C-x o"), 'O', chown_cmd
},
1256 { ' ', N_("&Advanced chown "), 'A', chown_advanced_cmd
},
1258 { ' ', N_("&Rename/Move F6"), 'R', ren_cmd
},
1259 { ' ', N_("&Mkdir F7"), 'M', mkdir_cmd
},
1260 { ' ', N_("&Delete F8"), 'D', delete_cmd
},
1261 { ' ', N_("&Quick cd M-c"), 'Q', quick_cd_cmd
},
1262 { ' ', "", ' ', 0 },
1263 { ' ', N_("select &Group M-+"), 'G', select_cmd
},
1264 { ' ', N_("u&Nselect group M-\\"),'N', unselect_cmd
},
1265 { ' ', N_("reverse selec&Tion M-*"), 'T', reverse_selection_cmd
},
1266 { ' ', "", ' ', 0 },
1267 { ' ', N_("e&Xit F10"), 'X', (callfn
) quit_cmd
}
1270 void external_panelize (void);
1271 static menu_entry CmdMenu
[] = {
1272 /* I know, I'm lazy, but the tree widget when it's not running
1273 * as a panel still has some problems, I have not yet finished
1274 * the WTree widget port, sorry.
1276 { ' ', N_("&Directory tree"), 'D', tree_box
},
1277 { ' ', N_("&Find file M-?"), 'F', find_cmd
},
1279 { ' ', N_("s&Wap panels C-u"), 'W', swap_cmd
},
1280 { ' ', N_("switch &Panels on/off C-o"), 'P', view_other_cmd
},
1282 { ' ', N_("&Compare directories C-x d"), 'C', compare_dirs_cmd
},
1283 { ' ', N_("e&Xternal panelize C-x !"), 'X', external_panelize
},
1285 { ' ', N_("show directory s&Izes"), 'I', dirsizes_cmd
},
1287 { ' ', "", ' ', 0 },
1288 { ' ', N_("command &History"), 'H', history_cmd
},
1289 { ' ', N_("di&Rectory hotlist C-\\"), 'R', quick_chdir_cmd
},
1291 { ' ', N_("&Active VFS list C-x a"), 'A', reselect_vfs
},
1293 #ifdef WITH_BACKGROUND
1294 { ' ', N_("&Background jobs C-x j"), 'B', jobs_cmd
},
1296 { ' ', "", ' ', 0 },
1297 #ifdef USE_EXT2FSLIB
1298 { ' ', N_("&Undelete files (ext2fs only)"), 'U', undelete_cmd
},
1301 { ' ', N_("&Listing format edit"), 'L', listmode_cmd
},
1303 { ' ', N_("&Extension file edit"), 'E', ext_cmd
},
1304 { ' ', N_("&Menu file edit"), 'M', menu_edit_cmd
}
1307 /* Must keep in sync with the constants in menu_cmd */
1308 static menu_entry OptMenu
[] = {
1309 { ' ', N_("&Configuration..."), 'C', configure_box
},
1310 { ' ', N_("&Layout..."), 'L', layout_cmd
},
1311 { ' ', N_("c&Onfirmation..."), 'O', confirm_box
},
1312 { ' ', N_("&Display bits..."), 'D', display_bits_box
},
1313 #if !defined(HAVE_X) && !defined(OS2_NT)
1314 { ' ', N_("learn &Keys..."), 'K', learn_keys
},
1317 { ' ', N_("&Virtual FS..."), 'V', configure_vfs
},
1319 { ' ', "", ' ', 0 },
1320 { ' ', N_("&Save setup"), 'S', save_setup_cmd
}
1323 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
1327 static Menu MenuBarEmpty
[5];
1336 MenuBar
[0] = create_menu (_(" Left "), PanelMenu
, menu_entries (PanelMenu
));
1338 MenuBar
[0] = create_menu ( horizontal_split
? _(" Above ") : _(" Left "),
1339 PanelMenu
, menu_entries (PanelMenu
));
1341 MenuBar
[1] = create_menu (_(" File "), FileMenu
, menu_entries (FileMenu
));
1342 MenuBar
[2] = create_menu (_(" Command "), CmdMenu
, menu_entries (CmdMenu
));
1343 MenuBar
[3] = create_menu (_(" Options "), OptMenu
, menu_entries (OptMenu
));
1346 MenuBar
[4] = create_menu (_(" Right "), RightMenu
, menu_entries (PanelMenu
));
1348 MenuBar
[4] = create_menu (horizontal_split
? _(" Below ") : _(" Right "),
1349 RightMenu
, menu_entries (PanelMenu
));
1350 for (i
= 0; i
< 5; i
++)
1351 MenuBarEmpty
[i
] = create_menu (MenuBar
[i
]->name
, 0, 0);
1353 #endif /* ! HAVE_XVIEW */
1362 for (i
= 0; i
< 5; i
++){
1363 destroy_menu (MenuBar
[i
]);
1365 destroy_menu (MenuBarEmpty
[i
]);
1368 for (i
= 0; i
< 4; i
++){
1369 destroy_menu (MenuBar
[i
]);
1376 menu_last_selected_cmd (void)
1378 the_menubar
->active
= 1;
1379 the_menubar
->dropped
= drop_menus
;
1380 the_menubar
->previous_selection
= dlg_item_number (midnight_dlg
);
1381 dlg_select_widget (midnight_dlg
, the_menubar
);
1387 if (the_menubar
->active
)
1390 if (get_current_index () == 0)
1391 the_menubar
->selected
= 0;
1393 the_menubar
->selected
= 4;
1394 menu_last_selected_cmd ();
1397 /* Flag toggling functions */
1399 toggle_confirm_delete (void)
1401 confirm_delete
= !confirm_delete
;
1405 toggle_fast_reload (void)
1407 fast_reload
= !fast_reload
;
1408 if (fast_reload_w
== 0 && fast_reload
){
1409 message (0, _(" Information "),
1410 _(" Using the fast reload option may not reflect the exact \n"
1411 " directory contents. In this cases you'll need to do a \n"
1412 " manual reload of the directory. See the man page for \n"
1419 toggle_mix_all_files (void)
1421 mix_all_files
= !mix_all_files
;
1422 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1426 toggle_show_backup (void)
1428 show_backups
= !show_backups
;
1429 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1433 toggle_show_hidden (void)
1435 show_dot_files
= !show_dot_files
;
1436 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1440 toggle_show_mini_status (void)
1442 show_mini_info
= !show_mini_info
;
1443 paint_panel (cpanel
);
1444 if (get_other_type () == view_listing
)
1445 paint_panel (opanel
);
1449 toggle_align_extensions (void)
1451 align_extensions
= !align_extensions
;
1454 #ifndef PORT_HAS_CREATE_PANELS
1456 create_panels (void)
1462 char original_dir
[1024];
1464 original_dir
[0] = 0;
1466 if (boot_current_is_left
){
1469 current_mode
= startup_left_mode
;
1470 other_mode
= startup_right_mode
;
1474 current_mode
= startup_right_mode
;
1475 other_mode
= startup_left_mode
;
1477 /* Creates the left panel */
1480 /* Ok, user has specified two dirs, save the original one,
1481 * since we may not be able to chdir to the proper
1482 * second directory later
1484 mc_get_current_wd (original_dir
, sizeof (original_dir
)-2);
1486 mc_chdir (this_dir
);
1488 set_display_type (current_index
, current_mode
);
1490 /* The other panel */
1492 if (original_dir
[0])
1493 mc_chdir (original_dir
);
1494 mc_chdir (other_dir
);
1496 set_display_type (other_index
, other_mode
);
1498 if (startup_left_mode
== view_listing
){
1499 current_panel
= left_panel
;
1502 current_panel
= right_panel
;
1504 current_panel
= left_panel
;
1507 /* Create the nice widgets */
1508 cmdline
= command_new (0, 0, 0);
1509 the_prompt
= label_new (0, 0, prompt
, NULL
);
1510 the_prompt
->transparent
= 1;
1511 the_bar
= buttonbar_new (keybar_visible
);
1514 the_hint
= label_new (0, 0, 0, NULL
);
1515 the_hint
->transparent
= 1;
1516 the_hint
->auto_adjust_cols
= 0;
1517 the_hint
->widget
.cols
= COLS
;
1521 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
, 5);
1523 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
+ 1, 3);
1524 the_bar2
= buttonbar_new (keybar_visible
);
1529 static void copy_current_pathname (void)
1531 if (!command_prompt
)
1534 stuff (input_w (cmdline
), cpanel
->cwd
, 0);
1535 if (cpanel
->cwd
[strlen (cpanel
->cwd
) - 1] != PATH_SEP
)
1536 stuff (input_w (cmdline
), PATH_SEP_STR
, 0);
1539 static void copy_other_pathname (void)
1541 if (get_other_type () != view_listing
)
1544 if (!command_prompt
)
1547 stuff (input_w (cmdline
), opanel
->cwd
, 0);
1548 if (cpanel
->cwd
[strlen (opanel
->cwd
) - 1] != PATH_SEP
)
1549 stuff (input_w (cmdline
), PATH_SEP_STR
, 0);
1552 static void copy_readlink (WPanel
*panel
)
1554 if (!command_prompt
)
1556 if (S_ISLNK (selection (panel
)->buf
.st_mode
)) {
1557 char buffer
[MC_MAXPATHLEN
];
1558 char *p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1561 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
);
1565 stuff (input_w (cmdline
), buffer
, 0);
1570 static void copy_current_readlink (void)
1572 copy_readlink (cpanel
);
1575 static void copy_other_readlink (void)
1577 if (get_other_type () != view_listing
)
1579 copy_readlink (opanel
);
1582 /* Inserts the selected file name into the input line */
1583 /* Exported so that the command modules uses it */
1584 void copy_prog_name (void)
1587 if (!command_prompt
)
1590 if (get_current_type () == view_tree
){
1591 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1592 tmp
= name_quote (tree
->selected_ptr
->name
, 1);
1594 tmp
= name_quote (selection (cpanel
)->fname
, 1);
1595 stuff (input_w (cmdline
), tmp
, 1);
1599 static void copy_tagged (WPanel
*panel
)
1603 if (!command_prompt
)
1605 input_disable_update (input_w (cmdline
));
1607 for (i
= 0; i
< panel
->count
; i
++)
1608 if (panel
->dir
.list
[i
].f
.marked
) {
1609 char *tmp
= name_quote (panel
->dir
.list
[i
].fname
, 1);
1610 stuff (input_w (cmdline
), tmp
, 1);
1614 char *tmp
= name_quote (panel
->dir
.list
[panel
->selected
].fname
, 1);
1615 stuff (input_w (cmdline
), tmp
, 1);
1618 input_enable_update (input_w (cmdline
));
1621 static void copy_current_tagged (void)
1623 copy_tagged (cpanel
);
1626 static void copy_other_tagged (void)
1628 if (get_other_type () != view_listing
)
1630 copy_tagged (opanel
);
1633 static void do_suspend_cmd (void)
1637 if (console_flag
&& !use_subshell
)
1642 struct sigaction sigtstp_action
;
1644 /* Make sure that the SIGTSTP below will suspend us directly,
1645 without calling ncurses' SIGTSTP handler; we *don't* want
1646 ncurses to redraw the screen immediately after the SIGCONT */
1647 sigaction (SIGTSTP
, &startup_handler
, &sigtstp_action
);
1649 kill (getpid (), SIGTSTP
);
1651 /* Restore previous SIGTSTP action */
1652 sigaction (SIGTSTP
, &sigtstp_action
, NULL
);
1656 if (console_flag
&& !use_subshell
)
1657 handle_console (CONSOLE_SAVE
);
1659 edition_post_exec ();
1662 void suspend_cmd (void)
1666 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1670 void init_labels (Widget
*paneletc
)
1672 define_label (midnight_dlg
, paneletc
, 1, _("Help"), help_cmd
);
1673 define_label (midnight_dlg
, paneletc
, 2, _("Menu"), user_menu_cmd
);
1674 define_label (midnight_dlg
, paneletc
, 9, _("PullDn"), menu_cmd
);
1675 define_label (midnight_dlg
, paneletc
, 10, _("Quit"), (voidfn
) quit_cmd
);
1679 static key_map ctl_x_map
[] = {
1680 { XCTRL('c'), (callfn
) quit_cmd
},
1682 { 'a', reselect_vfs
},
1684 { 'd', compare_dirs_cmd
},
1686 { 'p', copy_current_pathname
},
1687 { XCTRL('p'), copy_other_pathname
},
1688 { 't', copy_current_tagged
},
1689 { XCTRL('t'), copy_other_tagged
},
1695 { XCTRL('l'), other_symlink_cmd
},
1696 { 's', symlink_cmd
},
1697 { XCTRL('s'), edit_symlink_cmd
},
1698 { 'r', copy_current_readlink
},
1699 { XCTRL('r'), copy_other_readlink
},
1702 { 'i', info_cmd_no_menu
},
1703 { 'q', quick_cmd_no_menu
},
1705 { 'h', add2hotlist_cmd
},
1706 { '!', external_panelize
},
1707 #ifdef WITH_BACKGROUND
1710 #ifdef HAVE_SETSOCKOPT
1711 { '%', source_routing
},
1716 static int ctl_x_map_enabled
= 0;
1718 static void ctl_x_cmd (int ignore
)
1720 ctl_x_map_enabled
= 1;
1723 static void nothing ()
1727 static key_map default_map
[] = {
1729 { KEY_F(19), menu_last_selected_cmd
},
1730 { KEY_F(20), (key_callback
) quiet_quit_cmd
},
1732 /* Copy useful information to the command line */
1733 { ALT('\n'), copy_prog_name
},
1734 { ALT('\r'), copy_prog_name
},
1735 { ALT('a'), copy_current_pathname
},
1736 { ALT('A'), copy_other_pathname
},
1738 { ALT('c'), quick_cd_cmd
},
1740 /* To access the directory hotlist */
1741 { XCTRL('\\'), quick_chdir_cmd
},
1744 { XCTRL('z'), suspend_cmd
},
1746 /* The filtered view command */
1747 { ALT('!'), filtered_view_cmd_cpanel
},
1750 { ALT('?'), find_cmd
},
1753 { XCTRL('r'), reread_cmd
},
1755 { ALT('t'), toggle_listing_cmd
},
1759 { XCTRL('u'), swap_cmd
},
1762 { XCTRL('o'), view_other_cmd
},
1765 /* Control-X keybindings */
1766 { XCTRL('x'), ctl_x_cmd
},
1768 /* Trap dlg's exit commands */
1769 { ESC_CHAR
, nothing
},
1770 { XCTRL('c'), nothing
},
1771 { XCTRL('g'), nothing
},
1777 static void setup_sigwinch ()
1780 struct sigaction act
, oact
;
1782 # if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
1784 act
.sa_handler
= flag_winch
;
1785 sigemptyset (&act
.sa_mask
);
1788 act
.sa_flags
|= SA_RESTART
;
1790 sigaction (SIGWINCH
, &act
, &oact
);
1799 /* Call all the inits */
1801 meta (stdscr
, eight_bit_clean
);
1803 SLsmg_Display_Eight_Bit
= full_eight_bits
? 128 : 160;
1808 #define setup_sigwinch()
1816 init_uid_gid_cache ();
1819 if (baudrate () < 9600 || slow_terminal
){
1826 midnight_colors
[0] = 0;
1827 midnight_colors
[1] = REVERSE_COLOR
; /* FOCUSC */
1828 midnight_colors
[2] = INPUT_COLOR
; /* HOT_NORMALC */
1829 midnight_colors
[3] = NORMAL_COLOR
; /* HOT_FOCUSC */
1832 static void setup_mc (void)
1843 #ifdef HAVE_SUBSHELL_SUPPORT
1845 add_select_channel (subshell_pty
, load_prompt
, 0);
1851 static void setup_dummy_mc (const char *file
)
1853 char d
[MC_MAXPATHLEN
];
1855 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1859 /* Create a fake current_panel, this is needed because the
1860 * expand_format routine will use current panel.
1862 strcpy (cpanel
->cwd
, d
);
1863 cpanel
->selected
= 0;
1865 cpanel
->dir
.list
[0].fname
= (char *) file
;
1868 static void done_mc ()
1874 * We sync the profiles since the hotlist may have changed, while
1875 * we only change the setup data if we have the auto save feature set
1877 if (auto_save_setup
)
1878 save_setup (); /* does also call save_hotlist */
1882 vfs_add_current_stamps ();
1883 if (xterm_flag
&& xterm_hintbar
)
1884 set_hintbar(_("Thank you for using GNU Midnight Commander"));
1887 /* This should be called after destroy_dlg since panel widgets
1888 * save their state on the profiles
1890 static void done_mc_profile ()
1892 if (!auto_save_setup
)
1893 profile_forget_profile (profile_name
);
1899 /* This routine only handles cpanel, and opanel, it is easy to
1900 * change to use npanels, just loop over the number of panels
1901 * and use get_panel_widget (i) and make the test done below
1903 void make_panels_dirty ()
1906 panel_update_contents (cpanel
);
1908 if ((get_other_type () == view_listing
) && opanel
->dirty
)
1909 panel_update_contents (opanel
);
1912 /* In OS/2 and Windows NT people want to actually type the '\' key frequently */
1914 # define check_key_backslash(x) 0
1916 # define check_key_backslash(x) ((x) == '\\')
1919 int midnight_callback (struct Dlg_head
*h
, int id
, int msg
)
1926 /* Speed up routine: now, we just set the */
1928 make_panels_dirty ();
1932 if (ctl_x_map_enabled
){
1933 ctl_x_map_enabled
= 0;
1934 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1935 if (id
== ctl_x_map
[i
].key_code
){
1936 (*ctl_x_map
[i
].fn
)(id
);
1941 if (id
== KEY_F(10) && !the_menubar
->active
){
1947 free_completions (input_w (cmdline
));
1949 /* On Linux, we can tell the difference */
1950 if (id
== '\n' && ctrl_pressed ()){
1955 if (id
== '\n' && input_w (cmdline
)->buffer
[0]){
1956 send_message_to (h
, (Widget
*) cmdline
, WIDGET_KEY
, id
);
1960 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
)) &&
1961 !quote
&& !cpanel
->searching
) {
1962 if(!only_leading_plus_minus
) {
1963 /* Special treatement, since the input line will eat them */
1969 if (check_key_backslash (id
) || id
== '-'){
1975 reverse_selection_cmd ();
1978 } else if (command_prompt
&& !strlen (input_w (cmdline
)->buffer
)) {
1979 /* Special treatement '+', '-', '\', '*' only when this is
1980 * first char on input line
1988 if (check_key_backslash (id
) || id
== '-') {
1994 reverse_selection_cmd ();
2001 case DLG_HOTKEY_HANDLED
:
2002 if (get_current_type () == view_listing
)
2003 cpanel
->searching
= 0;
2006 case DLG_UNHANDLED_KEY
:
2007 if (command_prompt
){
2010 v
= send_message_to (h
, (Widget
*) cmdline
, WIDGET_KEY
, id
);
2014 if (ctl_x_map_enabled
){
2015 ctl_x_map_enabled
= 0;
2016 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
2017 if (id
== ctl_x_map
[i
].key_code
){
2018 (*ctl_x_map
[i
].fn
)(id
);
2022 for (i
= 0; default_map
[i
].key_code
; i
++){
2023 if (id
== default_map
[i
].key_code
){
2024 (*default_map
[i
].fn
)(id
);
2029 return MSG_NOT_HANDLED
;
2033 /* We handle the special case of the output lines */
2035 attrset (SELECTED_COLOR
);
2036 if (console_flag
&& output_lines
)
2037 show_console_contents (output_start_y
,
2038 LINES
-output_lines
-keybar_visible
-1,
2039 LINES
-keybar_visible
-1);
2044 return default_dlg_callback (h
, id
, msg
);
2048 /* This should be rewritten in order to support as many panel containers as
2052 widget_data containers
[2];
2053 int containers_no
= 2;
2056 xtoolkit_panel_setup ()
2058 containers
[0] = x_create_panel_container (0);
2059 containers
[1] = x_create_panel_container (1);
2060 input_w (cmdline
)->widget
.wcontainer
= containers
[0];
2061 input_w (cmdline
)->widget
.area
= AREA_BOTTOM
;
2062 the_prompt
->widget
.wcontainer
= containers
[0];
2063 the_prompt
->widget
.area
= AREA_BOTTOM
;
2064 the_bar
->widget
.wcontainer
= containers
[0];
2065 the_bar
->widget
.area
= AREA_TOP
;
2067 the_bar2
->widget
.wcontainer
= containers
[1];
2068 the_bar2
->widget
.area
= AREA_TOP
;
2070 get_panel_widget (0)->wcontainer
= containers
[0];
2071 get_panel_widget (0)->area
= AREA_RIGHT
;
2072 get_panel_widget (1)->wcontainer
= containers
[1];
2073 get_panel_widget (1)->area
= AREA_RIGHT
;
2074 the_menubar
->widget
.wcontainer
= (widget_data
) NULL
;
2077 # define xtoolkit_panel_setup()
2081 # define xtoolkit_panel_setup()
2084 #ifndef PORT_HAS_LOAD_HINT
2089 if (!the_hint
->widget
.parent
)
2092 if (!message_visible
&& (!xterm_flag
|| !xterm_hintbar
)){
2093 label_set_text (the_hint
, 0);
2097 if ((hint
= get_random_hint ())){
2102 set_hintbar ("The Midnight Commander " VERSION
2103 " (C) 1995-1997 the Free Software Foundation");
2109 setup_panels_and_run_mc ()
2113 xtoolkit_panel_setup ();
2114 tk_new_frame (midnight_dlg
, "p.");
2116 add_widget (midnight_dlg
, the_hint
);
2119 add_widgetl (midnight_dlg
, cmdline
, XV_WLAY_RIGHTOF
);
2120 add_widgetl (midnight_dlg
, the_prompt
, XV_WLAY_DONTCARE
);
2122 add_widget (midnight_dlg
, the_bar
);
2124 add_widget (midnight_dlg
, the_bar2
);
2126 if (boot_current_is_left
){
2133 add_widget (midnight_dlg
, get_panel_widget (first
));
2134 add_widget (midnight_dlg
, get_panel_widget (second
));
2135 add_widget (midnight_dlg
, the_menubar
);
2137 init_labels (get_panel_widget (0));
2138 init_labels (get_panel_widget (1));
2140 /* Run the Midnight Commander if no file was specified in the command line */
2141 run_dlg (midnight_dlg
);
2144 /* result must be free'd (I think this should go in util.c) */
2146 prepend_cwd_on_local (char *filename
)
2151 if (vfs_file_is_local (filename
)){
2152 if (*filename
== PATH_SEP
) /* an absolute pathname */
2153 return strdup (filename
);
2154 d
= malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
2155 mc_get_current_wd (d
, MC_MAXPATHLEN
);
2158 strcpy (d
+ l
, filename
);
2159 return canonicalize_pathname (d
);
2161 return strdup (filename
);
2164 #ifdef USE_INTERNAL_EDIT
2165 void edit (const char *file_name
, int startline
);
2168 mc_maybe_editor_or_viewer (void)
2172 if (!(view_one_file
|| edit_one_file
))
2175 /* Invoke the internal view/edit routine with:
2176 * the default processing and forcing the internal viewer/editor
2178 if (view_one_file
) {
2179 path
= prepend_cwd_on_local (view_one_file
);
2180 setup_dummy_mc (path
);
2181 view_file (path
, 0, 1);
2183 #ifdef USE_INTERNAL_EDIT
2185 path
= prepend_cwd_on_local ("");
2186 setup_dummy_mc (path
);
2187 edit (edit_one_file
, 1);
2191 midnight_shutdown
= 1;
2201 midnight_dlg
= create_dlg (0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
, "[main]", "midnight", 0);
2202 midnight_dlg
->has_menubar
= 1;
2204 #ifdef USE_INTERNAL_EDIT
2205 /* Check if we were invoked as an editor or file viewer */
2206 if (mc_maybe_editor_or_viewer ())
2213 setup_panels_and_run_mc ();
2217 midnight_shutdown
= 1;
2219 /* destroy_dlg destroys even cpanel->cwd, so we have to save a copy :) */
2220 if (print_last_wd
) {
2221 if (!vfs_current_is_local ())
2222 last_wd_string
= strdup (".");
2224 last_wd_string
= strdup (cpanel
->cwd
);
2229 destroy_dlg (midnight_dlg
);
2235 #include "features.inc"
2238 version (int verbose
)
2240 fprintf (stderr
, "The Midnight Commander %s\n", VERSION
);
2246 _("with mouse support on xterm%s.\n"),
2247 status_mouse_support
? _(" and the Linux console") : "");
2250 fprintf (stderr
, features
);
2252 write (stdout_fd
, ".", 1);
2255 #if defined (_OS_NT)
2256 /* Windows NT code */
2257 #define CONTROL_FILE "\\mc.%d.control"
2258 char control_file
[sizeof (CONTROL_FILE
) + 8];
2263 SetConsoleTitle ("GNU Midnight Commander");
2265 shell
= getenv ("COMSPEC");
2266 if (!shell
|| !*shell
)
2267 shell
= get_default_shell ();
2269 /* Default opening mode for files is binary, not text (CR/LF translation) */
2274 mc_home
= get_mc_lib_dir ();
2278 sigchld_handler_no_subshell (int sig
)
2288 init_sigfatals (void)
2290 /* Nothing to be done on the OS/2, Windows/NT */
2294 #elif defined (__os2__)
2296 # define CONTROL_FILE "\\mc.%d.control"
2297 char control_file
[sizeof (CONTROL_FILE
) + 8];
2302 /* .ado: This does not work: */
2303 /* DosSMSetTitle ((PSZ) "This is my app"); */
2305 DosSMSetTitle = SESMGR.DOSSMSETTITLE */
2306 shell
= getenv ("COMSPEC");
2307 if (!shell
|| !*shell
)
2308 shell
= get_default_shell ();
2310 mc_home
= get_mc_lib_dir ();
2314 sigchld_handler_no_subshell (int sig
)
2324 init_sigfatals (void)
2326 /* Nothing to be done on the OS/2, Windows/NT */
2331 #define CONTROL_FILE "/tmp/mc.%d.control"
2332 char control_file
[sizeof (CONTROL_FILE
) + 8];
2340 termvalue
= getenv ("TERM");
2342 fprintf (stderr
, _("The TERM environment variable is unset!\n"));
2346 if (force_xterm
|| (strncmp (termvalue
, "xterm", 5) == 0 || strcmp (termvalue
, "dtterm") == 0)){
2347 use_mouse_p
= XTERM_MOUSE
;
2350 printf ("\33]0;GNU Midnight Commander\7");
2353 #endif /* ! HAVE_X */
2354 shell
= getenv ("SHELL");
2355 if (!shell
|| !*shell
)
2356 shell
= strdup (getpwuid (geteuid ())->pw_shell
);
2357 if (!shell
|| !*shell
)
2360 sprintf (control_file
, CONTROL_FILE
, getpid ());
2361 my_putenv ("MC_CONTROL_FILE", control_file
);
2363 /* This is the directory, where MC was installed, on Unix this is LIBDIR */
2364 /* and can be overriden by the MCHOME environment variable */
2365 if ((mc_libdir
= getenv ("MCHOME")) != NULL
) {
2366 mc_home
= strdup (mc_libdir
);
2368 mc_home
= strdup (LIBDIR
);
2373 sigchld_handler_no_subshell (int sig
)
2381 /* COMMENT: if it were true that after the call to handle_console(..INIT)
2382 the value of console_flag never changed, we could simply not install
2383 this handler at all if (!console_flag && !use_subshell). */
2385 /* That comment is no longer true. We need to wait() on a sigchld
2386 handler (that's at least what the tarfs code expects currently). */
2389 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
2391 if (pid
== cons_saver_pid
){
2392 /* {{{ Someone has stopped or killed cons.saver; restart it */
2394 if (WIFSTOPPED (status
))
2395 kill (pid
, SIGCONT
);
2398 handle_console (CONSOLE_DONE
);
2399 handle_console (CONSOLE_INIT
);
2403 #endif /* ! SCO_FLAVOR */
2405 /* If we get here, some other child exited; ignore it */
2406 #endif /* ! HAVE_X */
2411 mc_fatal_signal (int signum
)
2416 char *args
[4] = { "gdb", NULL
, NULL
, NULL
};
2419 sprintf (buf
, "%d", getpid ());
2421 "Midnight Commander fatal error, PID=%d\n"
2422 "What to do: [e]xit, [s]tack trace, [a]ttach to process\n", getpid ());
2430 args
[1] = program_name
;
2434 fprintf (stderr
, "Could not fork, exiting\n");
2448 init_sigfatals (void)
2450 struct sigaction sa
;
2452 sa
.sa_hanlder
= mc_fatal_signal
;
2456 sigaction (SIGSEGV
, &sa
, NULL
);
2457 sigaction (SIGBUS
, &sa
, NULL
);
2458 sigaction (SIGFPE
, &sa
, NULL
);
2461 #define init_sigfatals()
2467 struct sigaction sigchld_action
;
2469 sigchld_action
.sa_handler
=
2470 #ifdef HAVE_SUBSHELL_SUPPORT
2471 use_subshell
? sigchld_handler
:
2473 sigchld_handler_no_subshell
;
2475 sigemptyset (&sigchld_action
.sa_mask
);
2478 sigchld_action
.sa_flags
= SA_RESTART
;
2480 sigchld_action
.sa_flags
= 0;
2483 sigaction (SIGCHLD
, &sigchld_action
, NULL
);
2486 #endif /* _OS_NT, __os2__, UNIX */
2488 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2489 extern int SLtt_Try_Termcap
;
2492 #ifndef PORT_WANTS_ARGP
2494 print_mc_usage (void)
2499 "mc [flags] [this_dir] [other_panel_dir]\n\n"
2500 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2501 "-a, --stickchars Force use of +, -, | for line drawing.\n"
2503 "-b, --nocolor Force black and white display.\n"
2504 #ifdef WITH_BACKGROUND
2505 "-B, --background [DEVEL-ONLY: Debug the background code]\n"
2507 "-c, --color Force color mode.\n"
2508 "-C, --colors Specify colors (use --help-colors to get a list).\n"
2509 #ifdef USE_INTERNAL_EDIT
2510 "-e, --edit Startup the internal editor.\n"
2512 "-d, --nomouse Disable mouse support.\n"
2513 "-f, --libdir Print configured paths.\n"
2514 "-h, --help Shows this help message.\n"
2515 "-k, --resetsoft Reset softkeys (HP terminals only) to their terminfo/termcap\n"
2517 "-P, --printwd At exit, print the last working directory.\n"
2518 "-s, --slow Disables verbose operation (for slow terminals).\n"
2519 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2520 "-t, --termcap Activate support for the TERMCAP variable.\n"
2523 "-l, --ftplog file Log ftpfs commands to the file.\n"
2525 #if defined(HAVE_SLANG) && defined(OS2_NT)
2526 "-S, --createcmdile Create command file to set default directory upon exit.\n"
2529 #ifdef HAVE_SUBSHELL_SUPPORT
2530 "-u, --nosubshell Disable the concurrent subshell mode.\n"
2531 "-U, --subshell Force the concurrent subshell mode.\n"
2532 "-r, --forceexec Force subshell execution.\n"
2534 "-v, --view fname Start up into the viewer mode.\n"
2535 "-V, --version Report version and configuration options.\n"
2536 "-x, --xterm Force xterm mouse support and screen save/restore.\n"
2537 #ifdef HAVE_SUBSHELL_SUPPORT
2538 "-X, --dbgsubshell [DEVEL-ONLY: Debug the subshell].\n"
2542 #endif /* PORT_WANTS_ARGP */
2545 print_color_usage (void)
2548 "--colors KEYWORD={FORE},{BACK}\n\n"
2549 "{FORE} and {BACK} can be ommited, and the default will be used\n"
2552 " Global: errors, reverse, gauge, input\n"
2553 " File display: normal, selected, marked, markselect\n"
2554 " Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus\n"
2555 " Menus: menu, menuhot, menusel, menuhotsel\n"
2556 " Help: helpnormal, helpitalic, helplink, helpslink\n"
2557 " File types: directory, execute, link, device, special, core\n"
2560 " black, gray, red, brightred, green, brightgreen, brown,\n"
2561 " yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
2562 " brightcyan, lightgray and white\n\n");
2568 probably_finish_program (void)
2570 if (finish_program
){
2583 process_args (int c
, char *option_arg
)
2599 fprintf (stderr
, _("Library directory for the Midnight Commander: %s\n"), mc_home
);
2604 fprintf (stderr
, _("Option -m is obsolete. Please look at Display Bits... in the Option's menu\n"));
2610 ftpfs_set_debug (option_arg
);
2617 batch_file_name
= option_arg
;
2622 use_mouse_p
= NO_MOUSE
;
2626 #ifdef HAVE_SUBSHELL_SUPPORT
2632 #ifdef HAVE_SUBSHELL_SUPPORT
2638 #ifdef HAVE_SUBSHELL_SUPPORT
2644 #ifdef HAVE_SUBSHELL_SUPPORT
2645 force_subshell_execution
= 1;
2650 print_color_usage ();
2655 #ifndef PORT_WANTS_ARGP
2662 #ifdef PORT_WANTS_ARGP
2663 static struct argp_option argp_options
[] = {
2664 #ifdef WITH_BACKGROUND
2665 { "background", 'B', NULL
, 0, N_("[DEVEL-ONLY: Debug the background code]"), 0 },
2667 #if defined(HAVE_SLANG) && defined(OS2_NT)
2668 { "createcmdfile", 'S', "CMDFILE", , 0, N_("Create command file to set default directory upon exit."), 1 },
2670 { "color", 'c', NULL
, 0, N_("Force color mode."), 0 },
2671 { "colors", 'C', "COLORS", 0, N_("Specify colors (use --help-colors to get a list)."), 1 },
2672 #ifdef HAVE_SUBSHELL_SUPPORT
2673 { "dbgsubshell", 'X', NULL
, 0, N_("[DEVEL-ONLY: Debug the subshell."), 0 },
2675 { "edit", 'e', "EDIT", 0, N_("Startup the internal editor."), 1 },
2676 { "help", 'h', NULL
, 0, N_("Shows this help message."), 0 },
2677 { "help-colors", 'H', NULL
, 0, N_("Help on how to specify colors."), 0 },
2679 { "ftplog", 'l', "FTPLOG", 0, N_("Log ftpfs commands to the file."), 1 },
2681 { "libdir", 'f', NULL
, 0, N_("Prints out the configured paths."), 0 },
2682 { NULL
, 'm', NULL
, OPTION_HIDDEN
, NULL
, 0 },
2683 { "nocolor", 'b', NULL
, 0, N_("Force black and white display."), 0 },
2684 { "nomouse", 'd', NULL
, 0, N_("Disable mouse support."), 0 },
2685 #ifdef HAVE_SUBSHELL_SUPPORT
2686 { "subshell", 'U', NULL
, 0, N_("Force the concurrent subshell mode"), 0 },
2687 { "nosubshell", 'u', NULL
, 0, N_("Disable the concurrent subshell mode."), 0 },
2688 { "forceexec", 'r', NULL
, 0, N_("Force subshell execution."), 0 },
2690 { "printwd", 'P', NULL
, 0, N_("At exit, print the last working directory."), 0 },
2691 { "resetsoft", 'k', NULL
, 0, N_("Reset softkeys (HP terminals only) to their terminfo/termcap default."), 0},
2692 { "slow", 's', NULL
, 0, N_("Disables verbose operation (for slow terminals)."), 0 },
2693 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2694 { "stickchars", 'a', NULL
, 0, N_("Use simple symbols for line drawing."), 0 },
2696 #ifdef HAVE_SUBSHELL_SUPPORT
2698 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2699 { "termcap", 't', NULL
, 0, N_("Activate support for the TERMCAP variable."), 0 },
2701 { "version", 'V', NULL
, 0, N_("Report versionand configuration options."), 0 },
2702 { "view", 'v', NULL
, 0, N_("Start up into the viewer mode."), 0 },
2703 { "xterm", 'x', NULL
, 0, N_("Force xterm mouse support and screen save/restore"), 0 },
2704 { "geometry", GEOMETRY_KEY
, "GEOMETRY", 0, N_("Geometry for the window"), 0 },
2705 { "nowindows", NOWIN_KEY
, NULL
, 0, N_("No windows opened at startup"), 0 },
2706 { NULL
, 0, NULL
, 0, NULL
},
2709 GList
*directory_list
= 0;
2710 GList
*geometry_list
= 0;
2714 parse_an_arg (int key
, char *arg
, struct argp_state
*state
)
2717 #ifdef WITH_BACKGROUND
2719 background_wait
= 1;
2731 reset_hp_softkeys
= 1;
2739 force_ugly_line_drawing
= 1;
2746 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2748 SLtt_Try_Termcap
= 1;
2753 geometry_list
= g_list_append (geometry_list
, arg
);
2767 process_args (key
, arg
);
2772 edit_one_file
= strdup (arg
);
2773 else if (view_one_file
)
2774 view_one_file
= strdup (arg
);
2776 directory_list
= g_list_append (directory_list
, arg
);
2781 static struct argp mc_argp_parser
= {
2782 argp_options
, parse_an_arg
, N_("[this dir] [other dir]"), NULL
, NULL
, NULL
, NULL
2787 static struct poptOption argumentTable
[] = {
2788 #ifdef WITH_BACKGROUND
2789 { "background", 'B', POPT_ARG_NONE
, &background_wait
, 0 },
2791 #if defined(HAVE_SLANG) && defined(OS2_NT)
2792 { "createcmdfile", 'S', POPT_ARG_STRING
, NULL
, 'S' },
2794 { "color", 'c', POPT_ARG_NONE
, NULL
, 'c' },
2795 { "colors", 'C', POPT_ARG_STRING
, &command_line_colors
, 0 },
2796 #ifdef HAVE_SUBSHELL_SUPPORT
2797 { "dbgsubshell", 'X', POPT_ARG_NONE
, &debug_subshell
, 0 },
2799 { "edit", 'e', POPT_ARG_STRING
, &edit_one_file
, 0 },
2801 { "help", 'h', POPT_ARG_NONE
, NULL
, 'h' },
2802 { "help-colors", 'H', POPT_ARG_NONE
, NULL
, 'H' },
2804 { "ftplog", 'l', POPT_ARG_STRING
, NULL
, 'l' },
2806 { "libdir", 'f', POPT_ARG_NONE
, NULL
, 'f' },
2807 { NULL
, 'm', POPT_ARG_NONE
, NULL
, 'm' },
2808 { "nocolor", 'b', POPT_ARG_NONE
, &disable_colors
, 0 },
2809 { "nomouse", 'd', POPT_ARG_NONE
, NULL
, 'd' },
2810 #ifdef HAVE_SUBSHELL_SUPPORT
2811 { "nosubshell", 'u', POPT_ARG_NONE
, NULL
, 'u' },
2812 { "forceexec", 'r', POPT_ARG_NONE
, NULL
, 'r' },
2814 { "printwd", 'P', POPT_ARG_NONE
, &print_last_wd
, 0 },
2815 { "resetsoft", 'k', POPT_ARG_NONE
, &reset_hp_softkeys
, 0 },
2816 { "slow", 's', POPT_ARG_NONE
, &slow_terminal
, 0 },
2817 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2818 { "stickchars", 'a', 0, &force_ugly_line_drawing
, 0 },
2820 #ifdef HAVE_SUBSHELL_SUPPORT
2821 { "subshell", 'U', POPT_ARG_NONE
, NULL
, 'U' },
2823 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2824 { "termcap", 't', 0, &SLtt_Try_Termcap
, 0 },
2826 { "version", 'V', POPT_ARG_NONE
, NULL
, 'V'},
2827 { "view", 'v', POPT_ARG_STRING
, &view_one_file
, 0 },
2828 { "xterm", 'x', POPT_ARG_NONE
, &force_xterm
, 0},
2830 { NULL
, 0, 0, NULL
, 0 }
2834 handle_args (int argc
, char *argv
[])
2836 char *tmp
, *option_arg
, *base
;
2840 optCon
= poptGetContext ("mc", argc
, argv
, argumentTable
, 0);
2843 SLtt_Try_Termcap
= 1;
2846 while ((c
= poptGetNextOpt (optCon
)) > 0) {
2847 option_arg
= poptGetOptArg(optCon
);
2849 process_args (c
, option_arg
);
2854 fprintf(stderr
, "%s: %s\n",
2855 poptBadOption(optCon
, POPT_BADOPTION_NOALIAS
),
2860 probably_finish_program ();
2862 /* Check for special invocation names mcedit and mcview,
2863 * if none apply then set the current directory and the other
2864 * directory from the command line arguments
2866 tmp
= poptGetArg (optCon
);
2867 base
= x_basename (argv
[0]);
2868 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP(base
, "vi")) {
2871 edit_one_file
= strdup (tmp
);
2873 if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP(base
, "view")) {
2875 view_one_file
= strdup (tmp
);
2877 /* sets the current dir and the other dir */
2879 char buffer
[MC_MAXPATHLEN
+ 2];
2880 this_dir
= strdup (tmp
);
2881 mc_get_current_wd (buffer
, sizeof (buffer
) - 2);
2882 if ((tmp
= poptGetArg (optCon
)))
2883 other_dir
= strdup (tmp
);
2886 poptFreeContext(optCon
);
2891 * The compatibility_move_mc_files routine is intended to
2892 * move all of the hidden .mc files into a private ~/.mc
2893 * directory in the home directory, to avoid cluttering the users.
2895 * Previous versions of the program had all of their files in
2896 * the $HOME, we are now putting them in $HOME/.mc
2899 # define compatibility_move_mc_files()
2903 do_mc_filename_rename (char *mc_dir
, char *o_name
, char *n_name
)
2905 char *full_o_name
= concat_dir_and_file (home_dir
, o_name
);
2906 char *full_n_name
= copy_strings (home_dir
, MC_BASE
, n_name
, NULL
);
2909 move
= 0 == rename (full_o_name
, full_n_name
);
2916 do_compatibility_move (char *mc_dir
)
2921 if (stat (mc_dir
, &s
) == 0)
2923 if (errno
!= ENOENT
)
2926 if (mkdir (mc_dir
, 0777) == -1)
2929 move
= do_mc_filename_rename (mc_dir
, ".mc.ini", "ini");
2930 move
+= do_mc_filename_rename (mc_dir
, ".mc.hot", "hotlist");
2931 move
+= do_mc_filename_rename (mc_dir
, ".mc.ext", "ext");
2932 move
+= do_mc_filename_rename (mc_dir
, ".mc.menu", "menu");
2933 move
+= do_mc_filename_rename (mc_dir
, ".mc.bashrc", "bashrc");
2934 move
+= do_mc_filename_rename (mc_dir
, ".mc.inputrc", "inputrc");
2935 move
+= do_mc_filename_rename (mc_dir
, ".mc.tcshrc", "tcshrc");
2936 move
+= do_mc_filename_rename (mc_dir
, ".mc.tree", "tree");
2941 show_change_notice
= 1;
2945 compatibility_move_mc_files (void)
2947 char *mc_dir
= concat_dir_and_file (home_dir
, ".mc");
2949 do_compatibility_move (mc_dir
);
2954 int main (int argc
, char *argv
[])
2957 /* Backward compatibility: Gives up privileges in case someone
2958 installed the mc as setuid */
2961 # define LOCALEDIR get_mc_lib_dir ()
2964 signal(SIGINT
,SIG_IGN
); /* Ignore CTRL-C */
2966 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2967 setlocale (LC_ALL
, "");
2968 bindtextdomain ("mc", LOCALEDIR
);
2971 /* Initialize list of all user group for timur_clr_mode */
2979 /* NOTE: This call has to be before any our argument handling :) */
2982 session_management_setup (argv
[0]);
2984 char *base
= x_basename (argv
[0]);
2987 if (strcmp (base
, "mcedit") == 0)
2990 if (strcmp (base
, "mcview") == 0)
2994 gnome_init ("gmc", &mc_argp_parser
, argc
, argv
, 0, NULL
);
2995 probably_finish_program ();
2998 if (xtoolkit_init (&argc
, argv
) == -1)
3004 SLtt_Ignore_Beep
= 1;
3007 /* NOTE: This has to be called before slang_init or whatever routine
3008 calls any define_sequence */
3011 #ifndef PORT_WANTS_ARGP
3012 handle_args (argc
, argv
);
3015 /* Used to report the last working directory at program end */
3018 stdout_fd
= dup (1);
3020 if (open (ttyname (0), O_RDWR
) < 0)
3021 if (open ("/dev/tty", O_RDWR
) < 0) {
3022 /* Try if stderr is not redirected as the last chance */
3023 char *p
= strdup (ttyname (0));
3025 if (!strcmp (p
, ttyname (2)))
3029 _("Couldn't open tty line. You have to run mc without the -P flag.\n"
3030 "On some systems you may want to run # `which mc`\n"));
3039 /* This is to avoid subshell trying to restard any child pid
3040 * that happends to have cons_saver_pid (a random startup value).
3041 * and PID 1 is init, unlikely we could be the parent of it.
3043 /* cons_saver_pid = 1; */
3045 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
3046 handle_console (CONSOLE_INIT
);
3049 # ifdef HAVE_SUBSHELL_SUPPORT
3050 subshell_get_console_attributes ();
3053 /* Install the SIGCHLD handler; must be done before init_subshell() */
3057 /* This variable is used by the subshell */
3058 home_dir
= getenv ("HOME");
3061 home_dir
= PATH_SEP_STR
;
3063 home_dir
= mc_home
; /* LIBDIR, calculated in OS_Setup() */
3067 compatibility_move_mc_files ();
3070 /* We need this, since ncurses endwin () doesn't restore the signals */
3071 save_stop_handler ();
3074 /* Must be done before init_subshell, to set up the terminal size: */
3075 /* FIXME: Should be removed and LINES and COLS computed on subshell */
3077 /* NOTE: This call has to be after slang_init. It's the small part from
3078 the previous init_key which had to be moved after the call of slang_init */
3079 init_key_input_fd ();
3093 # ifdef HAVE_SUBSHELL_SUPPORT
3094 /* Done here to ensure that the subshell doesn't */
3095 /* inherit the file descriptors opened below, etc */
3102 /* Removing this from the X code let's us type C-c */
3105 /* Also done after init_subshell, to save any shell init file messages */
3107 handle_console (CONSOLE_SAVE
);
3109 if (alternate_plus_minus
)
3110 application_keypad_mode ();
3113 /* The directory hot list */
3116 if (show_change_notice
){
3117 message (1, _(" Notice "),
3118 _(" The Midnight Commander configuration files \n"
3119 " are now stored in the ~/.mc directory, the \n"
3120 " files have been moved now\n"));
3123 # ifdef HAVE_SUBSHELL_SUPPORT
3125 prompt
= strip_ctrl_codes (subshell_prompt
);
3130 prompt
= (geteuid () == 0) ? "# " : "$ ";
3132 /* Program main loop */
3135 /* Virtual File System shutdown */
3138 /* Delete list of all user groups*/
3141 flush_extension_file (); /* does only free memory */
3144 /* Miguel, maybe the fix in slang is not required and
3145 * it could be done by removing the slang_done_screen.
3146 * Do I need to call slang_reset_tty then?
3151 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
3153 if (alternate_plus_minus
)
3154 numeric_keypad_mode ();
3158 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
3163 handle_console (CONSOLE_DONE
);
3164 putchar ('\r'); /* Hack to make shell's prompt start at left of screen */
3168 /* On NT, home_dir is malloced */
3172 if (print_last_wd
== 2){
3176 bat_file
= fopen(batch_file_name
, "w");
3177 if (bat_file
!= NULL
){
3178 /* .ado: \r\n for Win95 */
3179 fprintf(bat_file
, "@echo off\r\n");
3180 if (isalpha(last_wd_string
[0]))
3181 fprintf(bat_file
, "%c:\r\n", last_wd_string
[0]);
3182 fprintf(bat_file
, "cd %s\r\n", last_wd_string
);
3187 if (print_last_wd
) {
3188 if (print_last_revert
|| edit_one_file
|| view_one_file
)
3189 write (stdout_fd
, ".", 1);
3191 write (stdout_fd
, last_wd_string
, strlen (last_wd_string
));
3192 free (last_wd_string
);
3198 mad_finalize (__FILE__
, __LINE__
);