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
)
388 if (strlen (panel
->lwd
) > strlen (panel
->cwd
)
389 && strncmp (panel
->cwd
, panel
->lwd
, strlen (panel
->cwd
)) == 0
390 && strchr (panel
->lwd
+ strlen (panel
->cwd
) + 1, PATH_SEP
) == 0)
391 try_to_select (panel
, panel
->lwd
);
394 if ((!strncmp (panel
->lwd
, "tar:", 4) &&
395 !strncmp (panel
->lwd
+ 4, panel
->cwd
, strlen (panel
->cwd
))) ||
396 ((i
= extfs_prefix_to_type (panel
->lwd
)) != -1 &&
397 !strncmp (panel
->lwd
+ (j
= strlen (extfs_get_prefix (i
)) + 1),
398 panel
->cwd
, strlen (panel
->cwd
)))) {
399 p
= strdup (panel
->lwd
+ j
+ strlen (panel
->cwd
));
400 q
= strchr (p
, PATH_SEP
);
401 if (q
!= NULL
&& (q
!= p
|| (q
= strchr (q
+ 1, PATH_SEP
)) != NULL
))
403 try_to_select (panel
, p
);
407 try_to_select (panel
, NULL
);
411 reload_panelized (WPanel
*panel
)
414 dir_list
*list
= &panel
->dir
;
417 mc_chdir (panel
->cwd
);
419 for (i
= 0, j
= 0; i
< panel
->count
; i
++){
420 if (list
->list
[i
].f
.marked
) {
421 /* Unmark the file in advance. In case the following mc_lstat
422 * fails we are done, else we have to mark the file again
423 * (Note: do_file_mark depends on a valid "list->list [i].buf").
424 * IMO that's the best way to update the panel's summary status
427 do_file_mark (panel
, i
, 0);
429 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].buf
)){
430 free (list
->list
[i
].fname
);
433 if (list
->list
[i
].f
.marked
)
434 do_file_mark (panel
, i
, 1);
436 list
->list
[j
] = list
->list
[i
];
440 panel
->count
= set_zero_dir (list
);
445 mc_chdir (cpanel
->cwd
);
449 update_one_panel_widget (WPanel
*panel
, int force_update
, char *current_file
)
453 if (force_update
& UP_RELOAD
){
454 panel
->is_panelized
= 0;
457 bzero (&(panel
->dir_stat
), sizeof (panel
->dir_stat
));
460 /* If current_file == -1 (an invalid pointer) then preserve selection */
461 if (current_file
== UP_KEEPSEL
){
463 current_file
= strdup (panel
->dir
.list
[panel
->selected
].fname
);
467 if (panel
->is_panelized
)
468 reload_panelized (panel
);
470 panel_reload (panel
);
472 try_to_select (panel
, current_file
);
479 #ifndef PORT_HAS_UPDATE_PANELS
481 update_one_panel (int which
, int force_update
, char *current_file
)
485 if (get_display_type (which
) != view_listing
)
488 panel
= (WPanel
*) get_panel_widget (which
);
489 update_one_panel_widget (panel
, force_update
, current_file
);
492 /* This routine reloads the directory in both panels. It tries to
493 * select current_file in current_panel and other_file in other_panel.
494 * If current_file == -1 then it automatically sets current_file and
495 * other_file to the currently selected files in the panels.
497 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
498 * will not reload the other panel.
501 update_panels (int force_update
, char *current_file
)
503 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
506 update_one_panel (get_current_index (), force_update
, current_file
);
508 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
510 if (get_current_type () == view_listing
)
511 panel
= (WPanel
*) get_panel_widget (get_current_index ());
513 panel
= (WPanel
*) get_panel_widget (get_other_index ());
515 mc_chdir (panel
->cwd
);
520 static void select_by_index (WPanel
*panel
, int i
);
522 /* Called by parse_control_file */
523 static int index_by_name (file_entry
*list
, int count
)
528 name
= strtok (NULL
, " \t\n");
531 for (i
= 0; i
< count
; i
++){
532 if (strcmp (name
, list
[i
].fname
) == 0)
538 /* Called by parse_control_file */
539 static void select_by_index (WPanel
*panel
, int i
)
541 if (i
>= panel
->count
)
544 unselect_item (panel
);
548 while (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
549 /* Scroll window half screen */
550 panel
->top_file
+= ITEMS (panel
)/2;
554 while (panel
->selected
< panel
->top_file
){
555 /* Scroll window half screen */
556 panel
->top_file
-= ITEMS (panel
)/2;
557 if (panel
->top_file
< 0) panel
->top_file
= 0;
564 /* Called by my_system
565 No error reporting, just exits on the first sign of trouble */
566 static void parse_control_file (void)
568 char *data
, *current
;
575 if ((file
= fopen (control_file
, "r")) == NULL
){
578 /* Use of fstat prevents race conditions */
579 if (fstat (fileno (file
), &s
) != 0){
584 /* Security: Check that the user owns the control file to prevent
585 other users from playing tricks on him/her. */
586 if (s
.st_uid
!= getuid ()){
591 data
= (char *) xmalloc (s
.st_size
+1, "main, parse_control_file");
596 if (s
.st_size
!= fread (data
, 1, s
.st_size
, file
)){
601 data
[s
.st_size
] = 0;
604 /* The Control file has now been loaded to memory -> start parsing. */
605 current
= strtok (data
, " \t\n");
606 while (current
&& *current
){
607 if (isupper (*current
)){
608 if (get_other_type () != view_listing
)
615 list
= panel
->dir
.list
;
616 *current
= tolower (*current
);
618 if (strcmp (current
, "clear_tags") == 0){
619 unmark_files (panel
);
620 } else if (strcmp (current
, "tag") == 0){
621 i
= index_by_name (list
, panel
->count
);
623 do_file_mark (panel
, i
, 1);
625 } else if (strcmp (current
, "untag") == 0){
626 i
= index_by_name (list
, panel
->count
);
628 do_file_mark (panel
, i
, 0);
630 } else if (strcmp (current
, "select") == 0){
631 i
= index_by_name (list
, panel
->count
);
633 select_by_index (panel
, i
);
635 } else if (strcmp (current
, "change_panel") == 0){
637 } else if (strcmp (current
, "cd") == 0){
639 current
= strtok (NULL
, " \t\n");
641 if (cpanel
!= panel
){
645 do_cd (current
, cd_parse_command
);
649 /* Unknown command -> let's give up */
652 current
= strtok (NULL
, " \t\n");
656 paint_panel (cpanel
);
657 paint_panel (opanel
);
660 #define parse_control_file()
661 #endif /* WANT_PARSE */
663 /* Sets up the terminal before executing a program */
671 /* Save current stat of directories to avoid reloading the panels */
672 /* when no modifications have taken place */
674 save_cwds_stat (void)
677 mc_stat (cpanel
->cwd
, &(cpanel
->dir_stat
));
678 if (get_other_type () == view_listing
)
679 mc_stat (opanel
->cwd
, &(opanel
->dir_stat
));
683 #ifdef HAVE_SUBSHELL_SUPPORT
685 do_possible_cd (char *new_dir
)
687 if (!do_cd (new_dir
, cd_exact
))
688 message (1, _(" Warning "),
689 _(" The Commander can't change to the directory that \n"
690 " the subshell claims you are in. Perhaps you have \n"
691 " deleted your working directory, or given yourself \n"
692 " extra access permissions with the \"su\" command? "));
699 printf ("%s", subshell_prompt
);
707 restore_console (void)
709 handle_console (CONSOLE_RESTORE
);
715 do_execute (shell
, 0, 0);
719 do_execute (const char *shell
, const char *command
, int flags
)
721 #ifdef HAVE_SUBSHELL_SUPPORT
722 char *new_dir
= NULL
;
726 char *old_vfs_dir
= 0;
728 if (!vfs_current_is_local ())
729 old_vfs_dir
= strdup (vfs_get_current_dir ());
738 unlink (control_file
);
740 if (!use_subshell
&& !(flags
& EXECUTE_INTERNAL
)){
741 printf ("%s%s%s\n", last_paused
? "\r\n":"", prompt
, command
);
745 #ifdef HAVE_SUBSHELL_SUPPORT
746 if (use_subshell
&& !(flags
& EXECUTE_INTERNAL
)){
749 /* We don't care if it died, higher level takes care of this */
751 invoke_subshell (command
, VISIBLY
, old_vfs_dir
? 0 : &new_dir
);
753 invoke_subshell (command
, VISIBLY
, &new_dir
);
757 my_system (flags
, shell
, command
);
760 if (!(flags
& EXECUTE_INTERNAL
)){
761 if ((pause_after_run
== pause_always
||
762 (pause_after_run
== pause_on_dumb_terminals
&&
763 !xterm_flag
&& !console_flag
)) && !quit
){
764 printf (_("Press any key to continue..."));
771 if (output_lines
&& keybar_visible
) {
780 handle_console (CONSOLE_SAVE
);
781 edition_post_exec ();
783 #ifdef HAVE_SUBSHELL_SUPPORT
785 do_possible_cd (new_dir
);
790 mc_chdir (old_vfs_dir
);
795 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
797 parse_control_file ();
799 unlink (control_file
);
805 /* Executes a command */
807 shell_execute (char *command
, int flags
)
809 #ifdef HAVE_SUBSHELL_SUPPORT
811 if (subshell_state
== INACTIVE
|| force_subshell_execution
)
812 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
814 message (1, MSG_ERROR
, _(" The shell is already running a command "));
817 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
821 execute (char *command
)
823 shell_execute (command
, 0);
829 free_completions (input_w (cmdline
));
830 dlg_one_down (midnight_dlg
);
834 quit_cmd_internal (int quiet
)
838 if (quiet
|| !confirm_exit
){
841 if (query_dialog (_(" The Midnight Commander "),
842 _(" Do you really want to quit the Midnight Commander? "),
843 0, 2, _("&Yes"), _("&No")) == 0)
847 #ifdef HAVE_SUBSHELL_SUPPORT
849 midnight_dlg
->running
= 0;
851 if ((q
= exit_subshell ()))
853 midnight_dlg
->running
= 0;
862 quit_cmd_internal (0);
866 int quiet_quit_cmd (void)
868 print_last_revert
= 1;
869 quit_cmd_internal (1);
874 * Touch window and refresh window functions
877 /* This routine untouches the first line on both panels in order */
878 /* to avoid the refreshing the menu bar */
887 repaint_screen (void)
900 repaint_screen (void)
907 /* Wrapper for do_subshell_chdir, check for availability of subshell */
909 subshell_chdir (char *directory
)
911 #ifdef HAVE_SUBSHELL_SUPPORT
913 if (vfs_current_is_local ())
914 do_subshell_chdir (directory
, 0, 1);
920 directory_history_add (WPanel
* panel
, char *s
)
922 if (!panel
->dir_history
) {
923 panel
->dir_history
= malloc (sizeof (Hist
));
924 memset (panel
->dir_history
, 0, sizeof (Hist
));
925 panel
->dir_history
->text
= strdup (s
);
928 if (!strcmp (panel
->dir_history
->text
, s
))
930 if (panel
->dir_history
->next
) {
931 if (panel
->dir_history
->next
->text
) {
932 free (panel
->dir_history
->next
->text
);
933 panel
->dir_history
->next
->text
= 0;
936 panel
->dir_history
->next
= malloc (sizeof (Hist
));
937 memset (panel
->dir_history
->next
, 0, sizeof (Hist
));
938 panel
->dir_history
->next
->prev
= panel
->dir_history
;
940 panel
->dir_history
= panel
->dir_history
->next
;
941 panel
->dir_history
->text
= strdup (s
);
943 panel_update_marks (panel
);
946 /* Changes the current panel directory */
948 _do_panel_cd (WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
950 char *directory
, *olddir
;
951 char temp
[MC_MAXPATHLEN
];
955 struct vfs_stamping
*parent
;
957 olddir
= strdup (panel
->cwd
);
959 /* Convert *new_path to a suitable pathname, handle ~user */
961 if (cd_type
== cd_parse_command
){
962 while (*new_dir
== ' ')
965 if (!strcmp (new_dir
, "-")){
966 strcpy (temp
, panel
->lwd
);
970 directory
= *new_dir
? new_dir
: home_dir
;
972 if (mc_chdir (directory
) == -1){
973 strcpy (panel
->cwd
, olddir
);
978 /* Success: save previous directory, shutdown status of previous dir */
979 strcpy (panel
->lwd
, olddir
);
980 free_completions (input_w (cmdline
));
982 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
985 oldvfs
= vfs_type (olddir
);
986 oldvfsid
= vfs_ncs_getid (oldvfs
, olddir
, &parent
);
987 vfs_add_noncurrent_stamps (oldvfs
, oldvfsid
, parent
);
988 vfs_rm_parents (parent
);
992 subshell_chdir (panel
->cwd
);
994 /* Reload current panel */
995 clean_dir (&panel
->dir
, panel
->count
);
996 panel
->count
= do_load_dir (&panel
->dir
, panel
->sort_type
,
997 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
1001 panel
->dirs_marked
= 0;
1003 panel
->searching
= 0;
1004 cd_try_to_select (panel
);
1006 panel_update_contents (panel
);
1011 do_panel_cd (WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
1015 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
1017 directory_history_add (cpanel
, cpanel
->cwd
);
1022 do_cd (char *new_dir
, enum cd_enum exact
)
1024 return (do_panel_cd (cpanel
, new_dir
, exact
));
1028 directory_history_next (WPanel
* panel
)
1030 if (!panel
->dir_history
->next
)
1032 if (_do_panel_cd (panel
, panel
->dir_history
->next
->text
, cd_exact
))
1033 panel
->dir_history
= panel
->dir_history
->next
;
1034 panel_update_marks (panel
);
1038 directory_history_prev (WPanel
* panel
)
1040 if (!panel
->dir_history
->prev
)
1042 if (_do_panel_cd (panel
, panel
->dir_history
->prev
->text
, cd_exact
))
1043 panel
->dir_history
= panel
->dir_history
->prev
;
1044 panel_update_marks (panel
);
1048 directory_history_list (WPanel
* panel
)
1051 /* must be at least two to show a history */
1052 if (panel
->dir_history
) {
1053 if (panel
->dir_history
->prev
|| panel
->dir_history
->next
) {
1054 s
= show_hist (panel
->dir_history
, panel
->widget
.x
, panel
->widget
.y
);
1057 r
= _do_panel_cd (panel
, s
, cd_exact
);
1059 directory_history_add (panel
, panel
->cwd
);
1066 #ifdef HAVE_SUBSHELL_SUPPORT
1068 load_prompt (int fd
, void *unused
)
1070 if (!read_subshell_prompt (QUIETLY
))
1073 if (command_prompt
){
1076 prompt
= strip_ctrl_codes (subshell_prompt
);
1077 prompt_len
= strlen (prompt
);
1079 /* Check for prompts too big */
1080 if (prompt_len
> COLS
- 8) {
1081 prompt
[COLS
- 8 ] = 0;
1082 prompt_len
= COLS
- 8;
1084 label_set_text (the_prompt
, prompt
);
1085 winput_set_origin ((WInput
*)cmdline
, prompt_len
, COLS
-prompt_len
);
1087 /* since the prompt has changed, and we are called from one of the
1088 * get_event channels, the prompt updating does not take place
1089 * automatically: force a cursor update and a screen refresh
1091 if (current_dlg
== midnight_dlg
){
1092 update_cursor (midnight_dlg
);
1101 /* The user pressed the enter key */
1103 menu_bar_event (Gpm_Event
*event
, void *x
)
1105 if (event
->type
!= GPM_DOWN
)
1111 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1113 maybe_cd (int char_code
, int move_up_dir
)
1115 if (navigate_with_arrows
){
1116 if (!input_w (cmdline
)->buffer
[0]){
1118 do_cd ("..", cd_exact
);
1121 if (S_ISDIR (selection (cpanel
)->buf
.st_mode
)
1122 || link_isdir (selection (cpanel
))){
1123 do_cd (selection (cpanel
)->fname
, cd_exact
);
1132 set_sort_to (WPanel
*p
, sortfn
*sort_order
)
1134 p
->sort_type
= sort_order
;
1136 /* The directory is already sorted, we have to load the unsorted stuff */
1137 if (sort_order
== (sortfn
*) unsorted
){
1140 current_file
= strdup (cpanel
->dir
.list
[cpanel
->selected
].fname
);
1141 panel_reload (cpanel
);
1142 try_to_select (cpanel
, current_file
);
1143 free (current_file
);
1154 if (!SELECTED_IS_PANEL
)
1158 sort_order
= sort_box (p
->sort_type
, &p
->reverse
, &p
->case_sensitive
);
1160 if (sort_order
== 0)
1163 p
->sort_type
= sort_order
;
1165 /* The directory is already sorted, we have to load the unsorted stuff */
1166 if (sort_order
== (sortfn
*) unsorted
){
1169 current_file
= strdup (cpanel
->dir
.list
[cpanel
->selected
].fname
);
1170 panel_reload (cpanel
);
1171 try_to_select (cpanel
, current_file
);
1172 free (current_file
);
1182 sel_dir
= tree (selection (cpanel
)->fname
);
1184 do_cd(sel_dir
, cd_exact
);
1189 #if SOMEDAY_WE_WILL_FINISH_THIS_CODE
1194 newmode
= listmode_edit ("half <type,>name,|,size:8,|,perm:4+");
1195 message (0, " Listing format edit ", " New mode is \"%s\" ", newmode
);
1201 void init_menu () {};
1202 void done_menu () {};
1204 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
1205 static menu_entry PanelMenu
[] = {
1206 { ' ', N_("&Listing mode..."), 'L', listing_cmd
},
1207 { ' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
1208 { ' ', N_("&Info C-x i"), 'I', info_cmd
},
1209 { ' ', N_("&Tree"), 'T', tree_cmd
},
1210 { ' ', "", ' ', 0 },
1211 { ' ', N_("&Sort order..."), 'S', sort_cmd
},
1212 { ' ', "", ' ', 0 },
1213 { ' ', N_("&Filter..."), 'F', filter_cmd
},
1215 { ' ', "", ' ', 0 },
1216 { ' ', N_("&Network link..."), 'N', netlink_cmd
},
1217 { ' ', N_("FT&P link..."), 'P', ftplink_cmd
},
1219 { ' ', "", ' ', 0 },
1221 { ' ', N_("&Drive... M-d"), 'D', drive_cmd_a
},
1223 { ' ', N_("&Rescan C-r"), 'R', reread_cmd
}
1226 static menu_entry RightMenu
[] = {
1227 { ' ', N_("&Listing mode..."), 'L', listing_cmd
},
1228 { ' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
1229 { ' ', N_("&Info C-x i"), 'I', info_cmd
},
1230 { ' ', N_("&Tree"), 'T', tree_cmd
},
1231 { ' ', "", ' ', 0 },
1232 { ' ', N_("&Sort order..."), 'S', sort_cmd
},
1233 { ' ', "", ' ', 0 },
1234 { ' ', N_("&Filter..."), 'F', filter_cmd
},
1236 { ' ', "", ' ', 0 },
1237 { ' ', N_("&Network link..."), 'N', netlink_cmd
},
1238 { ' ', N_("FT&P link..."), 'P', ftplink_cmd
},
1240 { ' ', "", ' ', 0 },
1242 { ' ', N_("&Drive... M-d"), 'D', drive_cmd_b
},
1244 { ' ', N_("&Rescan C-r"), 'R', reread_cmd
}
1247 static menu_entry FileMenu
[] = {
1248 { ' ', N_("&User menu F2"), 'U', user_menu_cmd
},
1249 { ' ', N_("&View F3"), 'V', view_cmd
},
1250 { ' ', N_("&Filtered view M-!"), 'F', filtered_view_cmd
},
1251 { ' ', N_("&Edit F4"), 'E', edit_cmd
},
1252 { ' ', N_("&Copy F5"), 'C', copy_cmd
},
1253 { ' ', N_("c&Hmod C-x c"), 'H', chmod_cmd
},
1255 { ' ', N_("&Link C-x l"), 'L', link_cmd
},
1256 { ' ', N_("&SymLink C-x s"), 'S', symlink_cmd
},
1257 { ' ', N_("edit s&Ymlink C-x C-s"), 'Y', edit_symlink_cmd
},
1258 { ' ', N_("ch&Own C-x o"), 'O', chown_cmd
},
1259 { ' ', N_("&Advanced chown "), 'A', chown_advanced_cmd
},
1261 { ' ', N_("&Rename/Move F6"), 'R', ren_cmd
},
1262 { ' ', N_("&Mkdir F7"), 'M', mkdir_cmd
},
1263 { ' ', N_("&Delete F8"), 'D', delete_cmd
},
1264 { ' ', N_("&Quick cd M-c"), 'Q', quick_cd_cmd
},
1265 { ' ', "", ' ', 0 },
1266 { ' ', N_("select &Group M-+"), 'G', select_cmd
},
1267 { ' ', N_("u&Nselect group M-\\"),'N', unselect_cmd
},
1268 { ' ', N_("reverse selec&Tion M-*"), 'T', reverse_selection_cmd
},
1269 { ' ', "", ' ', 0 },
1270 { ' ', N_("e&Xit F10"), 'X', (callfn
) quit_cmd
}
1273 void external_panelize (void);
1274 static menu_entry CmdMenu
[] = {
1275 /* I know, I'm lazy, but the tree widget when it's not running
1276 * as a panel still has some problems, I have not yet finished
1277 * the WTree widget port, sorry.
1279 { ' ', N_("&Directory tree"), 'D', tree_box
},
1280 { ' ', N_("&Find file M-?"), 'F', find_cmd
},
1282 { ' ', N_("s&Wap panels C-u"), 'W', swap_cmd
},
1283 { ' ', N_("switch &Panels on/off C-o"), 'P', view_other_cmd
},
1285 { ' ', N_("&Compare directories C-x d"), 'C', compare_dirs_cmd
},
1286 { ' ', N_("e&Xternal panelize C-x !"), 'X', external_panelize
},
1288 { ' ', N_("show directory s&Izes"), 'I', dirsizes_cmd
},
1290 { ' ', "", ' ', 0 },
1291 { ' ', N_("command &History"), 'H', history_cmd
},
1292 { ' ', N_("di&Rectory hotlist C-\\"), 'R', quick_chdir_cmd
},
1294 { ' ', N_("&Active VFS list C-x a"), 'A', reselect_vfs
},
1296 #ifdef WITH_BACKGROUND
1297 { ' ', N_("&Background jobs C-x j"), 'B', jobs_cmd
},
1299 { ' ', "", ' ', 0 },
1300 #ifdef USE_EXT2FSLIB
1301 { ' ', N_("&Undelete files (ext2fs only)"), 'U', undelete_cmd
},
1304 { ' ', N_("&Listing format edit"), 'L', listmode_cmd
},
1306 { ' ', N_("&Extension file edit"), 'E', ext_cmd
},
1307 { ' ', N_("&Menu file edit"), 'M', menu_edit_cmd
}
1310 /* Must keep in sync with the constants in menu_cmd */
1311 static menu_entry OptMenu
[] = {
1312 { ' ', N_("&Configuration..."), 'C', configure_box
},
1313 { ' ', N_("&Layout..."), 'L', layout_cmd
},
1314 { ' ', N_("c&Onfirmation..."), 'O', confirm_box
},
1315 { ' ', N_("&Display bits..."), 'D', display_bits_box
},
1316 #if !defined(HAVE_X) && !defined(OS2_NT)
1317 { ' ', N_("learn &Keys..."), 'K', learn_keys
},
1320 { ' ', N_("&Virtual FS..."), 'V', configure_vfs
},
1322 { ' ', "", ' ', 0 },
1323 { ' ', N_("&Save setup"), 'S', save_setup_cmd
}
1326 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
1330 static Menu MenuBarEmpty
[5];
1339 MenuBar
[0] = create_menu (_(" Left "), PanelMenu
, menu_entries (PanelMenu
));
1341 MenuBar
[0] = create_menu ( horizontal_split
? _(" Above ") : _(" Left "),
1342 PanelMenu
, menu_entries (PanelMenu
));
1344 MenuBar
[1] = create_menu (_(" File "), FileMenu
, menu_entries (FileMenu
));
1345 MenuBar
[2] = create_menu (_(" Command "), CmdMenu
, menu_entries (CmdMenu
));
1346 MenuBar
[3] = create_menu (_(" Options "), OptMenu
, menu_entries (OptMenu
));
1349 MenuBar
[4] = create_menu (_(" Right "), RightMenu
, menu_entries (PanelMenu
));
1351 MenuBar
[4] = create_menu (horizontal_split
? _(" Below ") : _(" Right "),
1352 RightMenu
, menu_entries (PanelMenu
));
1353 for (i
= 0; i
< 5; i
++)
1354 MenuBarEmpty
[i
] = create_menu (MenuBar
[i
]->name
, 0, 0);
1356 #endif /* ! HAVE_XVIEW */
1365 for (i
= 0; i
< 5; i
++){
1366 destroy_menu (MenuBar
[i
]);
1368 destroy_menu (MenuBarEmpty
[i
]);
1371 for (i
= 0; i
< 4; i
++){
1372 destroy_menu (MenuBar
[i
]);
1379 menu_last_selected_cmd (void)
1381 the_menubar
->active
= 1;
1382 the_menubar
->dropped
= drop_menus
;
1383 the_menubar
->previous_selection
= dlg_item_number (midnight_dlg
);
1384 dlg_select_widget (midnight_dlg
, the_menubar
);
1390 if (the_menubar
->active
)
1393 if (get_current_index () == 0)
1394 the_menubar
->selected
= 0;
1396 the_menubar
->selected
= 4;
1397 menu_last_selected_cmd ();
1400 /* Flag toggling functions */
1402 toggle_confirm_delete (void)
1404 confirm_delete
= !confirm_delete
;
1408 toggle_fast_reload (void)
1410 fast_reload
= !fast_reload
;
1411 if (fast_reload_w
== 0 && fast_reload
){
1412 message (0, _(" Information "),
1413 _(" Using the fast reload option may not reflect the exact \n"
1414 " directory contents. In this cases you'll need to do a \n"
1415 " manual reload of the directory. See the man page for \n"
1422 toggle_mix_all_files (void)
1424 mix_all_files
= !mix_all_files
;
1425 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1429 toggle_show_backup (void)
1431 show_backups
= !show_backups
;
1432 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1436 toggle_show_hidden (void)
1438 show_dot_files
= !show_dot_files
;
1439 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1443 toggle_show_mini_status (void)
1445 show_mini_info
= !show_mini_info
;
1446 paint_panel (cpanel
);
1447 if (get_other_type () == view_listing
)
1448 paint_panel (opanel
);
1452 toggle_align_extensions (void)
1454 align_extensions
= !align_extensions
;
1457 #ifndef PORT_HAS_CREATE_PANELS
1459 create_panels (void)
1465 char original_dir
[1024];
1467 original_dir
[0] = 0;
1469 if (boot_current_is_left
){
1472 current_mode
= startup_left_mode
;
1473 other_mode
= startup_right_mode
;
1477 current_mode
= startup_right_mode
;
1478 other_mode
= startup_left_mode
;
1480 /* Creates the left panel */
1483 /* Ok, user has specified two dirs, save the original one,
1484 * since we may not be able to chdir to the proper
1485 * second directory later
1487 mc_get_current_wd (original_dir
, sizeof (original_dir
)-2);
1489 mc_chdir (this_dir
);
1491 set_display_type (current_index
, current_mode
);
1493 /* The other panel */
1495 if (original_dir
[0])
1496 mc_chdir (original_dir
);
1497 mc_chdir (other_dir
);
1499 set_display_type (other_index
, other_mode
);
1501 if (startup_left_mode
== view_listing
){
1502 current_panel
= left_panel
;
1505 current_panel
= right_panel
;
1507 current_panel
= left_panel
;
1510 /* Create the nice widgets */
1511 cmdline
= command_new (0, 0, 0);
1512 the_prompt
= label_new (0, 0, prompt
, NULL
);
1513 the_prompt
->transparent
= 1;
1514 the_bar
= buttonbar_new (keybar_visible
);
1517 the_hint
= label_new (0, 0, 0, NULL
);
1518 the_hint
->transparent
= 1;
1519 the_hint
->auto_adjust_cols
= 0;
1520 the_hint
->widget
.cols
= COLS
;
1524 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
, 5);
1526 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
+ 1, 3);
1527 the_bar2
= buttonbar_new (keybar_visible
);
1532 static void copy_current_pathname (void)
1534 if (!command_prompt
)
1537 stuff (input_w (cmdline
), cpanel
->cwd
, 0);
1538 if (cpanel
->cwd
[strlen (cpanel
->cwd
) - 1] != PATH_SEP
)
1539 stuff (input_w (cmdline
), PATH_SEP_STR
, 0);
1542 static void copy_other_pathname (void)
1544 if (get_other_type () != view_listing
)
1547 if (!command_prompt
)
1550 stuff (input_w (cmdline
), opanel
->cwd
, 0);
1551 if (cpanel
->cwd
[strlen (opanel
->cwd
) - 1] != PATH_SEP
)
1552 stuff (input_w (cmdline
), PATH_SEP_STR
, 0);
1555 static void copy_readlink (WPanel
*panel
)
1557 if (!command_prompt
)
1559 if (S_ISLNK (selection (panel
)->buf
.st_mode
)) {
1560 char buffer
[MC_MAXPATHLEN
];
1561 char *p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1564 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
);
1568 stuff (input_w (cmdline
), buffer
, 0);
1573 static void copy_current_readlink (void)
1575 copy_readlink (cpanel
);
1578 static void copy_other_readlink (void)
1580 if (get_other_type () != view_listing
)
1582 copy_readlink (opanel
);
1585 /* Inserts the selected file name into the input line */
1586 /* Exported so that the command modules uses it */
1587 void copy_prog_name (void)
1590 if (!command_prompt
)
1593 if (get_current_type () == view_tree
){
1594 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1595 tmp
= name_quote (tree
->selected_ptr
->name
, 1);
1597 tmp
= name_quote (selection (cpanel
)->fname
, 1);
1598 stuff (input_w (cmdline
), tmp
, 1);
1602 static void copy_tagged (WPanel
*panel
)
1606 if (!command_prompt
)
1608 input_disable_update (input_w (cmdline
));
1610 for (i
= 0; i
< panel
->count
; i
++)
1611 if (panel
->dir
.list
[i
].f
.marked
) {
1612 char *tmp
= name_quote (panel
->dir
.list
[i
].fname
, 1);
1613 stuff (input_w (cmdline
), tmp
, 1);
1617 char *tmp
= name_quote (panel
->dir
.list
[panel
->selected
].fname
, 1);
1618 stuff (input_w (cmdline
), tmp
, 1);
1621 input_enable_update (input_w (cmdline
));
1624 static void copy_current_tagged (void)
1626 copy_tagged (cpanel
);
1629 static void copy_other_tagged (void)
1631 if (get_other_type () != view_listing
)
1633 copy_tagged (opanel
);
1636 static void do_suspend_cmd (void)
1640 if (console_flag
&& !use_subshell
)
1645 struct sigaction sigtstp_action
;
1647 /* Make sure that the SIGTSTP below will suspend us directly,
1648 without calling ncurses' SIGTSTP handler; we *don't* want
1649 ncurses to redraw the screen immediately after the SIGCONT */
1650 sigaction (SIGTSTP
, &startup_handler
, &sigtstp_action
);
1652 kill (getpid (), SIGTSTP
);
1654 /* Restore previous SIGTSTP action */
1655 sigaction (SIGTSTP
, &sigtstp_action
, NULL
);
1659 if (console_flag
&& !use_subshell
)
1660 handle_console (CONSOLE_SAVE
);
1662 edition_post_exec ();
1665 void suspend_cmd (void)
1669 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1673 void init_labels (Widget
*paneletc
)
1675 define_label (midnight_dlg
, paneletc
, 1, _("Help"), help_cmd
);
1676 define_label (midnight_dlg
, paneletc
, 2, _("Menu"), user_menu_cmd
);
1677 define_label (midnight_dlg
, paneletc
, 9, _("PullDn"), menu_cmd
);
1678 define_label (midnight_dlg
, paneletc
, 10, _("Quit"), (voidfn
) quit_cmd
);
1682 static key_map ctl_x_map
[] = {
1683 { XCTRL('c'), (callfn
) quit_cmd
},
1685 { 'a', reselect_vfs
},
1687 { 'd', compare_dirs_cmd
},
1689 { 'p', copy_current_pathname
},
1690 { XCTRL('p'), copy_other_pathname
},
1691 { 't', copy_current_tagged
},
1692 { XCTRL('t'), copy_other_tagged
},
1698 { XCTRL('l'), other_symlink_cmd
},
1699 { 's', symlink_cmd
},
1700 { XCTRL('s'), edit_symlink_cmd
},
1701 { 'r', copy_current_readlink
},
1702 { XCTRL('r'), copy_other_readlink
},
1705 { 'i', info_cmd_no_menu
},
1706 { 'q', quick_cmd_no_menu
},
1708 { 'h', add2hotlist_cmd
},
1709 { '!', external_panelize
},
1710 #ifdef WITH_BACKGROUND
1713 #ifdef HAVE_SETSOCKOPT
1714 { '%', source_routing
},
1719 static int ctl_x_map_enabled
= 0;
1721 static void ctl_x_cmd (int ignore
)
1723 ctl_x_map_enabled
= 1;
1726 static void nothing ()
1730 static key_map default_map
[] = {
1732 { KEY_F(19), menu_last_selected_cmd
},
1733 { KEY_F(20), (key_callback
) quiet_quit_cmd
},
1735 /* Copy useful information to the command line */
1736 { ALT('\n'), copy_prog_name
},
1737 { ALT('\r'), copy_prog_name
},
1738 { ALT('a'), copy_current_pathname
},
1739 { ALT('A'), copy_other_pathname
},
1741 { ALT('c'), quick_cd_cmd
},
1743 /* To access the directory hotlist */
1744 { XCTRL('\\'), quick_chdir_cmd
},
1747 { XCTRL('z'), suspend_cmd
},
1749 /* The filtered view command */
1750 { ALT('!'), filtered_view_cmd_cpanel
},
1753 { ALT('?'), find_cmd
},
1756 { XCTRL('r'), reread_cmd
},
1758 { ALT('t'), toggle_listing_cmd
},
1762 { XCTRL('u'), swap_cmd
},
1765 { XCTRL('o'), view_other_cmd
},
1768 /* Control-X keybindings */
1769 { XCTRL('x'), ctl_x_cmd
},
1771 /* Trap dlg's exit commands */
1772 { ESC_CHAR
, nothing
},
1773 { XCTRL('c'), nothing
},
1774 { XCTRL('g'), nothing
},
1780 static void setup_sigwinch ()
1783 struct sigaction act
, oact
;
1785 # if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
1787 act
.sa_handler
= flag_winch
;
1788 sigemptyset (&act
.sa_mask
);
1791 act
.sa_flags
|= SA_RESTART
;
1793 sigaction (SIGWINCH
, &act
, &oact
);
1802 /* Call all the inits */
1804 meta (stdscr
, eight_bit_clean
);
1806 SLsmg_Display_Eight_Bit
= full_eight_bits
? 128 : 160;
1811 #define setup_sigwinch()
1819 init_uid_gid_cache ();
1822 if (baudrate () < 9600 || slow_terminal
){
1829 midnight_colors
[0] = 0;
1830 midnight_colors
[1] = REVERSE_COLOR
; /* FOCUSC */
1831 midnight_colors
[2] = INPUT_COLOR
; /* HOT_NORMALC */
1832 midnight_colors
[3] = NORMAL_COLOR
; /* HOT_FOCUSC */
1835 static void setup_mc (void)
1846 #ifdef HAVE_SUBSHELL_SUPPORT
1848 add_select_channel (subshell_pty
, load_prompt
, 0);
1854 static void setup_dummy_mc (const char *file
)
1856 char d
[MC_MAXPATHLEN
];
1858 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1862 /* Create a fake current_panel, this is needed because the
1863 * expand_format routine will use current panel.
1865 strcpy (cpanel
->cwd
, d
);
1866 cpanel
->selected
= 0;
1868 cpanel
->dir
.list
[0].fname
= (char *) file
;
1871 static void done_mc ()
1877 * We sync the profiles since the hotlist may have changed, while
1878 * we only change the setup data if we have the auto save feature set
1880 if (auto_save_setup
)
1881 save_setup (); /* does also call save_hotlist */
1885 vfs_add_current_stamps ();
1886 if (xterm_flag
&& xterm_hintbar
)
1887 set_hintbar(_("Thank you for using GNU Midnight Commander"));
1890 /* This should be called after destroy_dlg since panel widgets
1891 * save their state on the profiles
1893 static void done_mc_profile ()
1895 if (!auto_save_setup
)
1896 profile_forget_profile (profile_name
);
1902 /* This routine only handles cpanel, and opanel, it is easy to
1903 * change to use npanels, just loop over the number of panels
1904 * and use get_panel_widget (i) and make the test done below
1906 void make_panels_dirty ()
1909 panel_update_contents (cpanel
);
1911 if ((get_other_type () == view_listing
) && opanel
->dirty
)
1912 panel_update_contents (opanel
);
1915 /* In OS/2 and Windows NT people want to actually type the '\' key frequently */
1917 # define check_key_backslash(x) 0
1919 # define check_key_backslash(x) ((x) == '\\')
1922 int midnight_callback (struct Dlg_head
*h
, int id
, int msg
)
1929 /* Speed up routine: now, we just set the */
1931 make_panels_dirty ();
1935 if (ctl_x_map_enabled
){
1936 ctl_x_map_enabled
= 0;
1937 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1938 if (id
== ctl_x_map
[i
].key_code
){
1939 (*ctl_x_map
[i
].fn
)(id
);
1944 if (id
== KEY_F(10) && !the_menubar
->active
){
1950 free_completions (input_w (cmdline
));
1952 /* On Linux, we can tell the difference */
1953 if (id
== '\n' && ctrl_pressed ()){
1958 if (id
== '\n' && input_w (cmdline
)->buffer
[0]){
1959 send_message_to (h
, (Widget
*) cmdline
, WIDGET_KEY
, id
);
1963 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
)) &&
1964 !quote
&& !cpanel
->searching
) {
1965 if(!only_leading_plus_minus
) {
1966 /* Special treatement, since the input line will eat them */
1972 if (check_key_backslash (id
) || id
== '-'){
1978 reverse_selection_cmd ();
1981 } else if (command_prompt
&& !strlen (input_w (cmdline
)->buffer
)) {
1982 /* Special treatement '+', '-', '\', '*' only when this is
1983 * first char on input line
1991 if (check_key_backslash (id
) || id
== '-') {
1997 reverse_selection_cmd ();
2004 case DLG_HOTKEY_HANDLED
:
2005 if (get_current_type () == view_listing
)
2006 cpanel
->searching
= 0;
2009 case DLG_UNHANDLED_KEY
:
2010 if (command_prompt
){
2013 v
= send_message_to (h
, (Widget
*) cmdline
, WIDGET_KEY
, id
);
2017 if (ctl_x_map_enabled
){
2018 ctl_x_map_enabled
= 0;
2019 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
2020 if (id
== ctl_x_map
[i
].key_code
){
2021 (*ctl_x_map
[i
].fn
)(id
);
2025 for (i
= 0; default_map
[i
].key_code
; i
++){
2026 if (id
== default_map
[i
].key_code
){
2027 (*default_map
[i
].fn
)(id
);
2032 return MSG_NOT_HANDLED
;
2036 /* We handle the special case of the output lines */
2038 attrset (SELECTED_COLOR
);
2039 if (console_flag
&& output_lines
)
2040 show_console_contents (output_start_y
,
2041 LINES
-output_lines
-keybar_visible
-1,
2042 LINES
-keybar_visible
-1);
2047 return default_dlg_callback (h
, id
, msg
);
2051 /* This should be rewritten in order to support as many panel containers as
2055 widget_data containers
[2];
2056 int containers_no
= 2;
2059 xtoolkit_panel_setup ()
2061 containers
[0] = x_create_panel_container (0);
2062 containers
[1] = x_create_panel_container (1);
2063 input_w (cmdline
)->widget
.wcontainer
= containers
[0];
2064 input_w (cmdline
)->widget
.area
= AREA_BOTTOM
;
2065 the_prompt
->widget
.wcontainer
= containers
[0];
2066 the_prompt
->widget
.area
= AREA_BOTTOM
;
2067 the_bar
->widget
.wcontainer
= containers
[0];
2068 the_bar
->widget
.area
= AREA_TOP
;
2070 the_bar2
->widget
.wcontainer
= containers
[1];
2071 the_bar2
->widget
.area
= AREA_TOP
;
2073 get_panel_widget (0)->wcontainer
= containers
[0];
2074 get_panel_widget (0)->area
= AREA_RIGHT
;
2075 get_panel_widget (1)->wcontainer
= containers
[1];
2076 get_panel_widget (1)->area
= AREA_RIGHT
;
2077 the_menubar
->widget
.wcontainer
= (widget_data
) NULL
;
2080 # define xtoolkit_panel_setup()
2084 # define xtoolkit_panel_setup()
2087 #ifndef PORT_HAS_LOAD_HINT
2092 if (!the_hint
->widget
.parent
)
2095 if (!message_visible
&& (!xterm_flag
|| !xterm_hintbar
)){
2096 label_set_text (the_hint
, 0);
2100 if ((hint
= get_random_hint ())){
2105 set_hintbar ("The Midnight Commander " VERSION
2106 " (C) 1995-1997 the Free Software Foundation");
2112 setup_panels_and_run_mc ()
2116 xtoolkit_panel_setup ();
2117 tk_new_frame (midnight_dlg
, "p.");
2119 add_widget (midnight_dlg
, the_hint
);
2122 add_widgetl (midnight_dlg
, cmdline
, XV_WLAY_RIGHTOF
);
2123 add_widgetl (midnight_dlg
, the_prompt
, XV_WLAY_DONTCARE
);
2125 add_widget (midnight_dlg
, the_bar
);
2127 add_widget (midnight_dlg
, the_bar2
);
2129 if (boot_current_is_left
){
2136 add_widget (midnight_dlg
, get_panel_widget (first
));
2137 add_widget (midnight_dlg
, get_panel_widget (second
));
2138 add_widget (midnight_dlg
, the_menubar
);
2140 init_labels (get_panel_widget (0));
2141 init_labels (get_panel_widget (1));
2143 /* Run the Midnight Commander if no file was specified in the command line */
2144 run_dlg (midnight_dlg
);
2147 /* result must be free'd (I think this should go in util.c) */
2149 prepend_cwd_on_local (char *filename
)
2154 if (vfs_file_is_local (filename
)){
2155 if (*filename
== PATH_SEP
) /* an absolute pathname */
2156 return strdup (filename
);
2157 d
= malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
2158 mc_get_current_wd (d
, MC_MAXPATHLEN
);
2161 strcpy (d
+ l
, filename
);
2162 return canonicalize_pathname (d
);
2164 return strdup (filename
);
2167 #ifdef USE_INTERNAL_EDIT
2168 void edit (const char *file_name
, int startline
);
2171 mc_maybe_editor_or_viewer (void)
2175 if (!(view_one_file
|| edit_one_file
))
2178 /* Invoke the internal view/edit routine with:
2179 * the default processing and forcing the internal viewer/editor
2181 if (view_one_file
) {
2182 path
= prepend_cwd_on_local (view_one_file
);
2183 setup_dummy_mc (path
);
2184 view_file (path
, 0, 1);
2186 #ifdef USE_INTERNAL_EDIT
2188 path
= prepend_cwd_on_local ("");
2189 setup_dummy_mc (path
);
2190 edit (edit_one_file
, 1);
2194 midnight_shutdown
= 1;
2204 midnight_dlg
= create_dlg (0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
, "[main]", "midnight", 0);
2205 midnight_dlg
->has_menubar
= 1;
2207 #ifdef USE_INTERNAL_EDIT
2208 /* Check if we were invoked as an editor or file viewer */
2209 if (mc_maybe_editor_or_viewer ())
2216 setup_panels_and_run_mc ();
2220 midnight_shutdown
= 1;
2222 /* destroy_dlg destroys even cpanel->cwd, so we have to save a copy :) */
2223 if (print_last_wd
) {
2224 if (!vfs_current_is_local ())
2225 last_wd_string
= strdup (".");
2227 last_wd_string
= strdup (cpanel
->cwd
);
2232 destroy_dlg (midnight_dlg
);
2238 #include "features.inc"
2241 version (int verbose
)
2243 fprintf (stderr
, "The Midnight Commander %s\n", VERSION
);
2249 _("with mouse support on xterm%s.\n"),
2250 status_mouse_support
? _(" and the Linux console") : "");
2253 fprintf (stderr
, features
);
2255 write (stdout_fd
, ".", 1);
2258 #if defined (_OS_NT)
2259 /* Windows NT code */
2260 #define CONTROL_FILE "\\mc.%d.control"
2261 char control_file
[sizeof (CONTROL_FILE
) + 8];
2266 SetConsoleTitle ("GNU Midnight Commander");
2268 shell
= getenv ("COMSPEC");
2269 if (!shell
|| !*shell
)
2270 shell
= get_default_shell ();
2272 /* Default opening mode for files is binary, not text (CR/LF translation) */
2277 mc_home
= get_mc_lib_dir ();
2281 sigchld_handler_no_subshell (int sig
)
2291 init_sigfatals (void)
2293 /* Nothing to be done on the OS/2, Windows/NT */
2297 #elif defined (__os2__)
2299 # define CONTROL_FILE "\\mc.%d.control"
2300 char control_file
[sizeof (CONTROL_FILE
) + 8];
2305 /* .ado: This does not work: */
2306 /* DosSMSetTitle ((PSZ) "This is my app"); */
2308 DosSMSetTitle = SESMGR.DOSSMSETTITLE */
2309 shell
= getenv ("COMSPEC");
2310 if (!shell
|| !*shell
)
2311 shell
= get_default_shell ();
2313 mc_home
= get_mc_lib_dir ();
2317 sigchld_handler_no_subshell (int sig
)
2327 init_sigfatals (void)
2329 /* Nothing to be done on the OS/2, Windows/NT */
2334 #define CONTROL_FILE "/tmp/mc.%d.control"
2335 char control_file
[sizeof (CONTROL_FILE
) + 8];
2343 termvalue
= getenv ("TERM");
2345 fprintf (stderr
, _("The TERM environment variable is unset!\n"));
2349 if (force_xterm
|| (strncmp (termvalue
, "xterm", 5) == 0 || strcmp (termvalue
, "dtterm") == 0)){
2350 use_mouse_p
= XTERM_MOUSE
;
2353 printf ("\33]0;GNU Midnight Commander\7");
2356 #endif /* ! HAVE_X */
2357 shell
= getenv ("SHELL");
2358 if (!shell
|| !*shell
)
2359 shell
= strdup (getpwuid (geteuid ())->pw_shell
);
2360 if (!shell
|| !*shell
)
2363 sprintf (control_file
, CONTROL_FILE
, getpid ());
2364 my_putenv ("MC_CONTROL_FILE", control_file
);
2366 /* This is the directory, where MC was installed, on Unix this is LIBDIR */
2367 /* and can be overriden by the MCHOME environment variable */
2368 if ((mc_libdir
= getenv ("MCHOME")) != NULL
) {
2369 mc_home
= strdup (mc_libdir
);
2371 mc_home
= strdup (LIBDIR
);
2376 sigchld_handler_no_subshell (int sig
)
2384 /* COMMENT: if it were true that after the call to handle_console(..INIT)
2385 the value of console_flag never changed, we could simply not install
2386 this handler at all if (!console_flag && !use_subshell). */
2388 /* That comment is no longer true. We need to wait() on a sigchld
2389 handler (that's at least what the tarfs code expects currently). */
2392 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
2394 if (pid
== cons_saver_pid
){
2395 /* {{{ Someone has stopped or killed cons.saver; restart it */
2397 if (WIFSTOPPED (status
))
2398 kill (pid
, SIGCONT
);
2401 handle_console (CONSOLE_DONE
);
2402 handle_console (CONSOLE_INIT
);
2406 #endif /* ! SCO_FLAVOR */
2408 /* If we get here, some other child exited; ignore it */
2409 #endif /* ! HAVE_X */
2414 mc_fatal_signal (int signum
)
2419 char *args
[4] = { "gdb", NULL
, NULL
, NULL
};
2422 sprintf (buf
, "%d", getpid ());
2424 "Midnight Commander fatal error, PID=%d\n"
2425 "What to do: [e]xit, [s]tack trace, [a]ttach to process\n", getpid ());
2433 args
[1] = program_name
;
2437 fprintf (stderr
, "Could not fork, exiting\n");
2451 init_sigfatals (void)
2453 struct sigaction sa
;
2455 sa
.sa_hanlder
= mc_fatal_signal
;
2459 sigaction (SIGSEGV
, &sa
, NULL
);
2460 sigaction (SIGBUS
, &sa
, NULL
);
2461 sigaction (SIGFPE
, &sa
, NULL
);
2464 #define init_sigfatals()
2470 struct sigaction sigchld_action
;
2472 sigchld_action
.sa_handler
=
2473 #ifdef HAVE_SUBSHELL_SUPPORT
2474 use_subshell
? sigchld_handler
:
2476 sigchld_handler_no_subshell
;
2478 sigemptyset (&sigchld_action
.sa_mask
);
2481 sigchld_action
.sa_flags
= SA_RESTART
;
2483 sigchld_action
.sa_flags
= 0;
2486 sigaction (SIGCHLD
, &sigchld_action
, NULL
);
2489 #endif /* _OS_NT, __os2__, UNIX */
2491 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2492 extern int SLtt_Try_Termcap
;
2495 #ifndef PORT_WANTS_ARGP
2497 print_mc_usage (void)
2502 "mc [flags] [this_dir] [other_panel_dir]\n\n"
2503 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2504 "-a, --stickchars Force use of +, -, | for line drawing.\n"
2506 "-b, --nocolor Force black and white display.\n"
2507 #ifdef WITH_BACKGROUND
2508 "-B, --background [DEVEL-ONLY: Debug the background code]\n"
2510 "-c, --color Force color mode.\n"
2511 "-C, --colors Specify colors (use --help-colors to get a list).\n"
2512 #ifdef USE_INTERNAL_EDIT
2513 "-e, --edit Startup the internal editor.\n"
2515 "-d, --nomouse Disable mouse support.\n"
2516 "-f, --libdir Print configured paths.\n"
2517 "-h, --help Shows this help message.\n"
2518 "-k, --resetsoft Reset softkeys (HP terminals only) to their terminfo/termcap\n"
2520 "-P, --printwd At exit, print the last working directory.\n"
2521 "-s, --slow Disables verbose operation (for slow terminals).\n"
2522 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2523 "-t, --termcap Activate support for the TERMCAP variable.\n"
2526 "-l, --ftplog file Log ftpfs commands to the file.\n"
2528 #if defined(HAVE_SLANG) && defined(OS2_NT)
2529 "-S, --createcmdile Create command file to set default directory upon exit.\n"
2532 #ifdef HAVE_SUBSHELL_SUPPORT
2533 "-u, --nosubshell Disable the concurrent subshell mode.\n"
2534 "-U, --subshell Force the concurrent subshell mode.\n"
2535 "-r, --forceexec Force subshell execution.\n"
2537 "-v, --view fname Start up into the viewer mode.\n"
2538 "-V, --version Report version and configuration options.\n"
2539 "-x, --xterm Force xterm mouse support and screen save/restore.\n"
2540 #ifdef HAVE_SUBSHELL_SUPPORT
2541 "-X, --dbgsubshell [DEVEL-ONLY: Debug the subshell].\n"
2545 #endif /* PORT_WANTS_ARGP */
2548 print_color_usage (void)
2551 "--colors KEYWORD={FORE},{BACK}\n\n"
2552 "{FORE} and {BACK} can be ommited, and the default will be used\n"
2555 " Global: errors, reverse, gauge, input\n"
2556 " File display: normal, selected, marked, markselect\n"
2557 " Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus\n"
2558 " Menus: menu, menuhot, menusel, menuhotsel\n"
2559 " Help: helpnormal, helpitalic, helplink, helpslink\n"
2560 " File types: directory, execute, link, device, special, core\n"
2563 " black, gray, red, brightred, green, brightgreen, brown,\n"
2564 " yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
2565 " brightcyan, lightgray and white\n\n");
2571 probably_finish_program (void)
2573 if (finish_program
){
2586 process_args (int c
, char *option_arg
)
2602 fprintf (stderr
, _("Library directory for the Midnight Commander: %s\n"), mc_home
);
2607 fprintf (stderr
, _("Option -m is obsolete. Please look at Display Bits... in the Option's menu\n"));
2613 ftpfs_set_debug (option_arg
);
2620 batch_file_name
= option_arg
;
2625 use_mouse_p
= NO_MOUSE
;
2629 #ifdef HAVE_SUBSHELL_SUPPORT
2635 #ifdef HAVE_SUBSHELL_SUPPORT
2641 #ifdef HAVE_SUBSHELL_SUPPORT
2647 #ifdef HAVE_SUBSHELL_SUPPORT
2648 force_subshell_execution
= 1;
2653 print_color_usage ();
2658 #ifndef PORT_WANTS_ARGP
2665 #ifdef PORT_WANTS_ARGP
2666 static struct argp_option argp_options
[] = {
2667 #ifdef WITH_BACKGROUND
2668 { "background", 'B', NULL
, 0, N_("[DEVEL-ONLY: Debug the background code]"), 0 },
2670 #if defined(HAVE_SLANG) && defined(OS2_NT)
2671 { "createcmdfile", 'S', "CMDFILE", , 0, N_("Create command file to set default directory upon exit."), 1 },
2673 { "color", 'c', NULL
, 0, N_("Force color mode."), 0 },
2674 { "colors", 'C', "COLORS", 0, N_("Specify colors (use --help-colors to get a list)."), 1 },
2675 #ifdef HAVE_SUBSHELL_SUPPORT
2676 { "dbgsubshell", 'X', NULL
, 0, N_("[DEVEL-ONLY: Debug the subshell."), 0 },
2678 { "edit", 'e', "EDIT", 0, N_("Startup the internal editor."), 1 },
2679 { "help", 'h', NULL
, 0, N_("Shows this help message."), 0 },
2680 { "help-colors", 'H', NULL
, 0, N_("Help on how to specify colors."), 0 },
2682 { "ftplog", 'l', "FTPLOG", 0, N_("Log ftpfs commands to the file."), 1 },
2684 { "libdir", 'f', NULL
, 0, N_("Prints out the configured paths."), 0 },
2685 { NULL
, 'm', NULL
, OPTION_HIDDEN
, NULL
, 0 },
2686 { "nocolor", 'b', NULL
, 0, N_("Force black and white display."), 0 },
2687 { "nomouse", 'd', NULL
, 0, N_("Disable mouse support."), 0 },
2688 #ifdef HAVE_SUBSHELL_SUPPORT
2689 { "subshell", 'U', NULL
, 0, N_("Force the concurrent subshell mode"), 0 },
2690 { "nosubshell", 'u', NULL
, 0, N_("Disable the concurrent subshell mode."), 0 },
2691 { "forceexec", 'r', NULL
, 0, N_("Force subshell execution."), 0 },
2693 { "printwd", 'P', NULL
, 0, N_("At exit, print the last working directory."), 0 },
2694 { "resetsoft", 'k', NULL
, 0, N_("Reset softkeys (HP terminals only) to their terminfo/termcap default."), 0},
2695 { "slow", 's', NULL
, 0, N_("Disables verbose operation (for slow terminals)."), 0 },
2696 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2697 { "stickchars", 'a', NULL
, 0, N_("Use simple symbols for line drawing."), 0 },
2699 #ifdef HAVE_SUBSHELL_SUPPORT
2701 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2702 { "termcap", 't', NULL
, 0, N_("Activate support for the TERMCAP variable."), 0 },
2704 { "version", 'V', NULL
, 0, N_("Report versionand configuration options."), 0 },
2705 { "view", 'v', NULL
, 0, N_("Start up into the viewer mode."), 0 },
2706 { "xterm", 'x', NULL
, 0, N_("Force xterm mouse support and screen save/restore"), 0 },
2707 { "geometry", GEOMETRY_KEY
, "GEOMETRY", 0, N_("Geometry for the window"), 0 },
2708 { "nowindows", NOWIN_KEY
, NULL
, 0, N_("No windows opened at startup"), 0 },
2709 { NULL
, 0, NULL
, 0, NULL
},
2712 GList
*directory_list
= 0;
2713 GList
*geometry_list
= 0;
2717 parse_an_arg (int key
, char *arg
, struct argp_state
*state
)
2720 #ifdef WITH_BACKGROUND
2722 background_wait
= 1;
2734 reset_hp_softkeys
= 1;
2742 force_ugly_line_drawing
= 1;
2749 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2751 SLtt_Try_Termcap
= 1;
2756 geometry_list
= g_list_append (geometry_list
, arg
);
2770 process_args (key
, arg
);
2775 edit_one_file
= strdup (arg
);
2776 else if (view_one_file
)
2777 view_one_file
= strdup (arg
);
2779 directory_list
= g_list_append (directory_list
, arg
);
2784 static struct argp mc_argp_parser
= {
2785 argp_options
, parse_an_arg
, N_("[this dir] [other dir]"), NULL
, NULL
, NULL
, NULL
2790 static struct poptOption argumentTable
[] = {
2791 #ifdef WITH_BACKGROUND
2792 { "background", 'B', POPT_ARG_NONE
, &background_wait
, 0 },
2794 #if defined(HAVE_SLANG) && defined(OS2_NT)
2795 { "createcmdfile", 'S', POPT_ARG_STRING
, NULL
, 'S' },
2797 { "color", 'c', POPT_ARG_NONE
, NULL
, 'c' },
2798 { "colors", 'C', POPT_ARG_STRING
, &command_line_colors
, 0 },
2799 #ifdef HAVE_SUBSHELL_SUPPORT
2800 { "dbgsubshell", 'X', POPT_ARG_NONE
, &debug_subshell
, 0 },
2802 { "edit", 'e', POPT_ARG_STRING
, &edit_one_file
, 0 },
2804 { "help", 'h', POPT_ARG_NONE
, NULL
, 'h' },
2805 { "help-colors", 'H', POPT_ARG_NONE
, NULL
, 'H' },
2807 { "ftplog", 'l', POPT_ARG_STRING
, NULL
, 'l' },
2809 { "libdir", 'f', POPT_ARG_NONE
, NULL
, 'f' },
2810 { NULL
, 'm', POPT_ARG_NONE
, NULL
, 'm' },
2811 { "nocolor", 'b', POPT_ARG_NONE
, &disable_colors
, 0 },
2812 { "nomouse", 'd', POPT_ARG_NONE
, NULL
, 'd' },
2813 #ifdef HAVE_SUBSHELL_SUPPORT
2814 { "nosubshell", 'u', POPT_ARG_NONE
, NULL
, 'u' },
2815 { "forceexec", 'r', POPT_ARG_NONE
, NULL
, 'r' },
2817 { "printwd", 'P', POPT_ARG_NONE
, &print_last_wd
, 0 },
2818 { "resetsoft", 'k', POPT_ARG_NONE
, &reset_hp_softkeys
, 0 },
2819 { "slow", 's', POPT_ARG_NONE
, &slow_terminal
, 0 },
2820 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2821 { "stickchars", 'a', 0, &force_ugly_line_drawing
, 0 },
2823 #ifdef HAVE_SUBSHELL_SUPPORT
2824 { "subshell", 'U', POPT_ARG_NONE
, NULL
, 'U' },
2826 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2827 { "termcap", 't', 0, &SLtt_Try_Termcap
, 0 },
2829 { "version", 'V', POPT_ARG_NONE
, NULL
, 'V'},
2830 { "view", 'v', POPT_ARG_STRING
, &view_one_file
, 0 },
2831 { "xterm", 'x', POPT_ARG_NONE
, &force_xterm
, 0},
2833 { NULL
, 0, 0, NULL
, 0 }
2837 handle_args (int argc
, char *argv
[])
2839 char *tmp
, *option_arg
, *base
;
2843 optCon
= poptGetContext ("mc", argc
, argv
, argumentTable
, 0);
2846 SLtt_Try_Termcap
= 1;
2849 while ((c
= poptGetNextOpt (optCon
)) > 0) {
2850 option_arg
= poptGetOptArg(optCon
);
2852 process_args (c
, option_arg
);
2857 fprintf(stderr
, "%s: %s\n",
2858 poptBadOption(optCon
, POPT_BADOPTION_NOALIAS
),
2863 probably_finish_program ();
2865 /* Check for special invocation names mcedit and mcview,
2866 * if none apply then set the current directory and the other
2867 * directory from the command line arguments
2869 tmp
= poptGetArg (optCon
);
2870 base
= x_basename (argv
[0]);
2871 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP(base
, "vi")) {
2874 edit_one_file
= strdup (tmp
);
2876 if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP(base
, "view")) {
2878 view_one_file
= strdup (tmp
);
2880 /* sets the current dir and the other dir */
2882 char buffer
[MC_MAXPATHLEN
+ 2];
2883 this_dir
= strdup (tmp
);
2884 mc_get_current_wd (buffer
, sizeof (buffer
) - 2);
2885 if ((tmp
= poptGetArg (optCon
)))
2886 other_dir
= strdup (tmp
);
2889 poptFreeContext(optCon
);
2894 * The compatibility_move_mc_files routine is intended to
2895 * move all of the hidden .mc files into a private ~/.mc
2896 * directory in the home directory, to avoid cluttering the users.
2898 * Previous versions of the program had all of their files in
2899 * the $HOME, we are now putting them in $HOME/.mc
2902 # define compatibility_move_mc_files()
2906 do_mc_filename_rename (char *mc_dir
, char *o_name
, char *n_name
)
2908 char *full_o_name
= concat_dir_and_file (home_dir
, o_name
);
2909 char *full_n_name
= copy_strings (home_dir
, MC_BASE
, n_name
, NULL
);
2912 move
= 0 == rename (full_o_name
, full_n_name
);
2919 do_compatibility_move (char *mc_dir
)
2924 if (stat (mc_dir
, &s
) == 0)
2926 if (errno
!= ENOENT
)
2929 if (mkdir (mc_dir
, 0777) == -1)
2932 move
= do_mc_filename_rename (mc_dir
, ".mc.ini", "ini");
2933 move
+= do_mc_filename_rename (mc_dir
, ".mc.hot", "hotlist");
2934 move
+= do_mc_filename_rename (mc_dir
, ".mc.ext", "ext");
2935 move
+= do_mc_filename_rename (mc_dir
, ".mc.menu", "menu");
2936 move
+= do_mc_filename_rename (mc_dir
, ".mc.bashrc", "bashrc");
2937 move
+= do_mc_filename_rename (mc_dir
, ".mc.inputrc", "inputrc");
2938 move
+= do_mc_filename_rename (mc_dir
, ".mc.tcshrc", "tcshrc");
2939 move
+= do_mc_filename_rename (mc_dir
, ".mc.tree", "tree");
2944 show_change_notice
= 1;
2948 compatibility_move_mc_files (void)
2950 char *mc_dir
= concat_dir_and_file (home_dir
, ".mc");
2952 do_compatibility_move (mc_dir
);
2957 int main (int argc
, char *argv
[])
2960 /* Backward compatibility: Gives up privileges in case someone
2961 installed the mc as setuid */
2964 # define LOCALEDIR get_mc_lib_dir ()
2967 signal(SIGINT
,SIG_IGN
); /* Ignore CTRL-C */
2969 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2970 setlocale (LC_ALL
, "");
2971 bindtextdomain ("mc", LOCALEDIR
);
2974 /* Initialize list of all user group for timur_clr_mode */
2982 /* NOTE: This call has to be before any our argument handling :) */
2985 session_management_setup (argv
[0]);
2987 char *base
= x_basename (argv
[0]);
2990 if (strcmp (base
, "mcedit") == 0)
2993 if (strcmp (base
, "mcview") == 0)
2997 gnome_init ("gmc", &mc_argp_parser
, argc
, argv
, 0, NULL
);
2998 probably_finish_program ();
3001 if (xtoolkit_init (&argc
, argv
) == -1)
3007 SLtt_Ignore_Beep
= 1;
3010 /* NOTE: This has to be called before slang_init or whatever routine
3011 calls any define_sequence */
3014 #ifndef PORT_WANTS_ARGP
3015 handle_args (argc
, argv
);
3018 /* Used to report the last working directory at program end */
3021 stdout_fd
= dup (1);
3023 if (open (ttyname (0), O_RDWR
) < 0)
3024 if (open ("/dev/tty", O_RDWR
) < 0) {
3025 /* Try if stderr is not redirected as the last chance */
3026 char *p
= strdup (ttyname (0));
3028 if (!strcmp (p
, ttyname (2)))
3032 _("Couldn't open tty line. You have to run mc without the -P flag.\n"
3033 "On some systems you may want to run # `which mc`\n"));
3042 /* This is to avoid subshell trying to restard any child pid
3043 * that happends to have cons_saver_pid (a random startup value).
3044 * and PID 1 is init, unlikely we could be the parent of it.
3046 /* cons_saver_pid = 1; */
3048 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
3049 handle_console (CONSOLE_INIT
);
3052 # ifdef HAVE_SUBSHELL_SUPPORT
3053 subshell_get_console_attributes ();
3056 /* Install the SIGCHLD handler; must be done before init_subshell() */
3060 /* This variable is used by the subshell */
3061 home_dir
= getenv ("HOME");
3064 home_dir
= PATH_SEP_STR
;
3066 home_dir
= mc_home
; /* LIBDIR, calculated in OS_Setup() */
3070 compatibility_move_mc_files ();
3073 /* We need this, since ncurses endwin () doesn't restore the signals */
3074 save_stop_handler ();
3077 /* Must be done before init_subshell, to set up the terminal size: */
3078 /* FIXME: Should be removed and LINES and COLS computed on subshell */
3080 /* NOTE: This call has to be after slang_init. It's the small part from
3081 the previous init_key which had to be moved after the call of slang_init */
3082 init_key_input_fd ();
3096 # ifdef HAVE_SUBSHELL_SUPPORT
3097 /* Done here to ensure that the subshell doesn't */
3098 /* inherit the file descriptors opened below, etc */
3105 /* Removing this from the X code let's us type C-c */
3108 /* Also done after init_subshell, to save any shell init file messages */
3110 handle_console (CONSOLE_SAVE
);
3112 if (alternate_plus_minus
)
3113 application_keypad_mode ();
3116 /* The directory hot list */
3119 if (show_change_notice
){
3120 message (1, _(" Notice "),
3121 _(" The Midnight Commander configuration files \n"
3122 " are now stored in the ~/.mc directory, the \n"
3123 " files have been moved now\n"));
3126 # ifdef HAVE_SUBSHELL_SUPPORT
3128 prompt
= strip_ctrl_codes (subshell_prompt
);
3133 prompt
= (geteuid () == 0) ? "# " : "$ ";
3135 /* Program main loop */
3138 /* Virtual File System shutdown */
3141 /* Delete list of all user groups*/
3144 flush_extension_file (); /* does only free memory */
3147 /* Miguel, maybe the fix in slang is not required and
3148 * it could be done by removing the slang_done_screen.
3149 * Do I need to call slang_reset_tty then?
3154 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
3156 if (alternate_plus_minus
)
3157 numeric_keypad_mode ();
3161 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
3166 handle_console (CONSOLE_DONE
);
3167 putchar ('\r'); /* Hack to make shell's prompt start at left of screen */
3171 /* On NT, home_dir is malloced */
3175 if (print_last_wd
== 2){
3179 bat_file
= fopen(batch_file_name
, "w");
3180 if (bat_file
!= NULL
){
3181 /* .ado: \r\n for Win95 */
3182 fprintf(bat_file
, "@echo off\r\n");
3183 if (isalpha(last_wd_string
[0]))
3184 fprintf(bat_file
, "%c:\r\n", last_wd_string
[0]);
3185 fprintf(bat_file
, "cd %s\r\n", last_wd_string
);
3190 if (print_last_wd
) {
3191 if (print_last_revert
|| edit_one_file
|| view_one_file
)
3192 write (stdout_fd
, ".", 1);
3194 write (stdout_fd
, last_wd_string
, strlen (last_wd_string
));
3195 free (last_wd_string
);
3201 mad_finalize (__FILE__
, __LINE__
);