1 /* Routines invoked by a function key
2 They normally operate on the current panel.
4 Copyright (C) 1994, 1995 Miguel de Icaza
5 Copyright (C) 1994, 1995 Janne Kukonlehto
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 # define INCL_DOSFILEMGR
25 # define INCL_DOSERROR
32 #include <stdlib.h> /* getenv (), rand */
33 #include <sys/types.h>
34 #include <sys/param.h>
37 #include <sys/time.h___>
43 #include <fcntl.h> /* open, O_RDWR */
55 # include <sys/mman.h>
61 #include "cmd.h" /* Our definitions */
62 #include "view.h" /* view() */
63 #include "dialog.h" /* query_dialog, message */
64 #include "file.h" /* the file operations */
65 #include "find.h" /* do_find */
68 #include "subshell.h" /* use_subshell */
69 #include "cons.saver.h"
71 #include "dlg.h" /* required by wtools.h */
72 #include "widget.h" /* required by wtools.h */
73 #include "wtools.h" /* listbox */
74 #include "command.h" /* for input_w */
75 #include "win.h" /* do_exit_ca_mode */
76 #include "layout.h" /* get_current/other_type */
77 #include "ext.h" /* regex_command */
78 #include "view.h" /* view */
79 #include "key.h" /* get_key_code */
80 #include "help.h" /* interactive_display */
82 #include "boxes.h" /* cd_dialog */
90 #ifdef USE_INTERNAL_EDIT
91 extern int edit (const char *file
, int line
);
93 #include "../vfs/vfs.h"
95 #include "main.h" /* global variables, global functions */
101 # include "tkscreen.h"
104 /* If set and you don't have subshell support,then C-o will give you a shell */
105 int output_starts_shell
= 0;
107 /* Source routing destination */
108 int source_route
= 0;
110 /* If set, use the builtin editor */
111 int use_internal_edit
= 1;
113 /* Ugly hack in order to distinguish between left and right panel in menubar */
115 #define MENU_PANEL_IDX (is_right ? 1 : 0)
118 #ifndef PORT_HAS_FILTER_CHANGED
119 # define x_filter_changed(p)
122 /* This is used since the parameter panel on some of the commands */
123 /* defined in this file may receive a 0 parameter if they are invoked */
124 /* The drop down menu */
126 WPanel
*get_a_panel (WPanel
*panel
)
130 if (get_current_type () == view_listing
){
136 /* view_file (filename, normal, internal)
139 * filename: The file name to view
140 * plain_view: If set does not do any fancy pre-processing (no filtering) and
141 * always invokes the internal viewer.
142 * internal: If set uses the internal viewer, otherwise an external viewer.
144 int view_file_at_line (char *filename
, int plain_view
, int internal
, int start_line
)
146 static char *viewer
= 0;
151 int changed_hex_mode
= 0;
152 int changed_nroff_flag
= 0;
153 int changed_magic_flag
= 0;
155 altered_hex_mode
= 0;
156 altered_nroff_flag
= 0;
157 altered_magic_flag
= 0;
158 if (default_hex_mode
)
159 changed_hex_mode
= 1;
160 if (default_nroff_flag
)
161 changed_nroff_flag
= 1;
162 if (default_magic_flag
)
163 changed_magic_flag
= 1;
164 default_hex_mode
= 0;
165 default_nroff_flag
= 0;
166 default_magic_flag
= 0;
167 view (0, filename
, &move_dir
, start_line
);
168 if (changed_hex_mode
&& !altered_hex_mode
)
169 default_hex_mode
= 1;
170 if (changed_nroff_flag
&& !altered_nroff_flag
)
171 default_nroff_flag
= 1;
172 if (changed_magic_flag
&& !altered_magic_flag
)
173 default_magic_flag
= 1;
178 char view_entry
[32];
181 sprintf (view_entry
, "View:%d", start_line
);
183 strcpy (view_entry
, "View");
185 if (!regex_command (filename
, view_entry
, NULL
, &move_dir
)){
186 view (0, filename
, &move_dir
, start_line
);
193 viewer
= getenv ("PAGER");
197 /* The file may be a non local file, get a copy */
198 if (!vfs_file_is_local (filename
)){
199 localcopy
= mc_getlocalcopy (filename
);
200 if (localcopy
== NULL
){
201 message (1, MSG_ERROR
, _(" Can not fetch a local copy of %s "), filename
);
204 execute_internal (viewer
, localcopy
);
205 mc_ungetlocalcopy (filename
, localcopy
, 0);
207 execute_internal (viewer
, filename
);
213 view_file (char *filename
, int plain_view
, int internal
)
215 return view_file_at_line (filename
, plain_view
, internal
, 0);
218 /* scan_for_file (panel, idx, direction)
221 * panel: pointer to the panel on which we operate
222 * idx: starting file.
223 * direction: 1, or -1
225 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
227 int i
= idx
+ direction
;
231 i
= panel
->count
- 1;
232 if (i
== panel
->count
)
234 if (!S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
241 /* do_view: Invoked as the F3/F13 key. */
242 static void do_view_cmd (WPanel
*panel
, int normal
)
245 panel
= get_a_panel (panel
);
247 /* Directories are viewed by changing to them */
248 if (S_ISDIR (selection (panel
)->buf
.st_mode
) ||
249 link_isdir (selection (panel
))){
250 if (confirm_view_dir
&& (panel
->marked
|| panel
->dirs_marked
)){
251 if (query_dialog (_(" CD "), _("Files tagged, want to cd?"),
252 0, 2, _("&Yes"), _("&No")) == 1){
256 do_cd (selection (panel
)->fname
, cd_exact
);
261 file_idx
= panel
->selected
;
265 filename
= panel
->dir
.list
[file_idx
].fname
;
267 dir
= view_file (filename
, normal
, use_internal_view
);
270 file_idx
= scan_for_file (panel
, file_idx
, dir
);
274 void view_cmd (WPanel
*panel
)
276 do_view_cmd (panel
, 0);
279 void view_simple_cmd (WPanel
*panel
)
281 do_view_cmd (panel
, 1);
284 void filtered_view_cmd (WPanel
*panel
)
288 panel
= get_a_panel (panel
);
289 command
= input_dialog (_(" Filtered view "), _(" Filter command and arguments:"),
290 selection (panel
)->fname
);
294 view (command
, "", 0, 0);
299 void filtered_view_cmd_cpanel (void)
301 filtered_view_cmd (cpanel
);
304 void do_edit_at_line (const char *what
, int start_line
)
306 static char *editor
= 0;
308 #ifdef USE_INTERNAL_EDIT
309 if (use_internal_edit
){
310 edit (what
, start_line
);
316 editor
= getenv ("EDITOR");
318 editor
= get_default_editor ();
320 execute_internal (editor
, what
);
325 do_edit (const char *what
)
327 do_edit_at_line (what
, 1);
330 void edit_cmd (WPanel
*panel
)
332 panel
= get_a_panel(panel
);
333 if (!regex_command (selection (panel
)->fname
, "Edit", NULL
, 0))
334 do_edit (selection (panel
)->fname
);
337 void edit_cmd_new (WPanel
*panel
)
345 if (panel_operate (cpanel
, OP_COPY
, NULL
)){
346 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
354 if (panel_operate (cpanel
, OP_MOVE
, NULL
)){
355 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
360 void copymove_cmd_with_default (int copy
, char *thedefault
)
363 if (panel_operate (cpanel
, copy
? OP_COPY
: OP_MOVE
, thedefault
)){
364 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
369 void mkdir_cmd (WPanel
*panel
)
373 panel
= get_a_panel (panel
);
374 dir
= input_expand_dialog (_(" Mkdir "), _(" Enter directory name:") , "");
380 if (my_mkdir (dir
, 0777) == 0){
381 update_panels (UP_OPTIMIZE
, dir
);
383 select_item (cpanel
);
388 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
391 void delete_cmd (void)
395 if (panel_operate (cpanel
, OP_DELETE
, NULL
)){
396 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
407 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
413 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
414 p
->filter
= allocated_filter_string
;
416 free (allocated_filter_string
);
418 x_filter_changed (p
);
421 /* Set a given panel filter expression */
422 void set_panel_filter (WPanel
*p
)
427 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
429 reg_exp
= input_dialog (_(" Filter "), _(" Set expression for filtering filenames"), x
);
432 set_panel_filter_to (p
, reg_exp
);
435 /* Invoked from the left/right menus */
436 void filter_cmd (void)
440 if (!SELECTED_IS_PANEL
)
444 set_panel_filter (p
);
447 void reread_cmd (void)
451 mad_check (__FILE__
, __LINE__
);
452 if (get_current_type () == view_listing
&&
453 get_other_type () == view_listing
)
454 flag
= strcmp (cpanel
->cwd
, opanel
->cwd
) ? UP_ONLY_CURRENT
: 0;
456 flag
= UP_ONLY_CURRENT
;
458 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
462 /* Panel sorting related routines */
463 void do_re_sort (WPanel
*panel
)
468 panel
= get_a_panel (panel
);
469 filename
= strdup (selection (cpanel
)->fname
);
470 unselect_item (panel
);
471 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
, panel
->case_sensitive
);
472 panel
->selected
= -1;
473 for (i
= panel
->count
; i
; i
--){
474 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
475 panel
->selected
= i
-1;
480 cpanel
->top_file
= cpanel
->selected
- ITEMS (cpanel
)/2;
481 if (cpanel
->top_file
< 0)
482 cpanel
->top_file
= 0;
484 panel_update_contents (panel
);
487 void reverse_selection_cmd_panel (WPanel
*panel
)
492 for (i
= 0; i
< panel
->count
; i
++){
493 file
= &panel
->dir
.list
[i
];
494 if (S_ISDIR (file
->buf
.st_mode
))
496 do_file_mark (panel
, i
, !file
->f
.marked
);
501 void reverse_selection_cmd (void)
503 reverse_selection_cmd_panel (cpanel
);
506 void select_cmd_panel (WPanel
*panel
)
508 char *reg_exp
, *reg_exp_t
;
513 reg_exp
= input_dialog (_(" Select "), "", easy_patterns
? "*" : ".");
519 /* Check if they specified a directory */
520 if (*reg_exp_t
== PATH_SEP
){
524 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
526 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
529 for (i
= 0; i
< panel
->count
; i
++){
530 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
532 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
539 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
541 message (1, MSG_ERROR
, _(" Malformed regular expression "));
546 do_file_mark (panel
, i
, 1);
553 void select_cmd (void)
555 select_cmd_panel (cpanel
);
558 void unselect_cmd_panel (WPanel
*panel
)
560 char *reg_exp
, *reg_exp_t
;
565 reg_exp
= input_dialog (_(" Unselect "),"", easy_patterns
? "*" : ".");
571 /* Check if they specified directory matching */
572 if (*reg_exp_t
== PATH_SEP
){
576 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
578 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
580 for (i
= 0; i
< panel
->count
; i
++){
581 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
583 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
590 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
592 message (1, MSG_ERROR
, _(" Malformed regular expression "));
597 do_file_mark (panel
, i
, 0);
604 void unselect_cmd (void)
606 unselect_cmd_panel (cpanel
);
609 /* Check if the file exists */
610 /* If not copy the default */
611 static int check_for_default(char *default_file
, char *file
)
614 if (mc_stat (file
, &s
)){
615 if (mc_stat (default_file
, &s
)){
618 create_op_win (OP_COPY
, 0);
619 file_mask_defaults ();
620 copy_file_file (default_file
, file
, 1);
633 if (geteuid () == 0){
634 dir
= query_dialog (_("Extension file edit"),
635 _(" Which extension file you want to edit? "), 0, 2,
636 _("&User"), _("&System Wide"));
638 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
641 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
642 check_for_default (extdir
, buffer
);
649 flush_extension_file ();
652 void menu_edit_cmd (void)
660 _(" Which menu file will you edit? "),
661 0, geteuid() ? 2 : 3,
662 _("&Local"), _("&Home"), _("&System Wide")
665 menufile
= concat_dir_and_file(mc_home
, MC_GLOBAL_MENU
);
669 buffer
= strdup (MC_LOCAL_MENU
);
670 check_for_default (menufile
, buffer
);
674 buffer
= concat_dir_and_file (home_dir
, MC_HOME_MENU
);
675 check_for_default (menufile
, buffer
);
679 buffer
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
693 void quick_chdir_cmd (void)
697 target
= hotlist_cmd (LIST_HOTLIST
);
701 if (get_current_type () == view_tree
)
702 tree_chdir (the_tree
, target
);
704 do_cd (target
, cd_exact
);
709 void reselect_vfs (void)
713 target
= hotlist_cmd (LIST_VFSLIST
);
717 do_cd (target
, cd_exact
);
722 static int compare_files (char *name1
, char *name2
, long size
)
726 int result
= -1; /* Different by default */
728 file1
= open (name1
, O_RDONLY
);
730 file2
= open (name2
, O_RDONLY
);
734 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
735 if (data1
!= (char*) -1){
736 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
737 if (data2
!= (char*) -1){
739 result
= memcmp (data1
, data2
, size
);
740 munmap (data2
, size
);
742 munmap (data1
, size
);
745 /* Don't have mmap() :( Even more ugly :) */
746 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
751 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
752 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
753 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
754 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
764 compare_quick
, compare_size_only
, compare_thourough
768 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
771 char *src_name
, *dst_name
;
773 panel
= get_a_panel (panel
);
775 /* No marks by default */
778 panel
->dirs_marked
= 0;
780 /* Handle all files in the panel */
781 for (i
= 0; i
< panel
->count
; i
++){
782 file_entry
*source
= &panel
->dir
.list
[i
];
784 /* Default: unmarked */
785 file_mark (panel
, i
, 0);
787 /* Skip directories */
788 if (S_ISDIR (source
->buf
.st_mode
))
791 /* Search the corresponding entry from the other panel */
792 for (j
= 0; j
< other
->count
; j
++){
793 if (strcmp (source
->fname
,
794 other
->dir
.list
[j
].fname
) == 0)
797 if (j
>= other
->count
)
798 /* Not found -> mark */
799 do_file_mark (panel
, i
, 1);
802 file_entry
*target
= &other
->dir
.list
[j
];
804 if (mode
!= compare_size_only
){
805 /* Older version is not marked */
806 if (source
->buf
.st_mtime
< target
->buf
.st_mtime
)
810 /* Newer version with different size is marked */
811 if (source
->buf
.st_size
!= target
->buf
.st_size
){
812 do_file_mark (panel
, i
, 1);
816 if (mode
== compare_size_only
)
819 if (mode
== compare_quick
){
820 /* Thorough compare off, compare only time stamps */
821 /* Mark newer version, don't mark version with the same date */
822 if (source
->buf
.st_mtime
> target
->buf
.st_mtime
){
823 do_file_mark (panel
, i
, 1);
828 /* Thorough compare on, do byte-by-byte comparison */
829 src_name
= get_full_name (panel
->cwd
, source
->fname
);
830 dst_name
= get_full_name (other
->cwd
, target
->fname
);
831 if (compare_files (src_name
, dst_name
, source
->buf
.st_size
))
832 do_file_mark (panel
, i
, 1);
839 void compare_dirs_cmd (void)
841 enum CompareMode thorough_flag
= compare_quick
;
843 thorough_flag
= query_dialog (_(" Compare directories "), _(" Select compare method: "),
844 0, 3, _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
845 if (thorough_flag
< 0 || thorough_flag
> 2)
847 if (get_current_type () == view_listing
&&
848 get_other_type () == view_listing
){
849 compare_dir (cpanel
, opanel
, thorough_flag
);
850 compare_dir (opanel
, cpanel
, thorough_flag
);
851 paint_panel (cpanel
);
852 paint_panel (opanel
);
854 message (1, MSG_ERROR
, _(" Both panels should be on the listing view mode to use this command "));
858 void history_cmd (void)
863 if (input_w (cmdline
)->need_push
){
864 if (push_history (input_w (cmdline
), input_w (cmdline
)->buffer
) == 2)
865 input_w (cmdline
)->need_push
= 0;
867 if (!input_w (cmdline
)->history
){
868 message (1, MSG_ERROR
, _(" The command history is empty "));
871 current
= input_w (cmdline
)->history
;
872 while (current
->prev
)
873 current
= current
->prev
;
874 listbox
= create_listbox_window (60, 10, _(" Command history "),
877 LISTBOX_APPEND_TEXT (listbox
, 0, current
->text
,
879 current
= current
->next
;
881 run_dlg (listbox
->dlg
);
882 if (listbox
->dlg
->ret_value
== B_CANCEL
)
885 current
= listbox
->list
->current
->data
;
886 destroy_dlg (listbox
->dlg
);
891 input_w (cmdline
)->history
= current
;
892 assign_text (input_w (cmdline
), input_w (cmdline
)->history
->text
);
893 update_input (input_w (cmdline
), 1);
896 #if !defined(HAVE_XVIEW) && !defined(HAVE_GNOME)
906 view_other_cmd (void)
908 static int message_flag
= TRUE
;
909 #ifdef HAVE_SUBSHELL_SUPPORT
910 char *new_dir
= NULL
;
914 if (!xterm_flag
&& !console_flag
&& !use_subshell
){
916 message (1, MSG_ERROR
, _(" Not an xterm or Linux console; \n"
917 " the panels cannot be toggled. "));
918 message_flag
= FALSE
;
923 if (clear_before_exec
)
925 if (alternate_plus_minus
)
926 numeric_keypad_mode ();
929 /* With slang we don't want any of this, since there
930 * is no mc_raw_mode supported
935 keypad(stdscr
, FALSE
);
937 if (!status_using_ncurses
)
943 #ifdef HAVE_SUBSHELL_SUPPORT
945 new_dir_p
= vfs_current_is_local () ? &new_dir
: NULL
;
946 if (invoke_subshell (NULL
, VISIBLY
, new_dir_p
))
947 quiet_quit_cmd(); /* User did `exit' or `logout': quit MC quietly */
951 if (output_starts_shell
){
953 _("Type `exit' to return to the Midnight Commander\n\r\n\r"));
954 my_system (EXECUTE_AS_SHELL
, shell
, NULL
);
959 handle_console (CONSOLE_SAVE
);
961 if (!status_using_ncurses
)
965 keypad(stdscr
, TRUE
);
969 if (alternate_plus_minus
)
970 application_keypad_mode ();
973 #ifdef HAVE_SUBSHELL_SUPPORT
977 do_possible_cd (new_dir
);
978 if (console_flag
&& output_lines
)
979 show_console_contents (output_start_y
,
980 LINES
-keybar_visible
-output_lines
-1,
981 LINES
-keybar_visible
-1);
986 /* prevent screen flash when user did 'exit' or 'logout' within
995 do_link (int symbolic_link
, char *fname
)
1001 if (!symbolic_link
){
1002 stat_r
= mc_stat (fname
, &s
);
1004 message (1, MSG_ERROR
, _(" Couldn't stat %s \n %s "),
1005 fname
, unix_error_string (errno
));
1008 if (!S_ISREG (s
.st_mode
))
1012 if (!symbolic_link
){
1013 src
= copy_strings (_(" Link "), name_trunc (fname
, 46),
1015 dest
= input_expand_dialog (_(" Link "), src
, "");
1024 if (-1 == mc_link (fname
, dest
))
1025 message (1, MSG_ERROR
, _(" link: %s "), unix_error_string (errno
));
1027 #ifdef OLD_SYMLINK_VERSION
1028 symlink_dialog (fname
, "", &dest
, &src
);
1030 /* suggest the full path for symlink */
1031 char s
[MC_MAXPATHLEN
];
1032 char d
[MC_MAXPATHLEN
];
1034 strcpy(s
, cpanel
->cwd
);
1035 if ( ! ((s
[0] == '/') && (s
[1] == 0)))
1038 if (get_other_type () == view_listing
)
1039 strcpy(d
, opanel
->cwd
);
1043 if ( ! ((d
[0] == '/') && (d
[1] == 0)))
1045 symlink_dialog (s
, d
, &dest
, &src
);
1047 if (!dest
|| !*dest
) {
1057 if (-1 == mc_symlink (dest
, src
))
1058 message (1, MSG_ERROR
, _(" symlink: %s "),
1059 unix_error_string (errno
));
1065 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1069 void link_cmd (void)
1071 do_link (0, selection (cpanel
)->fname
);
1074 void symlink_cmd (void)
1076 do_link (1, selection (cpanel
)->fname
);
1079 void edit_symlink_cmd (void)
1081 if (S_ISLNK (selection (cpanel
)->buf
.st_mode
)) {
1082 char buffer
[MC_MAXPATHLEN
], *p
= selection (cpanel
)->fname
;
1084 char *dest
, *q
= copy_strings (_(" Symlink "), name_trunc (p
, 32), _(" points to:"), NULL
);
1086 i
= readlink (p
, buffer
, MC_MAXPATHLEN
);
1089 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
1091 if (*dest
&& strcmp (buffer
, dest
)) {
1094 if (-1 == mc_symlink (dest
, p
))
1095 message (1, MSG_ERROR
, _(" edit symlink: %s "),
1096 unix_error_string (errno
));
1097 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1107 void other_symlink_cmd (void)
1109 char *dest
, *q
, *p
, *r
, *s
, *t
;
1111 if (get_other_type () != view_listing
)
1114 if (!strcmp (selection (opanel
)->fname
, ".."))
1116 p
= concat_dir_and_file (cpanel
->cwd
, selection (cpanel
)->fname
);
1117 r
= concat_dir_and_file (opanel
->cwd
, selection (cpanel
)->fname
);
1119 q
= copy_strings (_(" Link symbolically "), name_trunc (p
, 32), _(" to:"), NULL
);
1120 dest
= input_expand_dialog (_(" Relative symlink "), q
, r
);
1123 t
= strrchr (dest
, PATH_SEP
);
1126 s
= diff_two_paths (dest
, p
);
1130 if (-1 == mc_symlink (dest
, s
))
1131 message (1, MSG_ERROR
, _(" relative symlink: %s "),
1132 unix_error_string (errno
));
1133 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1147 void help_cmd (void)
1149 char *hlpfile
= concat_dir_and_file (mc_home
, "mc.hlp");
1150 interactive_display (hlpfile
, "[main]");
1154 void view_panel_cmd (void)
1159 void edit_panel_cmd (void)
1164 void mkdir_panel_cmd (void)
1169 /* Returns a random hint */
1170 char *get_random_hint (void)
1172 char *data
, *result
, *eol
;
1177 /* Do not change hints more often than one minute */
1184 if ((now
- last
) < 60)
1188 static int last_sec
;
1189 static struct timeval tv
;
1191 gettimeofday (&tv
, NULL
);
1192 if (!(tv
.tv_sec
> last_sec
+60))
1194 last_sec
= tv
.tv_sec
;
1197 hintfile
= concat_dir_and_file (mc_home
, MC_HINT
);
1198 data
= load_file (hintfile
);
1204 srand ((short) now
);
1208 /* get a random entry */
1209 len
= strlen (data
);
1210 start
= rand () % len
;
1212 for (;start
; start
--){
1213 if (data
[start
] == '\n'){
1218 eol
= strchr (&data
[start
], '\n');
1221 result
= strdup (&data
[start
]);
1234 static char *machine_str
= N_(" Enter machine name (F1 for details): ");
1236 static void nice_cd (char *text
, char *xtext
, char *help
, char *prefix
, int to_home
)
1241 if (!SELECTED_IS_PANEL
)
1244 machine
= input_dialog_help (text
,
1250 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1251 cd_path
= copy_strings (machine
, to_home
? "/~/" : NULL
, NULL
);
1253 cd_path
= copy_strings (prefix
, machine
, to_home
? "/~/" : NULL
, NULL
);
1255 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1256 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1258 message (1, MSG_ERROR
, N_(" Could not chdir to %s "), cd_path
);
1263 void netlink_cmd (void)
1265 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1266 "[Network File System]", "mc:", 1);
1269 void ftplink_cmd (void)
1271 nice_cd (_(" FTP to machine "), _(machine_str
),
1272 "[FTP File System]", "ftp://", 1);
1275 #ifdef HAVE_SETSOCKOPT
1276 void source_routing (void)
1281 source
= input_dialog (_(" Socket source routing setup "),
1282 _(" Enter host name to use as a source routing hop: ")n
,
1287 hp
= gethostbyname (source
);
1289 message (1, _(" Host name "), _(" Error while looking up IP address "));
1292 source_route
= *((int *)hp
->h_addr
);
1294 #endif /* HAVE_SETSOCKOPT */
1295 #endif /* USE_NETCODE */
1297 #ifdef USE_EXT2FSLIB
1298 void undelete_cmd (void)
1300 nice_cd (_(" Undelete files on an ext2 file system "),
1301 _(" Enter the file system name where you want to run the\n "
1302 " undelete file system on: (F1 for details)"),
1303 "[Undelete File System]", "undel:", 0);
1307 void quick_cd_cmd (void)
1309 char *p
= cd_dialog ();
1312 char *q
= copy_strings ("cd ", p
, NULL
);
1324 #endif /* SCO_FLAVOR */
1327 void dirsizes_cmd (void)
1329 WPanel
*panel
= cpanel
;
1331 char *cmd
, *p
, *q
, *r
;
1334 # define dirsizes_command "du -s -b "
1336 # define dirsizes_command "du -s "
1338 #ifndef DUSUM_FACTOR
1339 # define DUSUM_FACTOR 512
1342 if (!vfs_current_is_local ())
1344 for (i
= 0; i
< panel
->count
; i
++)
1345 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
1346 j
+= strlen (panel
->dir
.list
[i
].fname
) + 1;
1349 cmd
= xmalloc (strlen (dirsizes_command
) + j
+ 1, "dirsizes_cmd");
1350 strcpy (cmd
, dirsizes_command
);
1351 p
= strchr (cmd
, 0);
1352 for (i
= 0; i
< panel
->count
; i
++)
1353 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
) &&
1354 strcmp (panel
->dir
.list
[i
].fname
, "..")) {
1355 strcpy (p
, panel
->dir
.list
[i
].fname
);
1361 f
= popen (cmd
, "r");
1364 /* Assume that du will display the directories in the order
1365 * I've passed to it :(
1368 p
= xmalloc (1024, "dirsizes_cmd");
1369 while (fgets (p
, 1024, f
)) {
1370 j
= atoi (p
) * DUSUM_FACTOR
;
1371 for (q
= p
; *q
&& *q
!= ' ' && *q
!= '\t'; q
++);
1372 while (*q
== ' ' || *q
== '\t')
1374 r
= strchr (q
, '\n');
1377 for (; i
< panel
->count
; i
++)
1378 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
1379 if (!strncmp (q
, panel
->dir
.list
[i
].fname
,
1381 if (panel
->dir
.list
[i
].f
.marked
)
1383 ((panel
->has_dir_sizes
) ? panel
->dir
.list
[i
].buf
.st_size
: 0);
1384 panel
->dir
.list
[i
].buf
.st_size
= j
;
1387 if (i
== panel
->count
)
1393 message (0, _("Show directory sizes"), _("Pipe close failed"));
1395 #else /* SCO_FLAVOR */
1397 ** SCO reports about error while all seems to be ok. Just ignore it...
1398 ** (alex@bcs.zaporizhzhe.ua)
1401 #endif /* SCO_FLAVOR */
1402 panel
->has_dir_sizes
= 1;
1403 close_error_pipe (0, 0);
1404 paint_panel (panel
);
1406 close_error_pipe (1, _("Cannot invoke du command."));
1411 save_setup_cmd (void)
1417 str
= copy_strings ( _(" Setup saved to ~/"), PROFILE_NAME
, NULL
);
1422 message (0, _(" Setup "), str
);
1428 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1432 p
->user_mini_status
= use_msformat
;
1433 p
->list_type
= view_type
;
1435 if (view_type
== list_user
|| use_msformat
){
1436 free (p
->user_format
);
1437 p
->user_format
= user
;
1439 free (p
->user_status_format
[view_type
]);
1440 p
->user_status_format
[view_type
] = status
;
1442 err
= set_panel_formats (p
);
1446 free (p
->user_format
);
1447 p
->user_format
= strdup (DEFAULT_USER_FORMAT
);
1451 free (p
->user_status_format
[view_type
]);
1452 p
->user_status_format
[view_type
] = strdup (DEFAULT_USER_FORMAT
);
1461 set_panel_formats (p
);
1469 info_cmd_no_menu (void)
1471 set_display_type (cpanel
== left_panel
? 1 : 0, view_info
);
1475 quick_cmd_no_menu (void)
1477 set_display_type (cpanel
== left_panel
? 1 : 0, view_quick
);
1481 switch_to_listing (int panel_index
)
1483 if (get_display_type (panel_index
) != view_listing
)
1484 set_display_type (panel_index
, view_listing
);
1490 int view_type
, use_msformat
;
1491 char *user
, *status
;
1495 display_type
= get_display_type (MENU_PANEL_IDX
);
1496 if (display_type
== view_listing
)
1497 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1501 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1503 if (view_type
== -1)
1506 switch_to_listing (MENU_PANEL_IDX
);
1508 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1510 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1516 set_display_type (MENU_PANEL_IDX
, view_tree
);
1522 set_display_type (MENU_PANEL_IDX
, view_info
);
1526 quick_view_cmd (void)
1528 set_display_type (MENU_PANEL_IDX
, view_quick
);
1532 /* Handle the tree internal listing modes switching */
1534 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1536 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1539 switch_to_listing (panel_index
);
1541 p
->list_type
= listing_mode
;
1542 if (set_panel_formats (p
))
1551 toggle_listing_cmd (void)
1553 int current
= get_current_index ();
1554 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1555 int list_mode
= p
->list_type
;
1569 if (set_basic_panel_listing_to (current
, m
))
1571 set_basic_panel_listing_to (current
, list_full
);